esc_html__( 'Is WP Mail SMTP mailer setup complete?', 'wp-mail-smtp' ), 'test' => array( $this, 'mailer_setup_complete_test' ), ); $tests['direct']['wp_mail_smtp_db_tables_exist'] = array( 'label' => esc_html__( 'Do WP Mail SMTP DB tables exist?', 'wp-mail-smtp' ), 'test' => [ $this, 'db_tables_test' ], ); return $tests; } /** * Register plugin WP Site Health debug information. * This will be displayed in the "Info" tab of the WP Site Health page. * * @since 1.9.0 * * @param array $debug_info Array of existing debug information. * * @return array */ public function register_debug_information( $debug_info ) { $debug_notices = Debug::get(); $db_tables = $this->get_db_tables( 'existing' ); $debug_info[ self::DEBUG_INFO_SLUG ] = [ 'label' => $this->get_label(), 'fields' => [ 'version' => [ 'label' => esc_html__( 'Version', 'wp-mail-smtp' ), 'value' => WPMS_PLUGIN_VER, ], 'license_key_type' => [ 'label' => esc_html__( 'License key type', 'wp-mail-smtp' ), 'value' => wp_mail_smtp()->get_license_type(), ], 'debug' => [ 'label' => esc_html__( 'Debug', 'wp-mail-smtp' ), 'value' => ! empty( $debug_notices ) ? implode( '. ', $debug_notices ) : esc_html__( 'No debug notices found.', 'wp-mail-smtp' ), ], 'db_tables' => [ 'label' => esc_html__( 'DB tables', 'wp-mail-smtp' ), 'value' => ! empty( $db_tables ) ? implode( ', ', $db_tables ) : esc_html__( 'No DB tables found.', 'wp-mail-smtp' ), ], ], ]; // Install date. $activated = get_option( 'wp_mail_smtp_activated', [] ); if ( ! empty( $activated['lite'] ) ) { $date = $activated['lite'] + ( get_option( 'gmt_offset' ) * 3600 ); $debug_info[ self::DEBUG_INFO_SLUG ]['fields']['lite_install_date'] = [ 'label' => esc_html__( 'Lite install date', 'wp-mail-smtp' ), 'value' => date_i18n( esc_html__( 'M j, Y @ g:ia' ), $date ), ]; } return $debug_info; } /** * Perform the WP site health test for checking, if the mailer setup is complete. * * @since 1.9.0 */ public function mailer_setup_complete_test() { $mailer = Options::init()->get( 'mail', 'mailer' ); $mailer_complete = false; $mailer_title = esc_html__( 'None selected', 'wp-mail-smtp' ); if ( ! empty( $mailer ) ) { $mailer_complete = wp_mail_smtp() ->get_providers() ->get_mailer( $mailer, wp_mail_smtp()->get_processor()->get_phpmailer() )->is_mailer_complete(); $mailer_title = wp_mail_smtp()->get_providers()->get_options( $mailer )->get_title(); } // The default mailer should be considered as a non-complete mailer. if ( $mailer === 'mail' ) { $mailer_complete = false; } $mailer_text = sprintf( '%s: %s', esc_html__( 'Current mailer', 'wp-mail-smtp' ), esc_html( $mailer_title ) ); $result = array( 'label' => esc_html__( 'WP Mail SMTP mailer setup is complete', 'wp-mail-smtp' ), 'status' => 'good', 'badge' => array( 'label' => $this->get_label(), 'color' => self::BADGE_COLOR, ), 'description' => sprintf( '

%s

%s

', $mailer_text, esc_html__( 'The WP Mail SMTP plugin mailer setup is complete. You can send a test email, to make sure it\'s working properly.', 'wp-mail-smtp' ) ), 'actions' => sprintf( '

%s

', esc_url( add_query_arg( 'tab', 'test', wp_mail_smtp()->get_admin()->get_admin_page_url() ) ), esc_html__( 'Test email sending', 'wp-mail-smtp' ) ), 'test' => 'wp_mail_smtp_mailer_setup_complete', ); if ( $mailer === 'mail' ) { $mailer_text .= sprintf( /* translators: %s - explanation why default mailer is not a valid mailer option. */ '

%s

', esc_html__( 'You currently have the default mailer selected, which means that you haven’t set up SMTP yet.', 'wp-mail-smtp' ) ); } if ( $mailer_complete === false ) { $result['label'] = esc_html__( 'WP Mail SMTP mailer setup is incomplete', 'wp-mail-smtp' ); $result['status'] = 'recommended'; $result['badge']['color'] = 'orange'; $result['description'] = sprintf( '

%s

%s

', $mailer_text, esc_html__( 'The WP Mail SMTP plugin mailer setup is incomplete. Please click on the link below to access plugin settings and configure the mailer.', 'wp-mail-smtp' ) ); $result['actions'] = sprintf( '

%s

', esc_url( wp_mail_smtp()->get_admin()->get_admin_page_url() ), esc_html__( 'Configure mailer', 'wp-mail-smtp' ) ); } return $result; } /** * Perform the test for checking if all custom plugin DB tables exist. * * @since 2.1.2 * * @return array */ public function db_tables_test() { $result = array( 'label' => esc_html__( 'WP Mail SMTP DB tables are created', 'wp-mail-smtp' ), 'status' => 'good', 'badge' => array( 'label' => $this->get_label(), 'color' => self::BADGE_COLOR, ), 'description' => esc_html__( 'WP Mail SMTP is using custom database tables for some of its features. In order to work properly, the custom tables should be created, and it looks like they exist in your database.', 'wp-mail-smtp' ), 'actions' => '', 'test' => 'wp_mail_smtp_db_tables_exist', ); $missing_tables = $this->get_db_tables( 'missing' ); if ( ! empty( $missing_tables ) ) { $result['label'] = esc_html__( 'WP Mail SMTP DB tables check has failed', 'wp-mail-smtp' ); $result['status'] = 'critical'; $result['badge']['color'] = 'red'; $result['description'] = sprintf( '

%s

%s

', sprintf( /* translators: %s - the list of missing tables separated by comma. */ esc_html( _n( 'Missing table: %s', 'Missing tables: %s', count( $missing_tables ), 'wp-mail-smtp' ) ), esc_html( implode( ', ', $missing_tables ) ) ), esc_html__( 'WP Mail SMTP is using custom database tables for some of its features. In order to work properly, the custom tables should be created, and it seems they are missing. Please try to re-install the WP Mail SMTP plugin. If this issue persists, please contact our support.', 'wp-mail-smtp' ) ); } return $result; } /** * Check DB: * - if any required plugin DB table is missing, * - which of the required plugin DB tables exist. * * @since 2.1.2 * * @param string $check Which type of tables to return: 'missing' or 'existing'. * * @return array Missing or existing tables. */ private function get_db_tables( $check = 'missing' ) { global $wpdb; $tables = wp_mail_smtp()->get_custom_db_tables(); $missing_tables = []; $existing_tables = []; foreach ( $tables as $table ) { $db_result = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ); // phpcs:ignore if ( strtolower( $db_result ) !== strtolower( $table ) ) { $missing_tables[] = $table; } else { $existing_tables[] = $table; } } return ( $check === 'existing' ) ? $existing_tables : $missing_tables; } }