init(); } /** * Initialize the notice */ private function init() { $is_notice_hidden = get_option( 'post-smtp-recommendation-notice-hidden', false ); if( ! $is_notice_hidden ) { add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'admin_head', array( $this, 'admin_head' ) ); add_action( 'admin_notices', array( $this, 'show_notice' ) ); add_action( 'admin_post_hide-post-smtp-recommendation-notice', array( $this, 'hide_post_smtp_recommendation_notice' ) ); add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); } } /** * Set plugin slug and format */ public function set_plugin_info( $slug, $format = 'png' ) { $this->slug = $slug; $this->format = $format; } /** * Check if any SMTP plugin is active */ private function is_smtp_plugin_active() { if( ! function_exists( 'is_plugin_active' ) ) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } foreach( $this->plugins as $plugin ) { if( is_plugin_active( $plugin ) ) { return true; } } return false; } /** * Display the admin notice */ public function show_notice() { // Don't show if any SMTP plugin is active if( $this->is_smtp_plugin_active() ) { return; } $button = array( 'text' => 'Install & Activate', 'action' => 'install-plugin_post-smtp', ); if( file_exists( WP_PLUGIN_DIR . "/{$this->plugins[0]}" ) ) { $this->is_installed = true; $button['text'] = 'Activate Post SMTP'; $button['action'] = 'activate-plugin_post-smtp'; } ?>
Post SMTP Logo

✨ Boost Your Email Delivery with Post SMTP!
Make sure every WordPress email lands safely in your users' inboxes. Install Post SMTP — trusted by 400,000+ websites for reliable delivery, detailed logs, and instant alerts.

'POST', 'callback' => array( $this, 'request_post_smtp' ), 'permission_callback' => function() { return current_user_can( 'manage_options' ); } ) ); } /** * Callback for the rest route */ public function request_post_smtp( $request ) { if ( ! \RecommendPostSMTP\Base\Recommend_Post_SMTP_Base::has_data_consent() ) { wp_send_json_success( array( 'message' => __( 'Action completed (data sharing skipped — no consent)', 'file-manager-advanced' ), 'consent' => false ) ); return; } $site_url = get_bloginfo( 'url' ); $status = $request->get_param( 'status' ); $plugin_slug = $this->slug; $secret_key = \RecommendPostSMTP\Base\Recommend_Post_SMTP_Base::get_site_secret_key(); $response = wp_remote_post( "https://connect.postmansmtp.com/wp-json/update/v1/update?site_url={$site_url}&status={$status}&plugin_slug={$plugin_slug}", array( 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/json', 'Secret-Key' => $secret_key ) ) ); wp_send_json_success( array( 'message' => __( 'Request sent successfully', 'file-manager-advanced' ) ) ); } /** * Add the admin footer script to the notice */ public function admin_enqueue_scripts() { wp_enqueue_script( 'recommend-post-smtp-script', plugin_dir_url( __FILE__ ) . 'assets/js/admin-script.js', array( 'updates', 'jquery' ), '1.0.0', true ); $has_consent = false; if ( class_exists( 'RecommendPostSMTP\\Base\\Recommend_Post_SMTP_Base' ) ) { $has_consent = \RecommendPostSMTP\Base\Recommend_Post_SMTP_Base::has_data_consent(); } wp_localize_script( 'recommend-post-smtp-script', 'recommendPostSMTP', array( 'redirectURL' => admin_url( "admin-post.php?action=hide-post-smtp-recommendation-notice&nonce=" . wp_create_nonce( 'hide-post-smtp-recommendation-notice' ) ), 'postSMTPURL' => admin_url( "admin.php?page=postman" ), 'XWPNonce' => wp_create_nonce( 'wp_rest' ), 'restURL' => rest_url(), 'ajaxURL' => admin_url( 'admin-ajax.php' ), 'ajaxNonce' => wp_create_nonce( 'post_smtp_request_nonce' ), 'hasConsent' => $has_consent, ) ); } } endif;