hooks();
}
/**
* Assign all hooks to proper places.
*
* @since 1.0.0
*/
protected function hooks() {
// Add the Settings link to a plugin on Plugins page.
add_filter( 'plugin_action_links_' . plugin_basename( WPMS_PLUGIN_FILE ), [ $this, 'add_plugin_action_link' ], 10, 1 );
// Add the options page.
add_action( 'admin_menu', [ $this, 'add_admin_options_page' ] );
// Register on load Email Log admin menu hook.
add_action( 'load-wp-mail-smtp_page_wp-mail-smtp-logs', [ $this, 'maybe_redirect_email_log_menu_to_email_log_settings_tab' ] );
// Admin footer text.
add_filter( 'admin_footer_text', [ $this, 'get_admin_footer' ], 1, 2 );
// Enqueue admin area scripts and styles.
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
// Process the admin page forms actions.
add_action( 'admin_init', [ $this, 'process_actions' ] );
// Display custom notices based on the error/success codes.
add_action( 'admin_init', [ $this, 'display_custom_auth_notices' ] );
// Display notice instructing the user to complete plugin setup.
add_action( 'admin_init', [ $this, 'display_setup_notice' ] );
// Outputs the plugin admin header.
add_action( 'in_admin_header', [ $this, 'display_admin_header' ], 100 );
// Hide all unrelated to the plugin notices on the plugin admin pages.
add_action( 'admin_print_scripts', [ $this, 'hide_unrelated_notices' ] );
// Process all AJAX requests.
add_action( 'wp_ajax_wp_mail_smtp_ajax', [ $this, 'process_ajax' ] );
( new Review() )->hooks();
}
/**
* Display custom notices based on the error/success codes.
*
* @since 1.0.0
*/
public function display_custom_auth_notices() {
$error = isset( $_GET['error'] ) ? sanitize_key( $_GET['error'] ) : ''; // phpcs:ignore
$success = isset( $_GET['success'] ) ? sanitize_key( $_GET['success'] ) : ''; // phpcs:ignore
if ( empty( $error ) && empty( $success ) ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
switch ( $error ) {
case 'google_access_denied':
WP::add_admin_notice( /* translators: %s - error code, returned by Google API. */
sprintf( esc_html__( 'There was an error while processing the authentication request: %s. Please try again.', 'wp-mail-smtp' ), '' . $error . '' ),
WP::ADMIN_NOTICE_ERROR
);
break;
case 'google_no_code_scope':
case 'microsoft_no_code':
WP::add_admin_notice(
esc_html__( 'There was an error while processing the authentication request. Please try again.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_ERROR
);
break;
case 'google_no_clients':
WP::add_admin_notice(
esc_html__( 'There was an error while processing the authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_ERROR
);
break;
}
switch ( $success ) {
case 'google_site_linked':
WP::add_admin_notice(
esc_html__( 'You have successfully linked the current site with your Google API project. Now you can start sending emails through Gmail.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
break;
case 'microsoft_site_linked':
WP::add_admin_notice(
esc_html__( 'You have successfully linked the current site with your Microsoft API project. Now you can start sending emails through Outlook.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
break;
}
}
/**
* Display notice instructing the user to complete plugin setup.
*
* @since 1.3.0
*/
public function display_setup_notice() {
// Bail if we're not on a plugin page.
if ( ! $this->is_admin_page( 'general' ) ) {
return;
}
$default_options = wp_json_encode( Options::get_defaults() );
$current_options = wp_json_encode( Options::init()->get_all() );
// Check if the current settings are the same as the default settings.
if ( $current_options !== $default_options ) {
return;
}
// Display notice informing user further action is needed.
WP::add_admin_notice(
sprintf(
wp_kses( /* translators: %s - Mailer anchor link. */
__( 'Thanks for using WP Mail SMTP! To complete the plugin setup and start sending emails, please select and configure your Mailer.', 'wp-mail-smtp' ),
[
'a' => [
'href' => [],
],
'strong' => [],
]
),
wp_mail_smtp()->get_admin()->get_admin_page_url( self::SLUG . '#wp-mail-smtp-setting-row-mailer' )
),
WP::ADMIN_NOTICE_INFO
);
}
/**
* Add admin area menu item.
*
* @since 1.0.0
* @since 1.5.0 Moved the menu to the top level. Added several more pages.
*/
public function add_admin_options_page() {
$this->hook = \add_menu_page(
\esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
\esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
'manage_options',
self::SLUG,
array( $this, 'display' ),
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9IiM5ZWEzYTgiIHdpZHRoPSI2NCIgaGVpZ2h0PSI2NCIgdmlld0JveD0iMCAwIDQzIDM0Ij48cGF0aCBkPSJNMC4wMDcsMy41ODVWMjAuNDIxcTAsMy41ODYsMy43NTEsMy41ODVMMjAsMjRWMTlIMzBWMTQuMDE0bDAuOTkxLTFMMzQsMTNWMy41ODVRMzQsMCwzMC4yNDksMEgzLjc1OFEwLjAwNywwLC4wMDcsMy41ODVoMFpNMy41MjQsNi4xNTdhMS40OSwxLjQ5LDAsMCwxLS41MDgtMC45MzUsMS41ODEsMS41ODEsMCwwLDEsLjI3NC0xLjIwOCwxLjQ0OSwxLjQ0OSwwLDAsMSwxLjA5NC0uNjYzLDEuNzU2LDEuNzU2LDAsMCwxLDEuMjUuMzEybDExLjQwOSw3LjcxNkwyOC4zNzQsMy42NjNhMS45NiwxLjk2LDAsMCwxLDEuMjg5LS4zMTIsMS41NDYsMS41NDYsMCwwLDEsMS4wOTQuNjYzLDEuNCwxLjQsMCwwLDEsLjI3MywxLjIwOCwxLjY3LDEuNjcsMCwwLDEtLjU0Ny45MzVMMTcuMDQzLDE3LjIyNVoiLz48cGF0aCBkPSJNMjIsMjhIMzJsLTAuMDA5LDQuNjI0YTEuMTI2LDEuMTI2LDAsMCwwLDEuOTIyLjhsOC4yNS04LjIzNmExLjEyNiwxLjEyNiwwLDAsMCwwLTEuNTk0bC04LjI1LTguMjQxYTEuMTI2LDEuMTI2LDAsMCwwLTEuOTIyLjh2NC44NjZMMjIsMjF2N1oiLz48L3N2Zz4=',
98
);
\add_submenu_page(
self::SLUG,
$this->get_current_tab_title() . ' ‹ ' . \esc_html__( 'Settings', 'wp-mail-smtp' ),
\esc_html__( 'Settings', 'wp-mail-smtp' ),
'manage_options',
self::SLUG,
array( $this, 'display' )
);
\add_submenu_page(
self::SLUG,
\esc_html__( 'Email Log', 'wp-mail-smtp' ),
\esc_html__( 'Email Log', 'wp-mail-smtp' ),
'manage_options',
self::SLUG . '-logs',
array( $this, 'display' )
);
if ( ! wp_mail_smtp()->is_white_labeled() ) {
\add_submenu_page(
self::SLUG,
\esc_html__( 'About Us', 'wp-mail-smtp' ),
\esc_html__( 'About Us', 'wp-mail-smtp' ),
'manage_options',
self::SLUG . '-about',
array( $this, 'display' )
);
}
}
/**
* Redirect the "Email Log" WP menu link to the "Email Log" setting tab for lite version of the plugin.
*
* @since 2.1.0
*/
public function maybe_redirect_email_log_menu_to_email_log_settings_tab() {
/**
* The Email Logs object to be used for loading the Email Log page.
*
* @var \WPMailSMTP\Admin\PageAbstract $logs
*/
$logs = $this->generate_display_logs_object();
if ( $logs instanceof \WPMailSMTP\Admin\Pages\Logs ) {
wp_safe_redirect( $logs->get_link() );
exit;
}
}
/**
* Enqueue admin area scripts and styles.
*
* @since 1.0.0
* @since 1.5.0 Added new assets for new pages.
* @since 1.7.0 Added jQuery Confirm library css/js files.
*
* @param string $hook Current hook.
*/
public function enqueue_assets( $hook ) {
if ( strpos( $hook, self::SLUG ) === false ) {
return;
}
// General styles and js.
\wp_enqueue_style(
'wp-mail-smtp-admin',
\wp_mail_smtp()->assets_url . '/css/smtp-admin.min.css',
false,
WPMS_PLUGIN_VER
);
\wp_enqueue_script(
'wp-mail-smtp-admin',
\wp_mail_smtp()->assets_url . '/js/smtp-admin' . WP::asset_min() . '.js',
array( 'jquery' ),
WPMS_PLUGIN_VER,
false
);
\wp_localize_script(
'wp-mail-smtp-admin',
'wp_mail_smtp',
array(
'text_provider_remove' => esc_html__( 'Are you sure you want to reset the current provider connection? You will need to immediately create a new one to be able to send emails.', 'wp-mail-smtp' ),
'text_settings_not_saved' => esc_html__( 'Changes that you made to the settings are not saved!', 'wp-mail-smtp' ),
'default_mailer_notice' => array(
'title' => esc_html__( 'Heads up!', 'wp-mail-smtp' ),
'content' => wp_kses(
__( '
The Default (PHP) mailer is currently selected, but is not recommended because in most cases it does not resolve email delivery issues.
Please consider selecting and configuring one of the other mailers.
is_admin_page() ) {
$url = 'https://wordpress.org/support/plugin/wp-mail-smtp/reviews/?filter=5#new-post';
$text = sprintf(
wp_kses(
/* translators: %1$s - WP.org link; %2$s - same WP.org link. */
__( 'Please rate WP Mail SMTP★★★★★ on WordPress.org to help us spread the word. Thank you from the WP Mail SMTP team!', 'wp-mail-smtp' ),
array(
'strong' => array(),
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
),
$url,
$url
);
}
return $text;
}
/**
* Display content of the admin area page.
*
* @since 1.0.0
* @since 1.5.0 Rewrite to distinguish between General tabs and separate pages.
*/
public function display() {
// Bail if we're not on a plugin page.
if ( ! $this->is_admin_page() ) {
return;
}
$page = ! empty( $_GET['page'] ) ? \sanitize_key( $_GET['page'] ) : ''; // phpcs:ignore
?>