L_Init::getInstance()->getService( 'plugin-meta' ); $min = ''; if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) { $min = '.min'; } wp_enqueue_style( 'wp-mail-logging-admin-smtp', $assets_url . "/css/wp-mail-logging-smtp{$min}.css", [], $plugin_meta['version'] ); wp_enqueue_script( 'wp-mail-logging-admin-smtp', $assets_url . "/js/wp-mail-logging-admin-smtp{$min}.js", [ 'jquery' ], $plugin_meta['version'] ); $error_could_not_install = sprintf( wp_kses( /* translators: %s - Lite plugin download URL. */ __( 'Could not install the plugin automatically. Please download it and install it manually.', 'wp-mail-logging' ), [ 'a' => [ 'href' => true, ], ] ), esc_url( $this->config['lite_download_url'] ) ); $error_could_not_activate = sprintf( wp_kses( /* translators: %s - Lite plugin download URL. */ __( 'Could not activate the plugin. Please activate it on the Plugins page.', 'wp-mail-logging' ), [ 'a' => [ 'href' => true, ], ] ), esc_url( admin_url( 'plugins.php' ) ) ); wp_localize_script( 'wp-mail-logging-admin-smtp', 'wp_mail_logging_admin_smtp', [ 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( self::NONCE_ACTION ), 'activating' => esc_html__( 'Activating...', 'wp-mail-logging' ), 'installing' => esc_html__( 'Installing...', 'wp-mail-logging' ), 'activated' => esc_html__( 'WP Mail SMTP Installed & Activated', 'wp-mail-logging' ), 'download_now' => esc_html__( 'Download Now', 'wp-mail-logging' ), 'plugins_page' => esc_html__( 'Go to Plugins page', 'wp-mail-logging' ), 'error_could_not_install' => $error_could_not_install, 'error_could_not_activate' => $error_could_not_activate, 'manual_install_url' => $this->config['lite_download_url'], 'manual_activate_url' => admin_url( 'plugins.php' ), 'smtp_wizard_url' => esc_url( $this->config['smtp_wizard_url'] ), 'smtp_wizard' => esc_html__( 'Open Setup Wizard', 'wp-mail-logging' ), 'smtp_settings' => esc_html__( 'Go to SMTP settings', 'wp-mail-logging' ), 'smtp_settings_url' => esc_url( $this->config['smtp_settings_url'] ), ] ); // Enqueue Lity. wp_enqueue_script( 'wp-mail-logging-admin-lity', $plugin_meta['uri'] . "lib/lity/lity.min.js", [], '2.4.1', true ); wp_enqueue_style( 'wp-mail-logging-admin-lity', $plugin_meta['uri'] . "lib/lity/lity.min.css", [], '2.4.1' ); } /** * Display the SMTP tab content. * * @since 1.11.0 * * @return void */ public function display_tab_content() { // Admin notices display after the first heading tag. echo '

' . esc_html__( 'WP Mail SMTP', 'wp-mail-logging' ) . '

'; echo '
'; $this->output_section_heading(); $this->output_section_screenshot(); $this->output_section_step_install(); $this->output_section_step_setup(); echo '
'; } /** * Generate and output heading section HTML. * * @since 1.11.0 */ private function output_section_heading() { $assets_url = WPML_Init::getInstance()->getService( 'plugin' )->get_assets_url(); // Heading section. printf( '
%3$s

%4$s

%5$s

', esc_url( $assets_url . '/images/smtp/wpmailsmtp-logo.png' ), esc_url( $assets_url . '/images/smtp/wpmailsmtp-logo@2x.png' ), esc_attr__( 'WP Mail SMTP', 'wp-mail-logging' ), esc_html__( 'Making Email Deliverability Easy for WordPress', 'wp-mail-logging' ), esc_html__( 'WP Mail SMTP fixes deliverability problems with your WordPress emails and form notifications. It\'s built by the same folks behind WPForms.', 'wp-mail-logging' ) ); } /** * Generate and output screenshot section HTML. * * @since 1.11.0 */ private function output_section_screenshot() { $assets_url = WPML_Init::getInstance()->getService( 'plugin' )->get_assets_url(); $plugin_meta = WPML_Init::getInstance()->getService( 'plugin-meta' ); // Screenshot section. printf( '
%2$s
', esc_url( $assets_url . '/images/smtp/screenshot-tnail.png?ver=' . $plugin_meta['version'] ), esc_attr__( 'WP Mail SMTP screenshot', 'wp-mail-logging' ), esc_url( $assets_url . '/images/smtp/screenshot-full.png?ver=' . $plugin_meta['version'] ), esc_html__( 'Improves email deliverability in WordPress.', 'wp-mail-logging' ), esc_html__( 'Used by 3+ million websites.', 'wp-mail-logging' ), esc_html__( 'Free mailers: SendLayer, SMTP.com, Sendinblue, Google / Gmail, Mailgun, Postmark, SendGrid.', 'wp-mail-logging' ), esc_html__( 'Pro mailers: Amazon SES, Microsoft 365 / Outlook.com, Zoho Mail.', 'wp-mail-logging' ) ); } /** * Generate and output step 'Install' section HTML. * * @since 1.11.0 */ private function output_section_step_install() { $step = $this->get_data_step_install(); if ( empty( $step ) ) { return; } $button_format = ''; $button_allowed_html = [ 'button' => [ 'class' => true, 'data-plugin' => true, 'data-action' => true, ], ]; if ( ! $this->output_data['plugin_installed'] && ! $this->output_data['pro_plugin_installed'] && ! $this->can_install_plugin() ) { $button_format = '%2$s '; $button_allowed_html = [ 'a' => [ 'class' => true, 'href' => true, 'target' => true, 'rel' => true, ], 'span' => [ 'class' => true, 'aria-hidden' => true, ], ]; } $assets_url = WPML_Init::getInstance()->getService( 'plugin' )->get_assets_url(); $button = sprintf( $button_format, esc_attr( $step['plugin'] ), esc_html( $step['button_text'] ), esc_attr( $step['button_class'] ), esc_attr( $step['button_action'] ) ); printf( '

%3$s

%4$s

%5$s
', esc_url( $assets_url . '/images/smtp/' . $step['icon'] ), esc_attr__( 'Step 1', 'wp-mail-logging' ), esc_html( $step['heading'] ), esc_html( $step['description'] ), wp_kses( $button, $button_allowed_html ) ); } /** * Step 'Install' data. * * @since 1.11.0 * * @return array Step data. */ private function get_data_step_install() { $step = []; $step['heading'] = esc_html__( 'Install and Activate WP Mail SMTP', 'wp-mail-logging' ); $step['description'] = esc_html__( 'Install WP Mail SMTP from the WordPress.org plugin repository.', 'wp-mail-logging' ); $this->output_data['all_plugins'] = get_plugins(); $this->output_data['plugin_installed'] = array_key_exists( $this->config['lite_plugin'], $this->output_data['all_plugins'] ); $this->output_data['pro_plugin_installed'] = array_key_exists( $this->config['pro_plugin'], $this->output_data['all_plugins'] ); $this->output_data['plugin_activated'] = false; $this->output_data['plugin_setup'] = false; if ( ! $this->output_data['plugin_installed'] && ! $this->output_data['pro_plugin_installed'] ) { $step['icon'] = 'step-1.svg'; $step['button_text'] = esc_html__( 'Install WP Mail SMTP', 'wp-mail-logging' ); $step['button_class'] = 'button-primary'; $step['button_action'] = 'install'; $step['plugin'] = ''; if ( ! $this->can_install_plugin() ) { $step['heading'] = esc_html__( 'WP Mail SMTP', 'wp-mail-logging' ); $step['description'] = ''; $step['button_text'] = esc_html__( 'WP Mail SMTP on WordPress.org', 'wp-mail-logging' ); $step['plugin'] = $this->config['lite_wporg_url']; } return $step; } $this->output_data['plugin_activated'] = $this->is_smtp_activated(); $this->output_data['plugin_setup'] = $this->is_smtp_configured(); $step['icon'] = $this->output_data['plugin_activated'] ? 'step-complete.svg' : 'step-1.svg'; $step['button_text'] = $this->output_data['plugin_activated'] ? esc_html__( 'WP Mail SMTP Installed & Activated', 'wp-mail-logging' ) : esc_html__( 'Activate WP Mail SMTP', 'wp-mail-logging' ); $step['button_class'] = $this->output_data['plugin_activated'] ? 'grey disabled' : 'button-primary'; $step['button_action'] = $this->output_data['plugin_activated'] ? '' : 'activate'; $step['plugin'] = $this->output_data['pro_plugin_installed'] ? $this->config['pro_plugin'] : $this->config['lite_plugin']; return $step; } /** * Determine if plugin installation is allowed. * * @since 1.11.0 * * @return bool */ private function can_install_plugin() { if ( ! current_user_can( 'install_plugins' ) || ! wp_is_file_mod_allowed( 'wp_mail_logging_can_install_plugin' ) ) { return false; } return true; } /** * Whether WP Mail SMTP plugin active or not. * * @since 1.11.0 * * @return bool True if SMTP plugin is active. */ private function is_smtp_activated() { return function_exists( 'wp_mail_smtp' ) && ( is_plugin_active( $this->config['lite_plugin'] ) || is_plugin_active( $this->config['pro_plugin'] ) ); } /** * Whether WP Mail SMTP plugin configured or not. * * @since 1.11.0 * * @return bool True if some mailer is selected and configured properly. */ private function is_smtp_configured() { if ( ! $this->is_smtp_activated() ) { return false; } $phpmailer = $this->get_phpmailer(); $mailer = \WPMailSMTP\Options::init()->get( 'mail', 'mailer' ); return ! empty( $mailer ) && $mailer !== 'mail' && wp_mail_smtp()->get_providers()->get_mailer( $mailer, $phpmailer )->is_mailer_complete(); } /** * Get $phpmailer instance. * * @since 1.11.0 * * @return \PHPMailer|\PHPMailer\PHPMailer\PHPMailer Instance of PHPMailer. */ private function get_phpmailer() { if ( version_compare( get_bloginfo( 'version' ), '5.5-alpha', '<' ) ) { $phpmailer = $this->get_phpmailer_v5(); } else { $phpmailer = $this->get_phpmailer_v6(); } return $phpmailer; } /** * Get $phpmailer v5 instance. * * @since 1.11.0 * * @return \PHPMailer Instance of PHPMailer. */ private function get_phpmailer_v5() { global $phpmailer; if ( ! ( $phpmailer instanceof \PHPMailer ) ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new \PHPMailer( true ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } return $phpmailer; } /** * Get $phpmailer v6 instance. * * @since 1.11.0 * * @return \PHPMailer\PHPMailer\PHPMailer Instance of PHPMailer. */ private function get_phpmailer_v6() { global $phpmailer; if ( ! ( $phpmailer instanceof \PHPMailer\PHPMailer\PHPMailer ) ) { require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; $phpmailer = new \PHPMailer\PHPMailer\PHPMailer( true ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } return $phpmailer; } /** * Generate and output step 'Setup' section HTML. * * @since 1.11.0 */ private function output_section_step_setup() { $step = $this->get_data_step_setup(); if ( empty( $step ) ) { return; } $assets_url = WPML_Init::getInstance()->getService( 'plugin' )->get_assets_url(); printf( '

%4$s

%5$s

', esc_attr( $step['section_class'] ), esc_url( $assets_url . '/images/smtp/' . $step['icon'] ), esc_attr__( 'Step 2', 'wp-mail-logging' ), esc_html__( 'Set Up WP Mail SMTP', 'wp-mail-logging' ), esc_html__( 'Select and configure your mailer.', 'wp-mail-logging' ), esc_attr( $step['button_class'] ), esc_url( admin_url( $this->config['smtp_wizard_url'] ) ), esc_html( $step['button_text'] ) ); } /** * Step 'Setup' data. * * @since 1.11.0 * * @return array Step data. */ protected function get_data_step_setup() { $step = [ 'icon' => 'step-2.svg', ]; if ( $this->output_data['plugin_activated'] ) { $step['section_class'] = ''; $step['button_class'] = 'button-primary'; $step['button_text'] = esc_html__( 'Open Setup Wizard', 'wp-mail-logging' ); } else { $step['section_class'] = 'grey'; $step['button_class'] = 'grey disabled'; $step['button_text'] = esc_html__( 'Start Setup', 'wp-mail-logging' ); } if ( $this->output_data['plugin_setup'] ) { $step['icon'] = 'step-complete.svg'; $step['button_text'] = esc_html__( 'Go to SMTP settings', 'wp-mail-logging' ); } return $step; } /** * Return the SMTP tab url. * * @since 1.11.0 * * @return string */ public static function get_url() { return add_query_arg( [ 'page' => 'wpml_plugin_log', 'tab' => 'smtp', ], admin_url( 'admin.php' ) ); } }