Initial commit

This commit is contained in:
2020-04-07 13:03:04 +00:00
committed by Gitium
commit 00f842d9bf
1673 changed files with 471161 additions and 0 deletions

View File

@ -0,0 +1,891 @@
<?php
namespace WPMailSMTP\Admin;
use WPMailSMTP\WP;
use WPMailSMTP\Options;
/**
* Class Area registers and process all wp-admin display functionality.
*
* @since 1.0.0
*/
class Area {
/**
* @since 1.0.0
*
* @var string Slug of the admin area page.
*/
const SLUG = 'wp-mail-smtp';
/**
* @since 1.0.0
*
* @var string Admin page unique hook.
*/
public $hook;
/**
* @since 1.0.0
*
* @var PageAbstract[]
*/
private $pages;
/**
* @since 1.5.0
*
* @var array List of official registered pages.
*/
public static $pages_registered = array( 'general', 'logs', 'about' );
/**
* Area constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->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', array( $this, 'add_plugin_action_link' ), 10, 2 );
// Add the options page.
add_action( 'admin_menu', array( $this, 'add_admin_options_page' ) );
// Admin footer text.
add_filter( 'admin_footer_text', array( $this, 'get_admin_footer' ), 1, 2 );
// Enqueue admin area scripts and styles.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
// Process the admin page forms actions.
add_action( 'admin_init', array( $this, 'process_actions' ) );
// Display custom notices based on the error/success codes.
add_action( 'admin_init', array( $this, 'display_custom_auth_notices' ) );
// Display notice instructing the user to complete plugin setup.
add_action( 'admin_init', array( $this, 'display_setup_notice' ) );
// Outputs the plugin admin header.
add_action( 'in_admin_header', array( $this, 'display_admin_header' ), 100 );
// Hide all unrelated to the plugin notices on the plugin admin pages.
add_action( 'admin_print_scripts', array( $this, 'hide_unrelated_notices' ) );
// Process all AJAX requests.
add_action( 'wp_ajax_wp_mail_smtp_ajax', array( $this, 'process_ajax' ) );
}
/**
* 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' ), '<code>' . $error . '</code>' ),
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, <strong>please select and configure your <a href="%s">Mailer</a></strong>.', 'wp-mail-smtp' ),
array(
'a' => array(
'href' => array(),
),
'strong' => array(),
)
),
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() . ' &lsaquo; ' . \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' )
);
\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' )
);
}
/**
* 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
*/
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' ),
'education' => array(
'upgrade_icon_lock' => '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="lock" class="svg-inline--fa fa-lock fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"></path></svg>',
'upgrade_title' => esc_html__( '%name% is a PRO Feature', 'wp-mail-smtp' ),
'upgrade_button' => esc_html__( 'Upgrade to Pro', 'wp-mail-smtp' ),
'upgrade_url' => 'https://wpmailsmtp.com/lite-upgrade/?discount=SMTPLITEUPGRADE&utm_source=WordPress&utm_medium=plugin-settings&utm_campaign=liteplugin',
'upgrade_bonus' => '<p>' .
wp_kses(
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span>20% off</span> regular price,<br>applied at checkout.', 'wp-mail-smtp' ),
array(
'strong' => true,
'span' => true,
'br' => true,
)
)
. '</p>',
'upgrade_doc' => '<a href="https://wpmailsmtp.com/docs/how-to-upgrade-wp-mail-smtp-to-pro-version/?utm_source=WordPress&amp;utm_medium=link&amp;utm_campaign=liteplugin" target="_blank" rel="noopener noreferrer" class="already-purchased">
' . esc_html__( 'Already purchased?', 'wp-mail-smtp' ) . '
</a>',
),
)
);
/*
* jQuery Confirm library v3.3.4.
*/
\wp_enqueue_style(
'wp-mail-smtp-admin-jconfirm',
\wp_mail_smtp()->assets_url . '/libs/jquery-confirm.min.css',
array( 'wp-mail-smtp-admin' ),
'3.3.4'
);
\wp_enqueue_script(
'wp-mail-smtp-admin-jconfirm',
\wp_mail_smtp()->assets_url . '/libs/jquery-confirm.min.js',
array( 'wp-mail-smtp-admin' ),
'3.3.4',
false
);
/*
* Logs page.
*/
if ( $this->is_admin_page( 'logs' ) ) {
\wp_enqueue_style(
'wp-mail-smtp-admin-logs',
apply_filters( 'wp_mail_smtp_admin_enqueue_assets_logs_css', '' ),
array( 'wp-mail-smtp-admin' ),
WPMS_PLUGIN_VER
);
\wp_enqueue_script(
'wp-mail-smtp-admin-logs',
apply_filters( 'wp_mail_smtp_admin_enqueue_assets_logs_js', '' ),
array( 'wp-mail-smtp-admin' ),
WPMS_PLUGIN_VER,
false
);
}
/*
* About page.
*/
if ( $this->is_admin_page( 'about' ) ) {
\wp_enqueue_style(
'wp-mail-smtp-admin-about',
\wp_mail_smtp()->assets_url . '/css/smtp-about.min.css',
array( 'wp-mail-smtp-admin' ),
WPMS_PLUGIN_VER
);
\wp_enqueue_script(
'wp-mail-smtp-admin-about',
\wp_mail_smtp()->assets_url . '/js/smtp-about' . WP::asset_min() . '.js',
array( 'wp-mail-smtp-admin' ),
'0.7.2',
false
);
$settings = array(
'ajax_url' => \admin_url( 'admin-ajax.php' ),
'nonce' => \wp_create_nonce( 'wp-mail-smtp-about' ),
// Strings.
'plugin_activate' => \esc_html__( 'Activate', 'wp-mail-smtp' ),
'plugin_activated' => \esc_html__( 'Activated', 'wp-mail-smtp' ),
'plugin_active' => \esc_html__( 'Active', 'wp-mail-smtp' ),
'plugin_inactive' => \esc_html__( 'Inactive', 'wp-mail-smtp' ),
'plugin_processing' => \esc_html__( 'Processing...', 'wp-mail-smtp' ),
'plugin_install_error' => \esc_html__( 'Could not install a plugin. Please download from WordPress.org and install manually.', 'wp-mail-smtp' ),
'plugin_install_activate_btn' => \esc_html__( 'Install and Activate', 'wp-mail-smtp' ),
'plugin_activate_btn' => \esc_html__( 'Activate', 'wp-mail-smtp' ),
'plugin_download_btn' => \esc_html__( 'Download', 'wp-mail-smtp' ),
);
\wp_localize_script(
'wp-mail-smtp-admin-about',
'wp_mail_smtp_about',
$settings
);
\wp_enqueue_script(
'wp-mail-smtp-admin-about-matchheight',
\wp_mail_smtp()->assets_url . '/js/jquery.matchHeight.min.js',
array( 'wp-mail-smtp-admin' ),
'0.7.2',
false
);
}
do_action( 'wp_mail_smtp_admin_area_enqueue_assets', $hook );
}
/**
* Outputs the plugin admin header.
*
* @since 1.0.0
*/
public function display_admin_header() {
// Bail if we're not on a plugin page.
if ( ! $this->is_admin_page() ) {
return;
}
?>
<div id="wp-mail-smtp-header-temp"></div>
<div id="wp-mail-smtp-header">
<!--suppress HtmlUnknownTarget -->
<img class="wp-mail-smtp-header-logo" src="<?php echo esc_url( wp_mail_smtp()->assets_url ); ?>/images/logo.svg" alt="WP Mail SMTP"/>
</div>
<?php
}
/**
* Display a text to ask users to review the plugin on WP.org.
*
* @since 1.0.0
*
* @param string $text
*
* @return string
*/
public function get_admin_footer( $text ) {
if ( $this->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 <strong>WP Mail SMTP</strong> <a href="%1$s" target="_blank" rel="noopener noreferrer">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%2$s" target="_blank" rel="noopener noreferrer">WordPress.org</a> 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
?>
<div class="wrap" id="wp-mail-smtp">
<?php
switch ( $page ) {
case self::SLUG:
?>
<div class="wp-mail-smtp-page wp-mail-smtp-page-general wp-mail-smtp-tab-<?php echo esc_attr( $this->get_current_tab() ); ?>">
<?php $this->display_tabs(); ?>
</div>
<?php
break;
case self::SLUG . '-logs':
$logs_class = apply_filters( 'wp_mail_smtp_admin_display_get_logs_fqcn', '\WPMailSMTP\Admin\Pages\Logs' );
/** @var \WPMailSMTP\Admin\PageAbstract $logs */
$logs = new $logs_class();
$is_archive = wp_mail_smtp()->is_pro() && wp_mail_smtp()->pro->get_logs()->is_archive();
?>
<div class="wp-mail-smtp-page wp-mail-smtp-page-logs <?php echo $is_archive ? 'wp-mail-smtp-page-logs-archive' : 'wp-mail-smtp-page-logs-single'; ?>">
<?php $logs->display(); ?>
</div>
<?php
break;
case self::SLUG . '-about':
$about = new Pages\About();
?>
<div class="wp-mail-smtp-page wp-mail-smtp-page-about wp-mail-smtp-tab-about-<?php echo \esc_attr( $about->get_current_tab() ); ?>">
<?php $about->display(); ?>
</div>
<?php
break;
}
?>
</div>
<?php
}
/**
* Display General page tabs.
*
* @since 1.5.0
*/
protected function display_tabs() {
?>
<div class="wp-mail-smtp-page-title">
<?php
foreach ( $this->get_pages() as $page_slug => $page ) :
$label = $page->get_label();
if ( empty( $label ) ) {
continue;
}
$class = $page_slug === $this->get_current_tab() ? 'active' : '';
?>
<a href="<?php echo esc_url( $page->get_link() ); ?>" class="tab <?php echo esc_attr( $class ); ?>">
<?php echo esc_html( $label ); ?>
</a>
<?php endforeach; ?>
</div>
<div class="wp-mail-smtp-page-content">
<h1 class="screen-reader-text">
<?php echo esc_html( $this->get_current_tab_title() ); ?>
</h1>
<?php $this->display_current_tab_content(); ?>
</div>
<?php
}
/**
* Get the current tab content.
*
* @since 1.0.0
*/
public function display_current_tab_content() {
$pages = $this->get_pages();
if ( ! array_key_exists( $this->get_current_tab(), $pages ) ) {
return;
}
$pages[ $this->get_current_tab() ]->display();
}
/**
* Get the current admin area tab.
*
* @since 1.0.0
*
* @return string
*/
protected function get_current_tab() {
$current = '';
if ( $this->is_admin_page( 'general' ) ) {
$current = ! empty( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings'; // phpcs:ignore
}
return $current;
}
/**
* Get the array of default registered tabs for General page admin area.
*
* @since 1.0.0
*
* @return \WPMailSMTP\Admin\PageAbstract[]
*/
public function get_pages() {
if ( empty( $this->pages ) ) {
$this->pages = array(
'settings' => new Pages\SettingsTab(),
'test' => new Pages\TestTab(),
'logs' => new Pages\LogsTab(),
'control' => new Pages\ControlTab(),
'misc' => new Pages\MiscTab(),
'auth' => new Pages\AuthTab(),
);
}
return apply_filters( 'wp_mail_smtp_admin_get_pages', $this->pages );
}
/**
* Get the current tab title.
*
* @since 1.0.0
*
* @return string
*/
public function get_current_tab_title() {
$pages = $this->get_pages();
if ( ! array_key_exists( $this->get_current_tab(), $pages ) ) {
return '';
}
return $pages[ $this->get_current_tab() ]->get_title();
}
/**
* Check whether we are on an admin page.
*
* @since 1.0.0
* @since 1.5.0 Added support for new pages.
*
* @param array|string $slug ID(s) of a plugin page. Possible values: 'general', 'logs', 'about' or array of them.
*
* @return bool
*/
public function is_admin_page( $slug = array() ) {
$cur_page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : ''; // phpcs:ignore
$check = self::SLUG;
$pages_equal = false;
if ( is_string( $slug ) ) {
$slug = sanitize_key( $slug );
if (
in_array( $slug, self::$pages_registered, true ) &&
$slug !== 'general'
) {
$check = self::SLUG . '-' . $slug;
}
$pages_equal = $cur_page === $check;
} elseif ( is_array( $slug ) ) {
if ( empty( $slug ) ) {
$slug = array_map( function ( $v ) {
if ( $v === 'general' ) {
return Area::SLUG;
}
return Area::SLUG . '-' . $v;
}, self::$pages_registered );
} else {
$slug = array_map( function ( $v ) {
if ( $v === 'general' ) {
return Area::SLUG;
}
return Area::SLUG . '-' . sanitize_key( $v );
}, $slug );
}
$pages_equal = in_array( $cur_page, $slug, true );
}
return is_admin() && $pages_equal;
}
/**
* Give ability to use either admin area option or a filter to hide error notices about failed email delivery.
* Filter has higher priority and overrides an option.
*
* @since 1.6.0
*
* @return bool
*/
public function is_error_delivery_notice_enabled() {
$is_hard_enabled = (bool) apply_filters( 'wp_mail_smtp_admin_is_error_delivery_notice_enabled', true );
// If someone changed the value to false using a filter - disable completely.
if ( ! $is_hard_enabled ) {
return false;
}
return ! (bool) Options::init()->get( 'general', 'email_delivery_errors_hidden' );
}
/**
* All possible plugin forms manipulation will be done here.
*
* @since 1.0.0
*/
public function process_actions() {
// Bail if we're not on a plugin General page.
if ( ! $this->is_admin_page( 'general' ) ) {
return;
}
$pages = $this->get_pages();
// Allow to process only own tabs.
if ( ! array_key_exists( $this->get_current_tab(), $pages ) ) {
return;
}
// Process POST only if it exists.
if ( ! empty( $_POST ) ) {
if ( ! empty( $_POST['wp-mail-smtp'] ) ) {
$post = $_POST['wp-mail-smtp'];
} else {
$post = array();
}
$pages[ $this->get_current_tab() ]->process_post( $post );
}
// This won't do anything for most pages.
// Works for plugin page only, when GET params are allowed.
$pages[ $this->get_current_tab() ]->process_auth();
}
/**
* Process all AJAX requests.
*
* @since 1.3.0
* @since 1.5.0 Added tasks to process plugins management.
*/
public function process_ajax() {
$data = array();
// Only admins can fire these ajax requests.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( $data );
}
if ( empty( $_POST['task'] ) ) { // phpcs:ignore
wp_send_json_error( $data );
}
$task = sanitize_key( $_POST['task'] ); // phpcs:ignore
switch ( $task ) {
case 'pro_banner_dismiss':
update_user_meta( get_current_user_id(), 'wp_mail_smtp_pro_banner_dismissed', true );
$data['message'] = esc_html__( 'WP Mail SMTP Pro related message was successfully dismissed.', 'wp-mail-smtp' );
break;
case 'about_plugin_install':
Pages\About::ajax_plugin_install();
break;
case 'about_plugin_activate':
Pages\About::ajax_plugin_activate();
break;
case 'notice_dismiss':
$notice = sanitize_key( $_POST['notice'] ); // phpcs:ignore
$mailer = sanitize_key( $_POST['mailer'] ); // phpcs:ignore
if ( empty( $notice ) || empty( $mailer ) ) {
break;
}
update_user_meta( get_current_user_id(), "wp_mail_smtp_notice_{$notice}_for_{$mailer}_dismissed", true );
$data['message'] = esc_html__( 'Educational notice for this mailer was successfully dismissed.', 'wp-mail-smtp' );
break;
default:
// Allow custom tasks data processing being added here.
$data = apply_filters( 'wp_mail_smtp_admin_process_ajax_' . $task . '_data', $data );
}
// Final ability to rewrite all the data, just in case.
$data = (array) apply_filters( 'wp_mail_smtp_admin_process_ajax_data', $data, $task );
if ( empty( $data ) ) {
wp_send_json_error( $data );
}
wp_send_json_success( $data );
}
/**
* Add a link to Settings page of a plugin on Plugins page.
*
* @since 1.0.0
* @since 1.5.0 Added a link to Email Log.
*
* @param array $links
* @param string $file
*
* @return mixed
*/
public function add_plugin_action_link( $links, $file ) {
// Will target both pro and lite version of a plugin.
if ( strpos( $file, 'wp-mail-smtp' ) === false ) {
return $links;
}
$settings_link = '<a href="' . esc_url( $this->get_admin_page_url() ) . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
$logs_link = '<a href="' . esc_url( $this->get_admin_page_url( self::SLUG . '-logs' ) ) . '">' . esc_html__( 'Email Log', 'wp-mail-smtp' ) . '</a>';
array_unshift( $links, $settings_link, $logs_link );
return $links;
}
/**
* Get plugin admin area page URL.
*
* @since 1.0.0
* @since 1.5.0 URL is changed to support the top level position of the plugin admin area.
*
* @param string $page
*
* @return string
*/
public function get_admin_page_url( $page = '' ) {
if ( empty( $page ) ) {
$page = self::SLUG;
}
return add_query_arg(
'page',
$page,
admin_url( 'admin.php' )
);
}
/**
* Remove all non-WP Mail SMTP plugin notices from plugin pages.
*
* @since 1.0.0
*/
public function hide_unrelated_notices() {
// Bail if we're not on our screen or page.
if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], self::SLUG ) === false ) {
return;
}
global $wp_filter;
if ( ! empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) {
foreach ( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) {
foreach ( $hooks as $name => $arr ) {
if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
continue;
}
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
continue;
}
if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
}
}
}
}
if ( ! empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) {
foreach ( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) {
foreach ( $hooks as $name => $arr ) {
if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
continue;
}
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
continue;
}
if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
}
}
}
}
if ( ! empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) {
foreach ( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) {
foreach ( $hooks as $name => $arr ) {
if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
continue;
}
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
continue;
}
if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
}
}
}
}
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace WPMailSMTP\Admin;
/**
* Class PageAbstract.
*
* @since 1.0.0
*/
abstract class PageAbstract implements PageInterface {
/**
* @var string Slug of a tab.
*/
protected $slug;
/**
* @inheritdoc
*/
public function get_link() {
return esc_url(
add_query_arg(
'tab',
$this->slug,
admin_url( 'admin.php?page=' . Area::SLUG )
)
);
}
/**
* Process tab form submission ($_POST ).
*
* @since 1.0.0
*
* @param array $data $_POST data specific for the plugin.
*/
public function process_post( $data ) {
}
/**
* Process tab & mailer specific Auth actions.
*
* @since 1.0.0
*/
public function process_auth() {
}
/**
* Print the nonce field for a specific tab.
*
* @since 1.0.0
*/
public function wp_nonce_field() {
wp_nonce_field( Area::SLUG . '-' . $this->slug );
}
/**
* Make sure that a user was referred from plugin admin page.
* To avoid security problems.
*
* @since 1.0.0
*/
public function check_admin_referer() {
check_admin_referer( Area::SLUG . '-' . $this->slug );
}
/**
* Save button to be reused on other tabs.
*
* @since 1.5.0
*/
public function display_save_btn() {
?>
<p class="wp-mail-smtp-submit">
<button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange">
<?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?>
</button>
</p>
<?php
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace WPMailSMTP\Admin;
/**
* Class PageInterface defines what should be in each page class.
*
* @since 1.0.0
*/
interface PageInterface {
/**
* URL to a tab.
*
* @since 1.0.0
*
* @return string
*/
public function get_link();
/**
* Title of a tab.
*
* @since 1.0.0
*
* @return string
*/
public function get_title();
/**
* Link label of a tab.
*
* @since 1.0.0
*
* @return string
*/
public function get_label();
/**
* Tab content.
*
* @since 1.0.0
*/
public function display();
}

View File

@ -0,0 +1,717 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\Area;
use WPMailSMTP\Admin\PageAbstract;
use WPMailSMTP\Admin\PluginsInstallSkin;
use WPMailSMTP\Admin\PluginsInstallUpgrader;
/**
* Class About to display a page with About Us and Versus content.
*
* @since 1.5.0
*/
class About extends PageAbstract {
/**
* @since 1.5.0
*
* @var string Slug of a page.
*/
protected $slug = 'about';
/**
* @since 1.5.0
*
* @var array List of supported tabs.
*/
protected $tabs = array( 'about', 'versus' );
/**
* Get the page/tab link.
*
* @since 1.5.0
*
* @param string $tab Tab to generate a link to.
*
* @return string
*/
public function get_link( $tab = '' ) {
return add_query_arg(
'tab',
$this->get_defined_tab( $tab ),
admin_url( 'admin.php?page=' . Area::SLUG . '-' . $this->slug )
);
}
/**
* Get the current tab.
*
* @since 1.5.0
*
* @return string Current tab.
*/
public function get_current_tab() {
if ( empty( $_GET['tab'] ) ) { // phpcs:ignore
return $this->slug;
}
return $this->get_defined_tab( $_GET['tab'] ); // phpcs:ignore
}
/**
* Get the defined or default tab.
*
* @since 1.5.0
*
* @param string $tab Tab to check.
*
* @return string Defined tab. Fallback to default one if it doesn't exist.
*/
protected function get_defined_tab( $tab ) {
$tab = \sanitize_key( $tab );
return \in_array( $tab, $this->tabs, true ) ? $tab : $this->slug;
}
/**
* Get label for a tab.
* Process only those that exists.
* Defaults to "About Us".
*
* @since 1.5.0
*
* @param string $tab Tab to get label for.
*
* @return string
*/
public function get_label( $tab = '' ) {
switch ( $this->get_defined_tab( $tab ) ) {
case 'versus':
$label = \sprintf(
/* translators: %s - plugin current license type. */
\esc_html__( '%s vs Pro', 'wp-mail-smtp' ),
\ucfirst( \wp_mail_smtp()->get_license_type() )
);
break;
case 'about':
default:
$label = \esc_html__( 'About Us', 'wp-mail-smtp' );
break;
}
return $label;
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label( $this->get_current_tab() );
}
/**
* Display About page content based on the current tab.
*
* @since 1.5.0
*/
public function display() {
?>
<div class="wp-mail-smtp-page-title">
<a href="<?php echo \esc_url( $this->get_link() ); ?>" class="tab <?php echo $this->get_current_tab() === 'about' ? 'active' : ''; ?>">
<?php echo \esc_html( $this->get_label( 'about' ) ); ?>
</a>
<?php if ( \wp_mail_smtp()->get_license_type() === 'lite' ) : ?>
<a href="<?php echo \esc_url( $this->get_link( 'versus' ) ); ?>" class="tab <?php echo $this->get_current_tab() === 'versus' ? 'active' : ''; ?>">
<?php echo \esc_html( $this->get_label( 'versus' ) ); ?>
</a>
<?php endif; ?>
</div>
<div class="wp-mail-smtp-page-content">
<h1 class="screen-reader-text">
<?php echo \esc_html( $this->get_label( $this->get_current_tab() ) ); ?>
</h1>
<?php
$callback = 'display_' . $this->get_current_tab();
if ( \method_exists( $this, $callback ) ) {
$this->{$callback}();
} else {
$this->display_about();
}
?>
</div>
<?php
}
/**
* Display an "About Us" tab content.
*
* @since 1.5.0
*/
protected function display_about() {
?>
<div class="wp-mail-smtp-admin-about-section wp-mail-smtp-admin-columns">
<div class="wp-mail-smtp-admin-column-60">
<h3>
<?php esc_html_e( 'Hello and welcome to WP Mail SMTP, the easiest and most popular WordPress SMTP plugin. We build software that helps your site reliably deliver emails every time.', 'wp-mail-smtp' ); ?>
</h3>
<p>
<?php esc_html_e( 'Email deliverability has been a well-documented problem for all WordPress websites. However as WPForms grew, we became more aware of this painful issue that affects our users and the larger WordPress community. So we decided to solve this problem and make a solution that\'s beginner friendly.', 'wp-mail-smtp' ); ?>
</p>
<p>
<?php esc_html_e( 'Our goal is to make reliable email deliverability easy for WordPress.', 'wp-mail-smtp' ); ?>
</p>
<p>
<?php
printf(
wp_kses(
/* translators: %1$s - WPForms URL, %2$s - WPBeginner URL, %3$s - OptinMonster URL, %4$s - MonsterInsights URL, %5$s - RafflePress URL */
__( 'WP Mail SMTP is brought to you by the same team that\'s behind the most user friendly WordPress forms, <a href="%1$s" target="_blank" rel="noopener noreferrer">WPForms</a>, the largest WordPress resource site, <a href="%2$s" target="_blank" rel="noopener noreferrer">WPBeginner</a>, the most popular lead-generation software, <a href="%3$s" target="_blank" rel="noopener noreferrer">OptinMonster</a>, the best WordPress analytics plugin, <a href="%4$s" target="_blank" rel="noopener noreferrer">MonsterInsights</a>, and the most powerful WordPress contest plugin, <a href="%5$s" target="_blank" rel="noopener noreferrer">RafflePress</a>.', 'wp-mail-smtp' ),
array(
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
'https://wpforms.com/?utm_source=wpmailsmtpplugin&utm_medium=pluginaboutpage&utm_campaign=aboutwpmailsmtp',
'https://www.wpbeginner.com/?utm_source=wpmailsmtpplugin&utm_medium=pluginaboutpage&utm_campaign=aboutwpmailsmtp',
'https://optinmonster.com/?utm_source=wpmailsmtpplugin&utm_medium=pluginaboutpage&utm_campaign=aboutwpmailsmtp',
'https://www.monsterinsights.com/?utm_source=wpmailsmtpplugin&utm_medium=pluginaboutpage&utm_campaign=aboutwpmailsmtp',
'https://rafflepress.com/?utm_source=wpmailsmtpplugin&utm_medium=pluginaboutpage&utm_campaign=aboutwpmailsmtp'
);
?>
</p>
<p>
<?php esc_html_e( 'Yup, we know a thing or two about building awesome products that customers love.', 'wp-mail-smtp' ); ?>
</p>
</div>
<div class="wp-mail-smtp-admin-column-40 wp-mail-smtp-admin-column-last">
<figure>
<img src="<?php echo esc_url( wp_mail_smtp()->assets_url . '/images/about/team.jpg' ); ?>" alt="<?php esc_attr_e( 'The WPForms Team photo', 'wp-mail-smtp' ); ?>">
<figcaption>
<?php esc_html_e( 'The WPForms Team', 'wp-mail-smtp' ); ?>
</figcaption>
</figure>
</div>
</div>
<div class="wp-mail-smtp-admin-about-plugins">
<div class="plugins-container">
<?php
foreach ( $this->get_am_plugins() as $key => $plugin ) :
$is_url_external = false;
$data = $this->get_about_plugins_data( $plugin );
if ( isset( $plugin['pro'] ) && \array_key_exists( $plugin['pro']['path'], \get_plugins() ) ) {
$is_url_external = true;
$plugin = $plugin['pro'];
$data = array_merge( $data, $this->get_about_plugins_data( $plugin, true ) );
}
?>
<div class="plugin-container">
<div class="plugin-item">
<div class="details wp-mail-smtp-clear">
<img src="<?php echo \esc_url( $plugin['icon'] ); ?>">
<h5 class="plugin-name">
<?php echo $plugin['name']; ?>
</h5>
<p class="plugin-desc">
<?php echo $plugin['desc']; ?>
</p>
</div>
<div class="actions wp-mail-smtp-clear">
<div class="status">
<strong>
<?php
\printf(
/* translators: %s - status HTML text. */
\esc_html__( 'Status: %s', 'wp-mail-smtp' ),
'<span class="status-label ' . $data['status_class'] . '">' . $data['status_text'] . '</span>'
);
?>
</strong>
</div>
<div class="action-button">
<?php
$go_to_class = '';
if ( $is_url_external && $data['status_class'] === 'status-download' ) {
$go_to_class = 'go_to';
}
?>
<a href="<?php echo \esc_url( $plugin['url'] ); ?>"
class="<?php echo \esc_attr( $data['action_class'] ); ?> <?php echo $go_to_class; ?>"
data-plugin="<?php echo $data['plugin_src']; ?>">
<?php echo $data['action_text']; ?>
</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php
}
/**
* Generate all the required CSS classed and labels to be used in rendering.
*
* @since 1.5.0
*
* @param array $plugin
* @param bool $is_pro
*
* @return mixed
*/
protected function get_about_plugins_data( $plugin, $is_pro = false ) {
$data = array();
if ( \array_key_exists( $plugin['path'], \get_plugins() ) ) {
if ( \is_plugin_active( $plugin['path'] ) ) {
// Status text/status.
$data['status_class'] = 'status-active';
$data['status_text'] = \esc_html__( 'Active', 'wp-mail-smtp' );
// Button text/status.
$data['action_class'] = $data['status_class'] . ' button button-secondary disabled';
$data['action_text'] = \esc_html__( 'Activated', 'wp-mail-smtp' );
$data['plugin_src'] = \esc_attr( $plugin['path'] );
} else {
// Status text/status.
$data['status_class'] = 'status-inactive';
$data['status_text'] = \esc_html__( 'Inactive', 'wp-mail-smtp' );
// Button text/status.
$data['action_class'] = $data['status_class'] . ' button button-secondary';
$data['action_text'] = \esc_html__( 'Activate', 'wp-mail-smtp' );
$data['plugin_src'] = \esc_attr( $plugin['path'] );
}
} else {
if ( ! $is_pro ) {
// Doesn't exist, install.
// Status text/status.
$data['status_class'] = 'status-download';
$data['status_text'] = \esc_html__( 'Not Installed', 'wp-mail-smtp' );
// Button text/status.
$data['action_class'] = $data['status_class'] . ' button button-primary';
$data['action_text'] = \esc_html__( 'Install Plugin', 'wp-mail-smtp' );
$data['plugin_src'] = \esc_url( $plugin['url'] );
}
}
return $data;
}
/**
* List of AM plugins that we propose to install.
*
* @since 1.5.0
*
* @return array
*/
private function get_am_plugins() {
$data = array(
'mi' => array(
'path' => 'google-analytics-for-wordpress/googleanalytics.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-mi.png',
'name' => \esc_html__( 'MonsterInsights', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'MonsterInsights makes it “effortless” to properly connect your WordPress site with Google Analytics, so you can start making data-driven decisions to grow your business.', 'wp-mail-smtp' ),
'url' => 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.zip',
'pro' => array(
'path' => 'google-analytics-premium/googleanalytics-premium.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-mi.png',
'name' => \esc_html__( 'MonsterInsights Pro', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'MonsterInsights makes it “effortless” to properly connect your WordPress site with Google Analytics, so you can start making data-driven decisions to grow your business.', 'wp-mail-smtp' ),
'url' => 'https://www.monsterinsights.com/?utm_source=WordPress&utm_medium=about&utm_campaign=smtp',
),
),
'om' => array(
'path' => 'optinmonster/optin-monster-wp-api.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-om.png',
'name' => \esc_html__( 'OptinMonster', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'Our high-converting optin forms like Exit-Intent® popups, Fullscreen Welcome Mats, and Scroll boxes help you dramatically boost conversions and get more email subscribers.', 'wp-mail-smtp' ),
'url' => 'https://downloads.wordpress.org/plugin/optinmonster.zip',
),
'wpforms' => array(
'path' => 'wpforms-lite/wpforms.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-wpf.png',
'name' => \esc_html__( 'Contact Forms by WPForms', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'The best WordPress contact form plugin. Drag & Drop online form builder that helps you create beautiful contact forms with just a few clicks.', 'wp-mail-smtp' ),
'url' => 'https://downloads.wordpress.org/plugin/wpforms-lite.zip',
'pro' => array(
'path' => 'wpforms/wpforms.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-wpf.png',
'name' => \esc_html__( 'WPForms Pro', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'The best WordPress contact form plugin. Drag & Drop online form builder that helps you create beautiful contact forms with just a few clicks.', 'wp-mail-smtp' ),
'url' => 'https://wpforms.com/?utm_source=WordPress&utm_medium=about&utm_campaign=smtp',
),
),
'rafflepress' => array(
'path' => 'rafflepress/rafflepress.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-rp.png',
'name' => \esc_html__( 'RafflePress', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'Turn your visitors into brand ambassadors! Easily grow your email list, website traffic, and social media followers with powerful viral giveaways & contests.', 'wp-mail-smtp' ),
'url' => 'https://downloads.wordpress.org/plugin/rafflepress.zip',
'pro' => array(
'path' => 'rafflepress-pro/rafflepress-pro.php',
'icon' => \wp_mail_smtp()->assets_url . '/images/about/plugin-rp.png',
'name' => \esc_html__( 'RafflePress Pro', 'wp-mail-smtp' ),
'desc' => \esc_html__( 'Turn your visitors into brand ambassadors! Easily grow your email list, website traffic, and social media followers with powerful viral giveaways & contests.', 'wp-mail-smtp' ),
'url' => 'https://rafflepress.com/pricing/',
),
),
);
return $data;
}
/**
* Active the given plugin.
*
* @since 1.5.0
*/
public static function ajax_plugin_activate() {
// Run a security check.
\check_ajax_referer( 'wp-mail-smtp-about', 'nonce' );
$error = \esc_html__( 'Could not activate the plugin. Please activate it from the Plugins page.', 'wp-mail-smtp' );
// Check for permissions.
if ( ! \current_user_can( 'activate_plugins' ) ) {
\wp_send_json_error( $error );
}
if ( isset( $_POST['plugin'] ) ) {
$activate = \activate_plugins( $_POST['plugin'] ); // phpcs:ignore
if ( ! \is_wp_error( $activate ) ) {
\wp_send_json_success( esc_html__( 'Plugin activated.', 'wp-mail-smtp' ) );
}
}
\wp_send_json_error( $error );
}
/**
* Install & activate the given plugin.
*
* @since 1.5.0
*/
public static function ajax_plugin_install() {
// Run a security check.
\check_ajax_referer( 'wp-mail-smtp-about', 'nonce' );
$error = \esc_html__( 'Could not install the plugin.', 'wp-mail-smtp' );
// Check for permissions.
if ( ! \current_user_can( 'activate_plugins' ) ) {
\wp_send_json_error( $error );
}
if ( empty( $_POST['plugin'] ) ) {
\wp_send_json_error();
}
// Set the current screen to avoid undefined notices.
\set_current_screen( 'wp-mail-smtp_page_wp-mail-smtp-about' );
// Prepare variables.
$url = \esc_url_raw(
\add_query_arg(
array(
'page' => 'wp-mail-smtp-about',
),
\admin_url( 'admin.php' )
)
);
$creds = \request_filesystem_credentials( $url, '', false, false, null );
// Check for file system permissions.
if ( false === $creds ) {
\wp_send_json_error( $error );
}
if ( ! \WP_Filesystem( $creds ) ) {
\wp_send_json_error( $error );
}
// Do not allow WordPress to search/download translations, as this will break JS output.
\remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
// Create the plugin upgrader with our custom skin.
$installer = new PluginsInstallUpgrader( new PluginsInstallSkin() );
// Error check.
if ( ! \method_exists( $installer, 'install' ) || empty( $_POST['plugin'] ) ) {
\wp_send_json_error( $error );
}
$installer->install( $_POST['plugin'] ); // phpcs:ignore
// Flush the cache and return the newly installed plugin basename.
\wp_cache_flush();
if ( $installer->plugin_info() ) {
$plugin_basename = $installer->plugin_info();
// Activate the plugin silently.
$activated = \activate_plugin( $plugin_basename );
if ( ! \is_wp_error( $activated ) ) {
\wp_send_json_success(
array(
'msg' => \esc_html__( 'Plugin installed & activated.', 'wp-mail-smtp' ),
'is_activated' => true,
'basename' => $plugin_basename,
)
);
} else {
\wp_send_json_success(
array(
'msg' => esc_html__( 'Plugin installed.', 'wp-mail-smtp' ),
'is_activated' => false,
'basename' => $plugin_basename,
)
);
}
}
\wp_send_json_error( $error );
}
/**
* Display a "Lite vs Pro" tab content.
*
* @since 1.5.0
*/
protected function display_versus() {
$license = \wp_mail_smtp()->get_license_type();
?>
<div class="wp-mail-smtp-admin-about-section wp-mail-smtp-admin-about-section-squashed">
<h1 class="centered">
<strong>
<?php
\printf(
/* translators: %s - plugin current license type. */
\esc_html__( '%s vs Pro', 'wp-mail-smtp' ),
\esc_html( \ucfirst( $license ) )
);
?>
</strong>
</h1>
<p class="centered <?php echo ( $license === 'pro' ? 'hidden' : '' ); ?>">
<?php esc_html_e( 'Get the most out of WP Mail SMTP by upgrading to Pro and unlocking all of the powerful features.', 'wp-mail-smtp' ); ?>
</p>
</div>
<div class="wp-mail-smtp-admin-about-section wp-mail-smtp-admin-about-section-squashed wp-mail-smtp-admin-about-section-hero wp-mail-smtp-admin-about-section-table">
<div class="wp-mail-smtp-admin-about-section-hero-main wp-mail-smtp-admin-columns">
<div class="wp-mail-smtp-admin-column-33">
<h3 class="no-margin">
<?php esc_html_e( 'Feature', 'wp-mail-smtp' ); ?>
</h3>
</div>
<div class="wp-mail-smtp-admin-column-33">
<h3 class="no-margin">
<?php echo esc_html( ucfirst( $license ) ); ?>
</h3>
</div>
<div class="wp-mail-smtp-admin-column-33">
<h3 class="no-margin">
<?php esc_html_e( 'Pro', 'wp-mail-smtp' ); ?>
</h3>
</div>
</div>
<div class="wp-mail-smtp-admin-about-section-hero-extra no-padding wp-mail-smtp-admin-columns">
<table>
<?php
foreach ( $this->get_license_features() as $slug => $name ) {
$current = $this->get_license_data( $slug, $license );
$pro = $this->get_license_data( $slug, 'pro' );
?>
<tr class="wp-mail-smtp-admin-columns">
<td class="wp-mail-smtp-admin-column-33">
<p><?php echo $name; ?></p>
</td>
<td class="wp-mail-smtp-admin-column-33">
<p class="features-<?php echo esc_attr( $current['status'] ); ?>">
<?php echo \implode( '<br>', $current['text'] ); ?>
</p>
</td>
<td class="wp-mail-smtp-admin-column-33">
<p class="features-full">
<?php echo \implode( '<br>', $pro['text'] ); ?>
</p>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<?php if ( 'lite' === $license ) : ?>
<div class="wp-mail-smtp-admin-about-section wp-mail-smtp-admin-about-section-hero">
<div class="wp-mail-smtp-admin-about-section-hero-main no-border">
<h3 class="call-to-action centered">
<a href="<?php echo esc_url( wp_mail_smtp()->get_upgrade_link( 'lite-vs-pro' ) ); ?>" target="_blank" rel="noopener noreferrer">
<?php \esc_html_e( 'Get WP Mail SMTP Pro Today and Unlock all of these Powerful Features', 'wp-mail-smtp' ); ?>
</a>
</h3>
<p class="centered">
<?php
echo \wp_kses(
\__( 'Bonus: WP Mail SMTP Lite users get <span class="price-off">20% off regular price</span>, automatically applied at checkout.', 'wp-mail-smtp' ),
array(
'span' => array(
'class' => array(),
),
)
);
?>
</p>
</div>
</div>
<?php endif; ?>
<?php
}
/**
* Get the list of features for all licenses.
*
* @since 1.5.0
*
* @return array
*/
private function get_license_features() {
return array(
'log' => \esc_html__( 'Email Log', 'wp-mail-smtp' ),
'control' => \esc_html__( 'Email Controls', 'wp-mail-smtp' ),
'mailers' => \esc_html__( 'Additional Mailers', 'wp-mail-smtp' ),
'support' => \esc_html__( 'Customer Support', 'wp-mail-smtp' ),
);
}
/**
* Get the array of data that compared the license data.
*
* @since 1.5.0
*
* @param string $feature Feature name.
* @param string $license License type to get data for.
*
* @return array|false
*/
private function get_license_data( $feature, $license ) {
$data = array(
'log' => array(
'lite' => array(
'status' => 'none',
'text' => array(
'<strong>' . esc_html__( 'Emails are not logged', 'wp-mail-smtp' ) . '</strong>',
),
),
'pro' => array(
'status' => 'full',
'text' => array(
'<strong>' . esc_html__( 'Complete Email Log management inside WordPress', 'wp-mail-smtp' ) . '</strong>',
),
),
),
'control' => array(
'lite' => array(
'status' => 'none',
'text' => array(
'<strong>' . esc_html__( 'No controls over whether default WordPress emails are sent', 'wp-mail-smtp' ) . '</strong>',
),
),
'pro' => array(
'status' => 'full',
'text' => array(
'<strong>' . esc_html__( 'Complete Email Controls management for most default WordPress emails', 'wp-mail-smtp' ) . '</strong>',
),
),
),
'mailers' => array(
'lite' => array(
'status' => 'none',
'text' => array(
'<strong>' . esc_html__( 'Only default list of mailers', 'wp-mail-smtp' ) . '</strong>',
),
),
'pro' => array(
'status' => 'full',
'text' => array(
'<strong>' . esc_html__( 'Additional mailers: Microsoft Outlook (with Office365 support) and Amazon SES', 'wp-mail-smtp' ) . '</strong>',
),
),
),
'support' => array(
'lite' => array(
'status' => 'none',
'text' => array(
'<strong>' . esc_html__( 'Limited Support', 'wp-mail-smtp' ) . '</strong>',
),
),
'pro' => array(
'status' => 'full',
'text' => array(
'<strong>' . esc_html__( 'Priority Support', 'wp-mail-smtp' ) . '</strong>',
),
),
),
);
// Wrong feature?
if ( ! isset( $data[ $feature ] ) ) {
return false;
}
// Wrong license type?
if ( ! isset( $data[ $feature ][ $license ] ) ) {
return false;
}
return $data[ $feature ][ $license ];
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Options;
use WPMailSMTP\Providers\AuthAbstract;
/**
* Class AuthTab.
*
* @since 1.0.0
*/
class AuthTab {
/**
* @var string Slug of a tab.
*/
protected $slug = 'auth';
/**
* Launch mailer specific Auth logic.
*
* @since 1.0.0
*/
public function process_auth() {
$auth = wp_mail_smtp()->get_providers()->get_auth( Options::init()->get( 'mail', 'mailer' ) );
if (
$auth &&
$auth instanceof AuthAbstract &&
method_exists( $auth, 'process' )
) {
$auth->process();
}
}
/**
* Return nothing, as we don't need this functionality.
*
* @since 1.0.0
*/
public function get_label() {
return '';
}
/**
* Return nothing, as we don't need this functionality.
*
* @since 1.0.0
*/
public function get_title() {
return '';
}
/**
* Do nothing, as we don't need this functionality.
*
* @since 1.0.0
*/
public function display() {
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\PageAbstract;
/**
* Class ControlTab is a placeholder for Pro Email Control tab settings.
* Displays an upsell.
*
* @since 1.6.0
*/
class ControlTab extends PageAbstract {
/**
* @since 1.6.0
*
* @var string Slug of a tab.
*/
protected $slug = 'control';
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'Email Controls', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
$features = array(
array(
'image' => 'comments.png',
'title' => esc_html__( 'Comment Notifications', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Manage emails sent when comments are published or awaiting moderation.', 'wp-mail-smtp' ),
),
array(
'image' => 'admin.png',
'title' => esc_html__( 'Site Admin Email Change Notifications', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Manage emails sent when site admin\'s account has been changed.', 'wp-mail-smtp' ),
),
array(
'image' => 'users.png',
'title' => esc_html__( 'User Change Notifications', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Limit emails triggered by password changed/reset, email changed, and more.', 'wp-mail-smtp' ),
),
array(
'image' => 'personal.png',
'title' => esc_html__( 'Personal Data Requests Notifications', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Control emails for data requests and data removal actions.', 'wp-mail-smtp' ),
),
array(
'image' => 'update.png',
'title' => esc_html__( 'Automatic Update Notifications', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Manage emails sent by the core automatic update process.', 'wp-mail-smtp' ),
),
array(
'image' => 'user_new.png',
'title' => esc_html__( 'New User Notifications', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Toggle emails sent to both user and site administrator about new user accounts.', 'wp-mail-smtp' ),
),
)
?>
<div class="wp-mail-smtp-page-upsell">
<h2><?php esc_html_e( 'Unlock Email Controls', 'wp-mail-smtp' ); ?></h2>
<h3>
<?php esc_html_e( 'Email Controls allows you to granularly manage emails sent by WordPress.', 'wp-mail-smtp' ); ?>
</h3>
<div class="wp-mail-smtp-page-upsell-content">
<div class="wp-mail-smtp-page-upsell-features">
<?php foreach ( $features as $feature ) : ?>
<div class="wp-mail-smtp-page-upsell-feature">
<div class="wp-mail-smtp-page-upsell-feature-image">
<img src="<?php echo esc_url( wp_mail_smtp()->assets_url . '/images/control/' . $feature['image'] ); ?>" alt="">
</div>
<div class="wp-mail-smtp-page-upsell-feature-content">
<h4><?php echo esc_html( $feature['title'] ); ?></h4>
<p><?php echo esc_html( $feature['desc'] ); ?></p>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="wp-mail-smtp-page-upsell-button">
<a href="https://wpmailsmtp.com/lite-upgrade/?discount=LITEUPGRADE&amp;utm_source=WordPress&amp;utm_medium=logs&amp;utm_campaign=liteplugin"
class="wp-mail-smtp-btn wp-mail-smtp-btn-lg wp-mail-smtp-btn-orange" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Upgrade to WP Mail SMTP Pro', 'wp-mail-smtp' ); ?>
</a>
</div>
</div>
<?php
}
/**
* Not used as we display an upsell.
*
* @since 1.6.0
*
* @param array $data
*/
public function process_post( $data ) {
}
}

View File

@ -0,0 +1,85 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\Area;
use WPMailSMTP\Admin\PageAbstract;
/**
* Class Logs
*/
class Logs extends PageAbstract {
/**
* @since 1.5.0
*
* @var string Slug of a page.
*/
protected $slug = 'logs';
/**
* Get the page/tab link.
*
* @since 1.5.0
*
* @return string
*/
public function get_link() {
return add_query_arg(
'page',
Area::SLUG . '-' . $this->slug,
admin_url( 'admin.php' )
);
}
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'Email Log', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
?>
<div class="wp-mail-smtp-page-title">
<h1 class="page-title">
<?php echo esc_html( $this->get_label() ); ?>
</h1>
</div>
<div class="wp-mail-smtp-page-upsell">
<h2><?php esc_html_e( 'Unlock Email Logging', 'wp-mail-smtp' ); ?></h2>
<h3>
<?php esc_html_e( 'Keep track of every email sent from your WordPress site with email logging.', 'wp-mail-smtp' ); ?><br>
<?php esc_html_e( 'Troubleshoot sending issues, recover lost emails, and more!', 'wp-mail-smtp' ); ?>
</h3>
<div class="wp-mail-smtp-page-upsell-images">
<img src="<?php echo esc_url( wp_mail_smtp()->assets_url . '/images/logs/archive.png' ); ?>" alt="<?php esc_attr_e( 'Logs Archive Page Screenshot', 'wp-mail-smtp' ); ?>">
<img src="<?php echo esc_url( wp_mail_smtp()->assets_url . '/images/logs/single.png' ); ?>" alt="<?php esc_attr_e( 'Logs Single Page Screenshot', 'wp-mail-smtp' ); ?>">
</div>
<div class="wp-mail-smtp-page-upsell-button">
<a href="https://wpmailsmtp.com/lite-upgrade/?discount=LITEUPGRADE&amp;utm_source=WordPress&amp;utm_medium=logs&amp;utm_campaign=liteplugin" class="wp-mail-smtp-btn wp-mail-smtp-btn-lg wp-mail-smtp-btn-orange wp-mail-smtp-upgrade-modal" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Upgrade to WP Mail SMTP Pro', 'wp-mail-smtp' ); ?>
</a>
</div>
</div>
<?php
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\Area;
use WPMailSMTP\Admin\PageAbstract;
/**
* Class LogsTab is a placeholder for Lite users and redirects them to Email Log page.
*
* @since 1.6.0
*/
class LogsTab extends PageAbstract {
/**
* Part of the slug of a tab.
*
* @since 1.6.0
*
* @var string
*/
protected $slug = 'logs';
/**
* @inheritdoc
*
* @since 1.6.0
*/
public function get_label() {
return esc_html__( 'Email Log', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*
* @since 1.6.0
*/
public function get_title() {
return $this->get_label();
}
/**
* Custom URL for this tab, redirects to Email Log page.
*
* @since 1.6.0
*
* @return string
*/
public function get_link() {
return wp_mail_smtp()->get_admin()->get_admin_page_url( Area::SLUG . '-' . $this->slug );
}
/**
* Not used as we are simply redirecting users.
*
* @since 1.6.0
*/
public function display() {
}
/**
* Not used as we are simply redirecting users.
*
* @since 1.6.0
*
* @param array $data
*/
public function process_post( $data ) {
}
}

View File

@ -0,0 +1,219 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\PageAbstract;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
/**
* Class MiscTab is part of Area, displays different plugin-related settings of the plugin (not related to emails).
*
* @since 1.0.0
*/
class MiscTab extends PageAbstract {
/**
* @var string Slug of a tab.
*/
protected $slug = 'misc';
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'Misc', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
$options = new Options();
?>
<form method="POST" action="">
<?php $this->wp_nonce_field(); ?>
<!-- Section Title -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php echo $this->get_title(); ?></h2>
</div>
</div>
<!-- Do not send -->
<div id="wp-mail-smtp-setting-row-do_not_send" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-do_not_send">
<?php esc_html_e( 'Do Not Send', 'wp-mail-smtp' ); ?>
</label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[general][do_not_send]" type="checkbox" value="true" id="wp-mail-smtp-setting-do_not_send"
<?php echo $options->is_const_defined( 'general', 'do_not_send' ) ? 'disabled' : ''; ?>
<?php checked( true, $options->get( 'general', 'do_not_send' ) ); ?>
>
<label for="wp-mail-smtp-setting-do_not_send">
<?php esc_html_e( 'Check this if you would like to stop sending all emails.', 'wp-mail-smtp' ); ?>
</label>
<p class="desc">
<?php
printf(
wp_kses(
__( 'Some plugins, like BuddyPress and Events Manager, are using their own email delivery solutions. By default, this option does not block their emails, as those plugins do not use default <code>wp_mail()</code> function to send emails.', 'wp-mail-smtp' ),
array(
'code' => array(),
)
)
);
?>
<br>
<?php esc_html_e( 'You will need to consult with their documentation to switch them to use default WordPress email delivery.', 'wp-mail-smtp' ); ?>
<br>
<?php esc_html_e( 'Test emails are allowed to be sent, regardless of this option.', 'wp-mail-smtp' ); ?>
<br>
<?php
if ( $options->is_const_defined( 'general', 'do_not_send' ) ) {
printf( /* translators: %1$s - constant that was used; %2$s - file where it was used. */
esc_html__( 'The value of this field was set using a constant %1$s most likely inside %2$s of your WordPress installation.', 'wp-mail-smtp' ),
'<code>WPMS_DO_NOT_SEND</code>',
'<code>wp-config.php</code>'
);
} else {
printf( /* translators: %1$s - constant to use; %2$s - file to put that constant in. */
esc_html__( 'If you want to disable using a constant, put %1$s in your %2$s file.', 'wp-mail-smtp' ),
'<code>define( \'WPMS_DO_NOT_SEND\', true );</code>',
'<code>wp-config.php</code>'
);
}
?>
</p>
</div>
</div>
<!-- Hide Announcements -->
<div id="wp-mail-smtp-setting-row-am_notifications_hidden" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-am_notifications_hidden">
<?php esc_html_e( 'Hide Announcements', 'wp-mail-smtp' ); ?>
</label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[general][am_notifications_hidden]" type="checkbox"
value="true" <?php checked( true, $options->get( 'general', 'am_notifications_hidden' ) ); ?>
id="wp-mail-smtp-setting-am_notifications_hidden"
>
<label for="wp-mail-smtp-setting-am_notifications_hidden">
<?php esc_html_e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?>
</label>
</div>
</div>
<!-- Hide Email Delivery Errors -->
<div id="wp-mail-smtp-setting-row-email_delivery_errors_hidden"
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-email_delivery_errors_hidden">
<?php esc_html_e( 'Hide Email Delivery Errors', 'wp-mail-smtp' ); ?>
</label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php
$is_hard_disabled = has_filter( 'wp_mail_smtp_admin_is_error_delivery_notice_enabled' ) && ! wp_mail_smtp()->get_admin()->is_error_delivery_notice_enabled();
?>
<?php if ( $is_hard_disabled ) : ?>
<input type="checkbox" disabled checked id="wp-mail-smtp-setting-email_delivery_errors_hidden">
<?php else : ?>
<input name="wp-mail-smtp[general][email_delivery_errors_hidden]" type="checkbox" value="true"
<?php checked( true, $options->get( 'general', 'email_delivery_errors_hidden' ) ); ?>
id="wp-mail-smtp-setting-email_delivery_errors_hidden">
<?php endif; ?>
<label for="wp-mail-smtp-setting-email_delivery_errors_hidden">
<?php esc_html_e( 'Check this if you would like to hide warnings alerting of email delivery errors.', 'wp-mail-smtp' ); ?>
</label>
<?php if ( $is_hard_disabled ) : ?>
<p class="desc">
<?php
printf( /* translators: %s - filter that was used to disabled. */
esc_html__( 'Email Delivery Errors were disabled using a %s filter.', 'wp-mail-smtp' ),
'<code>wp_mail_smtp_admin_is_error_delivery_notice_enabled</code>'
);
?>
</p>
<?php else : ?>
<p class="desc">
<?php
echo wp_kses(
__( '<strong>This is not recommended</strong> and should only be done for staging or development sites.', 'wp-mail-smtp' ),
array(
'strong' => true,
)
);
?>
</p>
<?php endif; ?>
</div>
</div>
<!-- Uninstall -->
<div id="wp-mail-smtp-setting-row-uninstall" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-uninstall">
<?php esc_html_e( 'Uninstall WP Mail SMTP', 'wp-mail-smtp' ); ?>
</label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[general][uninstall]" type="checkbox"
value="true" <?php checked( true, $options->get( 'general', 'uninstall' ) ); ?>
id="wp-mail-smtp-setting-uninstall">
<label for="wp-mail-smtp-setting-uninstall">
<?php esc_html_e( 'Check this if you would like to remove ALL WP Mail SMTP data upon plugin deletion. All settings will be unrecoverable.', 'wp-mail-smtp' ); ?>
</label>
</div>
</div>
<?php $this->display_save_btn(); ?>
</form>
<?php
}
/**
* @inheritdoc
*/
public function process_post( $data ) {
$this->check_admin_referer();
$options = new Options();
// Unchecked checkboxes doesn't exist in $_POST, so we need to ensure we actually have them in data to save.
if ( empty( $data['general']['am_notifications_hidden'] ) ) {
$data['general']['am_notifications_hidden'] = false;
}
if ( empty( $data['general']['uninstall'] ) ) {
$data['general']['uninstall'] = false;
}
$to_save = array_merge( $options->get_all(), $data );
// All the sanitization is done there.
$options->set( $to_save );
WP::add_admin_notice(
esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
}
}

View File

@ -0,0 +1,546 @@
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\PageAbstract;
use WPMailSMTP\Debug;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
/**
* Class SettingsTab is part of Area, displays general settings of the plugin.
*
* @since 1.0.0
*/
class SettingsTab extends PageAbstract {
/**
* Settings constructor.
*
* @since 1.5.0
*/
public function __construct() {
add_action( 'wp_mail_smtp_admin_pages_settings_license_key', array( __CLASS__, 'display_license_key_field_content' ) );
}
/**
* @var string Slug of a tab.
*/
protected $slug = 'settings';
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'General', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
$options = new Options();
$mailer = $options->get( 'mail', 'mailer' );
$disabled_email = 'gmail' === $mailer || 'outlook' === $mailer ? 'disabled' : '';
$disabled_name = 'outlook' === $mailer ? 'disabled' : '';
?>
<form method="POST" action="" autocomplete="off">
<?php $this->wp_nonce_field(); ?>
<!-- License Section Title -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading" id="wp-mail-smtp-setting-row-license-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php esc_html_e( 'License', 'wp-mail-smtp' ); ?></h2>
<p class="desc">
<?php esc_html_e( 'Your license key provides access to updates and support.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<!-- License Key -->
<div id="wp-mail-smtp-setting-row-license_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-license_key wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-license_key"><?php esc_html_e( 'License Key', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php do_action( 'wp_mail_smtp_admin_pages_settings_license_key', $options ); ?>
</div>
</div>
<!-- Mail Section Title -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php esc_html_e( 'Mail', 'wp-mail-smtp' ); ?></h2>
</div>
</div>
<!-- From Email -->
<div id="wp-mail-smtp-setting-row-from_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-from_email"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][from_email]" type="email"
value="<?php echo esc_attr( $options->get( 'mail', 'from_email' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_email' ) || ! empty( $disabled_email ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email" spellcheck="false"
placeholder="<?php echo esc_attr( wp_mail_smtp()->get_processor()->get_default_email() ); ?>">
<?php if ( empty( $disabled_email ) ) : ?>
<p class="desc">
<?php esc_html_e( 'The email address which emails are sent from.', 'wp-mail-smtp' ); ?><br/>
<?php esc_html_e( 'If you using an email provider (Gmail, Yahoo, Outlook.com, etc) this should be your email address for that account.', 'wp-mail-smtp' ); ?>
</p>
<p class="desc">
<?php esc_html_e( 'Please note that other plugins can change this, to prevent this use the setting below.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
<hr class="wp-mail-smtp-setting-mid-row-sep">
<input name="wp-mail-smtp[mail][from_email_force]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'from_email_force' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'from_email_force' ) || ! empty( $disabled_email ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email_force">
<label for="wp-mail-smtp-setting-from_email_force">
<?php esc_html_e( 'Force From Email', 'wp-mail-smtp' ); ?>
</label>
<?php if ( ! empty( $disabled_email ) ) : ?>
<p class="desc">
<?php esc_html_e( 'Current provider will automatically force From Email to be the email address that you use to set up the connection below.', 'wp-mail-smtp' ); ?>
</p>
<?php else : ?>
<p class="desc">
<?php esc_html_e( 'If checked, the From Email setting above will be used for all emails, ignoring values set by other plugins.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
</div>
</div>
<!-- From Name -->
<div id="wp-mail-smtp-setting-row-from_name" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][from_name]" type="text"
value="<?php echo esc_attr( $options->get( 'mail', 'from_name' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_name' ) || ! empty( $disabled_name ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name" spellcheck="false"
placeholder="<?php echo esc_attr( wp_mail_smtp()->get_processor()->get_default_name() ); ?>">
<?php if ( empty( $disabled_name ) ) : ?>
<p class="desc">
<?php esc_html_e( 'The name which emails are sent from.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
<hr class="wp-mail-smtp-setting-mid-row-sep">
<input name="wp-mail-smtp[mail][from_name_force]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'from_name_force' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'from_name_force' ) || ! empty( $disabled_name ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name_force">
<label for="wp-mail-smtp-setting-from_name_force">
<?php esc_html_e( 'Force From Name', 'wp-mail-smtp' ); ?>
</label>
<?php if ( ! empty( $disabled_name ) ) : ?>
<p class="desc">
<?php esc_html_e( 'Current provider doesn\'t support setting and forcing From Name. Emails will be sent on behalf of the account name used to setup the connection below.', 'wp-mail-smtp' ); ?>
</p>
<?php else : ?>
<p class="desc">
<?php esc_html_e( 'If checked, the From Name setting above will be used for all emails, ignoring values set by other plugins.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
</div>
</div>
<!-- Return Path -->
<div id="wp-mail-smtp-setting-row-return_path" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-return_path"><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][return_path]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'return_path' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'return_path' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-return_path">
<label for="wp-mail-smtp-setting-return_path">
<?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?>
</label>
<p class="desc">
<?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?><br/>
<?php esc_html_e( 'If unchecked, bounce messages may be lost. Some providers may ignore this option.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<!-- Mailer -->
<div id="wp-mail-smtp-setting-row-mailer" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-mailer wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-mailer"><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<div class="wp-mail-smtp-mailers">
<?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
<div class="wp-mail-smtp-mailer wp-mail-smtp-mailer-<?php echo esc_attr( $provider->get_slug() ); ?> <?php echo $mailer === $provider->get_slug() ? 'active' : ''; ?>">
<div class="wp-mail-smtp-mailer-image <?php echo $provider->is_recommended() ? 'is-recommended' : ''; ?>">
<img src="<?php echo esc_url( $provider->get_logo_url() ); ?>"
alt="<?php echo esc_attr( $provider->get_title() ); ?>">
</div>
<div class="wp-mail-smtp-mailer-text">
<?php if ( $provider->is_disabled() ) : ?>
<input type="radio" name="wp-mail-smtp[mail][mailer]" disabled class="educate"
id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
value="<?php echo esc_attr( $provider->get_slug() ); ?>"
/>
<?php else : ?>
<input id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
type="radio" name="wp-mail-smtp[mail][mailer]"
value="<?php echo esc_attr( $provider->get_slug() ); ?>"
<?php checked( $provider->get_slug(), $mailer ); ?>
<?php echo $options->is_const_defined( 'mail', 'mailer' ) || $provider->is_disabled() ? 'disabled' : ''; ?>
<?php echo $provider->is_disabled() ? 'class="educate"' : ''; ?>
/>
<?php endif; ?>
<label for="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>">
<?php echo esc_html( $provider->get_title() ); ?>
</label>
</div>
</div>
<?php endforeach; ?>
<!-- Suggest a mailer -->
<div class="wp-mail-smtp-mailer suggest-new">
<a href="https://wpmailsmtp.com/suggest-a-mailer" class="wp-mail-smtp-mailer-image" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Suggest a Mailer', 'wp-mail-smtp' ); ?>
</a>
<div class="wp-mail-smtp-mailer-text">
<label><?php esc_html_e( 'Suggest a Mailer', 'wp-mail-smtp' ); ?></label>
</div>
</div>
</div>
</div>
</div>
<!-- Mailer Options -->
<div class="wp-mail-smtp-mailer-options">
<?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
<?php $provider_desc = $provider->get_description(); ?>
<div class="wp-mail-smtp-mailer-option wp-mail-smtp-mailer-option-<?php echo esc_attr( $provider->get_slug() ); ?> <?php echo $mailer === $provider->get_slug() ? 'active' : 'hidden'; ?>">
<!-- Mailer Title/Notice/Description -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading <?php echo empty( $provider_desc ) ? 'no-desc' : ''; ?>" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<?php if ( $provider->is_disabled() ) : ?>
<?php $provider->display_options(); ?>
<?php else : ?>
<h2><?php echo $provider->get_title(); ?></h2>
<?php
$provider_edu_notice = $provider->get_notice( 'educational' );
$is_dismissed = (bool) get_user_meta( get_current_user_id(), "wp_mail_smtp_notice_educational_for_{$provider->get_slug()}_dismissed", true );
if ( ! empty( $provider_edu_notice ) && ! $is_dismissed ) :
?>
<p class="inline-notice inline-edu-notice"
data-notice="educational"
data-mailer="<?php echo esc_attr( $provider->get_slug() ); ?>">
<a href="#" title="<?php esc_attr_e( 'Dismiss this notice', 'wp-mail-smtp' ); ?>"
class="wp-mail-smtp-mailer-notice-dismiss js-wp-mail-smtp-mailer-notice-dismiss">
<span class="dashicons dashicons-dismiss"></span>
</a>
<?php echo $provider_edu_notice; ?>
</p>
<?php endif; ?>
<?php if ( ! empty( $provider_desc ) ) : ?>
<p class="desc"><?php echo $provider_desc; ?></p>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<?php $provider->display_options(); ?>
</div>
<?php endforeach; ?>
</div>
<?php $this->display_save_btn(); ?>
</form>
<?php
$this->display_wpforms();
$this->display_pro_banner();
}
/**
* License key text for a Lite version of the plugin.
*
* @since 1.5.0
*
* @param Options $options
*/
public static function display_license_key_field_content( $options ) {
?>
<p><?php esc_html_e( 'You\'re using WP Mail SMTP Lite - no license needed. Enjoy!', 'wp-mail-smtp' ); ?> 🙂</p>
<p>
<?php
printf(
wp_kses( /* translators: %s - WPMailSMTP.com upgrade URL. */
__( 'To unlock more features consider <strong><a href="%s" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-upgrade-modal">upgrading to PRO</a></strong>.', 'wp-mail-smtp' ),
array(
'a' => array(
'href' => array(),
'class' => array(),
'target' => array(),
'rel' => array(),
),
'strong' => array(),
)
),
esc_url( wp_mail_smtp()->get_upgrade_link( 'general-license-key' ) )
);
?>
</p>
<p class="desc">
<?php
echo wp_kses(
__( 'As a valued WP Mail SMTP Lite user you receive <strong>20% off</strong>, automatically applied at checkout!', 'wp-mail-smtp' ),
array(
'strong' => array(),
'br' => array(),
)
);
?>
</p>
<?php
}
/**
* Display a WPForms related message.
*
* @since 1.3.0
* @since 1.4.0 Display only to site admins.
* @since 1.5.0 Do nothing.
*/
protected function display_wpforms() {
/*
* Used to have this check:
*
* $is_dismissed = get_user_meta( get_current_user_id(), 'wp_mail_smtp_wpforms_dismissed', true );
*/
}
/**
* Display WP Mail SMTP Pro upgrade banner.
*
* @since 1.5.0
*/
protected function display_pro_banner() {
// Display only to site admins. Only site admins can install plugins.
if ( ! is_super_admin() ) {
return;
}
// Do not display if WP Mail SMTP Pro already installed.
if ( wp_mail_smtp()->is_pro() ) {
return;
}
$is_dismissed = get_user_meta( get_current_user_id(), 'wp_mail_smtp_pro_banner_dismissed', true );
// Do not display if user dismissed.
if ( (bool) $is_dismissed === true ) {
return;
}
?>
<div id="wp-mail-smtp-pro-banner">
<span class="wp-mail-smtp-pro-banner-dismiss">
<button id="wp-mail-smtp-pro-banner-dismiss">
<span class="dashicons dashicons-dismiss"></span>
</button>
</span>
<h2>
<?php esc_html_e( 'Get WP Mail SMTP Pro and Unlock all the Powerful Features', 'wp-mail-smtp' ); ?>
</h2>
<p>
<?php esc_html_e( 'Thanks for being a loyal WP Mail SMTP user. Upgrade to WP Mail SMTP Pro to unlock more awesome features and experience why WP Mail SMTP is the most popular SMTP plugin.', 'wp-mail-smtp' ); ?>
</p>
<p>
<?php esc_html_e( 'We know that you will truly love WP Mail SMTP. It\'s used by over 1,000,000 websites.', 'wp-mail-smtp' ); ?>
</p>
<p><strong><?php esc_html_e( 'Pro Features:', 'wp-mail-smtp' ); ?></strong></p>
<div class="benefits">
<ul>
<li><?php esc_html_e( 'Manage Notifications - control which emails your site sends', 'wp-mail-smtp' ); ?></li>
<li><?php esc_html_e( 'Email Logging - keep track of every email sent from your site', 'wp-mail-smtp' ); ?></li>
<li><?php esc_html_e( 'Office 365 - send emails using your Office 365 account', 'wp-mail-smtp' ); ?></li>
<li><?php esc_html_e( 'Amazon SES - harness the power of AWS', 'wp-mail-smtp' ); ?></li>
<li><?php esc_html_e( 'Outlook.com - send emails using your Outlook.com account', 'wp-mail-smtp' ); ?></li>
<li><?php esc_html_e( 'Access to our world class support team', 'wp-mail-smtp' ); ?></li>
</ul>
<ul>
<li><?php esc_html_e( 'White Glove Setup - sit back and relax while we handle everything for you', 'wp-mail-smtp' ); ?></li>
<li class="arrow-right"><?php esc_html_e( 'Install WP Mail SMTP Pro plugin', 'wp-mail-smtp' ); ?></li>
<li class="arrow-right"><?php esc_html_e( 'Set up domain name verification (DNS)', 'wp-mail-smtp' ); ?></li>
<li class="arrow-right"><?php esc_html_e( 'Configure Mailgun service', 'wp-mail-smtp' ); ?></li>
<li class="arrow-right"><?php esc_html_e( 'Set up WP Mail SMTP Pro plugin', 'wp-mail-smtp' ); ?></li>
<li class="arrow-right"><?php esc_html_e( 'Test and verify email delivery', 'wp-mail-smtp' ); ?></li>
</ul>
</div>
<p>
<?php
printf(
wp_kses( /* translators: %s - WPMailSMTP.com URL. */
__( '<a href="%s" target="_blank" rel="noopener noreferrer">Get WP Mail SMTP Pro Today and Unlock all the Powerful Features &raquo;</a>', 'wp-mail-smtp' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
'strong' => array(),
)
),
esc_url( wp_mail_smtp()->get_upgrade_link( 'general-cta' ) )
);
?>
</p>
<p>
<?php
echo wp_kses(
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span class="price-off">20% off regular price</span>, automatically applied at checkout.', 'wp-mail-smtp' ),
array(
'strong' => array(),
'span' => array(
'class' => array(),
),
)
);
?>
</p>
</div>
<?php
}
/**
* @inheritdoc
*/
public function process_post( $data ) {
$this->check_admin_referer();
$options = new Options();
$old_opt = $options->get_all();
// When checkbox is unchecked - it's not submitted at all, so we need to define its default false value.
if ( ! isset( $data['mail']['from_email_force'] ) ) {
$data['mail']['from_email_force'] = false;
}
if ( ! isset( $data['mail']['from_name_force'] ) ) {
$data['mail']['from_name_force'] = false;
}
if ( ! isset( $data['mail']['return_path'] ) ) {
$data['mail']['return_path'] = false;
}
if ( ! isset( $data['smtp']['autotls'] ) ) {
$data['smtp']['autotls'] = false;
}
if ( ! isset( $data['smtp']['auth'] ) ) {
$data['smtp']['auth'] = false;
}
// Remove all debug messages when switching mailers.
if (
! empty( $old_opt['mail']['mailer'] ) &&
! empty( $data['mail']['mailer'] ) &&
$old_opt['mail']['mailer'] !== $data['mail']['mailer']
) {
Debug::clear();
}
$to_redirect = false;
// Old and new Gmail client id/secret values are different - we need to invalidate tokens and scroll to Auth button.
if (
$options->get( 'mail', 'mailer' ) === 'gmail' &&
! empty( $data['gmail']['client_id'] ) &&
! empty( $data['gmail']['client_secret'] ) &&
(
$options->get( 'gmail', 'client_id' ) !== $data['gmail']['client_id'] ||
$options->get( 'gmail', 'client_secret' ) !== $data['gmail']['client_secret']
)
) {
unset( $old_opt['gmail'] );
if (
! empty( $data['gmail']['client_id'] ) &&
! empty( $data['gmail']['client_secret'] )
) {
$to_redirect = true;
}
}
// New gmail clients data will be added from new $data.
$to_save = Options::array_merge_recursive( $old_opt, $data );
// All the sanitization is done in Options class.
$options->set( $to_save );
if ( $to_redirect ) {
wp_redirect( $_POST['_wp_http_referer'] . '#wp-mail-smtp-setting-row-gmail-authorize' );
exit;
}
WP::add_admin_notice(
esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,55 @@
<?php
namespace WPMailSMTP\Admin;
/**
* WordPress class extended for on-the-fly plugin installations.
*
* @since 1.5.0
* @since 1.7.1 Removed feedback() method override to be compatible with PHP5.3+ and WP5.3.
*/
class PluginsInstallSkin extends \WP_Upgrader_Skin {
/**
* Empty out the header of its HTML content and only check to see if it has
* been performed or not.
*
* @since 1.5.0
*/
public function header() {
}
/**
* Empty out the footer of its HTML contents.
*
* @since 1.5.0
*/
public function footer() {
}
/**
* Instead of outputting HTML for errors, json_encode the errors and send them
* back to the Ajax script for processing.
*
* @since 1.5.0
*
* @param array $errors Array of errors with the install process.
*/
public function error( $errors ) {
if ( ! empty( $errors ) ) {
wp_send_json_error( $errors );
}
}
/**
* Empty out JavaScript output that calls function to decrement the update counts.
*
* @since 1.5.0
*
* @param string $type Type of update count to decrement.
*/
public function decrement_update_count( $type ) {
}
}

View File

@ -0,0 +1,576 @@
<?php
namespace WPMailSMTP\Admin;
use WP_Error;
use WP_Upgrader;
use WP_Filesystem_Base;
/** \WP_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
/** \Plugin_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
/**
* In WP 5.3 a PHP 5.6 splat operator (...$args) was added to \WP_Upgrader_Skin::feedback().
* We need to remove all calls to *Skin::feedback() method, as we can't override it in own Skin
* without breaking support for PHP 5.3-5.5.
*
* @internal Please do not use this class outside of core WPForms development. May be removed at any time.
*
* @since 1.7.1
*/
class PluginsInstallUpgrader extends \Plugin_Upgrader {
/**
* Run an upgrade/installation.
*
* Attempts to download the package (if it is not a local file), unpack it, and
* install it in the destination folder.
*
* @since 2.8.0
*
* @param array $options {
* Array or string of arguments for upgrading/installing a package.
*
* @type string $package The full path or URI of the package to install.
* Default empty.
* @type string $destination The full path to the destination folder.
* Default empty.
* @type bool $clear_destination Whether to delete any files already in the
* destination folder. Default false.
* @type bool $clear_working Whether to delete the files form the working
* directory after copying to the destination.
* Default false.
* @type bool $abort_if_destination_exists Whether to abort the installation if the destination
* folder already exists. When true, `$clear_destination`
* should be false. Default true.
* @type bool $is_multi Whether this run is one of multiple upgrade/installation
* actions being performed in bulk. When true, the skin
* WP_Upgrader::header() and WP_Upgrader::footer()
* aren't called. Default false.
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
* WP_Upgrader::run().
* }
* @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error,
* or false if unable to connect to the filesystem.
*/
public function run( $options ) {
$defaults = array(
'package' => '', // Please always pass this.
'destination' => '', // And this
'clear_destination' => false,
'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
'clear_working' => true,
'is_multi' => false,
'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
);
$options = wp_parse_args( $options, $defaults );
/**
* Filters the package options before running an update.
*
* See also {@see 'upgrader_process_complete'}.
*
* @since 4.3.0
*
* @param array $options {
* Options used by the upgrader.
*
* @type string $package Package for update.
* @type string $destination Update location.
* @type bool $clear_destination Clear the destination resource.
* @type bool $clear_working Clear the working resource.
* @type bool $abort_if_destination_exists Abort if the Destination directory exists.
* @type bool $is_multi Whether the upgrader is running multiple times.
* @type array $hook_extra {
* Extra hook arguments.
*
* @type string $action Type of action. Default 'update'.
* @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'.
* @type bool $bulk Whether the update process is a bulk update. Default true.
* @type string $plugin Path to the plugin file relative to the plugins directory.
* @type string $theme The stylesheet or template name of the theme.
* @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme',
* or 'core'.
* @type object $language_update The language pack update offer.
* }
* }
*/
$options = apply_filters( 'upgrader_package_options', $options );
if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
$this->skin->header();
}
// Connect to the Filesystem first.
$res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
// Mainly for non-connected filesystem.
if ( ! $res ) {
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return false;
}
$this->skin->before();
if ( is_wp_error( $res ) ) {
$this->skin->error( $res );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return $res;
}
/*
* Download the package (Note, This just returns the filename
* of the file if the package is a local file)
*/
$download = $this->download_package( $options['package'], true );
// Allow for signature soft-fail.
// WARNING: This may be removed in the future.
if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
// Don't output the 'no signature could be found' failure message for now.
if ( 'signature_verification_no_signature' != $download->get_error_code() || WP_DEBUG ) {
// Outout the failure error as a normal feedback, and not as an error:
//$this->skin->feedback( $download->get_error_message() );
// Report this failure back to WordPress.org for debugging purposes.
wp_version_check(
array(
'signature_failure_code' => $download->get_error_code(),
'signature_failure_data' => $download->get_error_data(),
)
);
}
// Pretend this error didn't happen.
$download = $download->get_error_data( 'softfail-filename' );
}
if ( is_wp_error( $download ) ) {
$this->skin->error( $download );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return $download;
}
$delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
// Unzips the file into a temporary directory.
$working_dir = $this->unpack_package( $download, $delete_package );
if ( is_wp_error( $working_dir ) ) {
$this->skin->error( $working_dir );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return $working_dir;
}
// With the given options, this installs it to the destination directory.
$result = $this->install_package(
array(
'source' => $working_dir,
'destination' => $options['destination'],
'clear_destination' => $options['clear_destination'],
'abort_if_destination_exists' => $options['abort_if_destination_exists'],
'clear_working' => $options['clear_working'],
'hook_extra' => $options['hook_extra'],
)
);
$this->skin->set_result( $result );
if ( is_wp_error( $result ) ) {
$this->skin->error( $result );
//$this->skin->feedback( 'process_failed' );
} else {
// Installation succeeded.
//$this->skin->feedback( 'process_success' );
}
$this->skin->after();
if ( ! $options['is_multi'] ) {
/**
* Fires when the upgrader process is complete.
*
* See also {@see 'upgrader_package_options'}.
*
* @since 3.6.0
* @since 3.7.0 Added to WP_Upgrader::run().
* @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
*
* @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a
* Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
* @param array $hook_extra {
* Array of bulk item update data.
*
* @type string $action Type of action. Default 'update'.
* @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
* @type bool $bulk Whether the update process is a bulk update. Default true.
* @type array $plugins Array of the basename paths of the plugins' main files.
* @type array $themes The theme slugs.
* @type array $translations {
* Array of translations update data.
*
* @type string $language The locale the translation is for.
* @type string $type Type of translation. Accepts 'plugin', 'theme', or 'core'.
* @type string $slug Text domain the translation is for. The slug of a theme/plugin or
* 'default' for core translations.
* @type string $version The version of a theme, plugin, or core.
* }
* }
*/
do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
$this->skin->footer();
}
return $result;
}
/**
* Toggle maintenance mode for the site.
*
* Creates/deletes the maintenance file to enable/disable maintenance mode.
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
*
* @param bool $enable True to enable maintenance mode, false to disable.
*/
public function maintenance_mode( $enable = false ) {
global $wp_filesystem;
$file = $wp_filesystem->abspath() . '.maintenance';
if ( $enable ) {
//$this->skin->feedback( 'maintenance_start' );
// Create maintenance file to signal that we are upgrading
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
$wp_filesystem->delete( $file );
$wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE );
} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
//$this->skin->feedback( 'maintenance_end' );
$wp_filesystem->delete( $file );
}
}
/**
* Download a package.
*
* @since 2.8.0
*
* @param string $package The URI of the package. If this is the full path to an
* existing local file, it will be returned untouched.
* @param bool $check_signatures Whether to validate file signatures. Default false.
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
*/
public function download_package( $package, $check_signatures = false ) {
/**
* Filters whether to return the package.
*
* @since 3.7.0
*
* @param bool $reply Whether to bail without returning the package.
* Default false.
* @param string $package The package file name.
* @param WP_Upgrader $this The WP_Upgrader instance.
*/
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this );
if ( false !== $reply ) {
return $reply;
}
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { //Local file or remote?
return $package; //must be a local file..
}
if ( empty( $package ) ) {
return new WP_Error( 'no_package', $this->strings['no_package'] );
}
//$this->skin->feedback( 'downloading_package', $package );
$download_file = download_url( $package, 300, $check_signatures );
if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) {
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() );
}
return $download_file;
}
/**
* Unpack a compressed package file.
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $package Full path to the package file.
* @param bool $delete_package Optional. Whether to delete the package file after attempting
* to unpack it. Default true.
* @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure.
*/
public function unpack_package( $package, $delete_package = true ) {
global $wp_filesystem;
//$this->skin->feedback( 'unpack_package' );
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
//Clean up contents of upgrade directory beforehand.
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
if ( ! empty( $upgrade_files ) ) {
foreach ( $upgrade_files as $file ) {
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
}
}
// We need a working directory - Strip off any .tmp or .zip suffixes
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
// Clean up working directory
if ( $wp_filesystem->is_dir( $working_dir ) ) {
$wp_filesystem->delete( $working_dir, true );
}
// Unzip package to working directory
$result = unzip_file( $package, $working_dir );
// Once extracted, delete the package if required.
if ( $delete_package ) {
unlink( $package );
}
if ( is_wp_error( $result ) ) {
$wp_filesystem->delete( $working_dir, true );
if ( 'incompatible_archive' == $result->get_error_code() ) {
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
}
return $result;
}
return $working_dir;
}
/**
* Install a package.
*
* Copies the contents of a package form a source directory, and installs them in
* a destination directory. Optionally removes the source. It can also optionally
* clear out the destination folder if it already exists.
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global array $wp_theme_directories
*
* @param array|string $args {
* Optional. Array or string of arguments for installing a package. Default empty array.
*
* @type string $source Required path to the package source. Default empty.
* @type string $destination Required path to a folder to install the package in.
* Default empty.
* @type bool $clear_destination Whether to delete any files already in the destination
* folder. Default false.
* @type bool $clear_working Whether to delete the files form the working directory
* after copying to the destination. Default false.
* @type bool $abort_if_destination_exists Whether to abort the installation if
* the destination folder already exists. Default true.
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
* WP_Upgrader::install_package(). Default empty array.
* }
*
* @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
*/
public function install_package( $args = array() ) {
global $wp_filesystem, $wp_theme_directories;
$defaults = array(
'source' => '', // Please always pass this
'destination' => '', // and this
'clear_destination' => false,
'clear_working' => false,
'abort_if_destination_exists' => true,
'hook_extra' => array(),
);
$args = wp_parse_args( $args, $defaults );
// These were previously extract()'d.
$source = $args['source'];
$destination = $args['destination'];
$clear_destination = $args['clear_destination'];
set_time_limit( 300 );
if ( empty( $source ) || empty( $destination ) ) {
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
}
//$this->skin->feedback( 'installing_package' );
/**
* Filters the install response before the installation has started.
*
* Returning a truthy value, or one that could be evaluated as a WP_Error
* will effectively short-circuit the installation, returning that value
* instead.
*
* @since 2.8.0
*
* @param bool|WP_Error $response Response.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
if ( is_wp_error( $res ) ) {
return $res;
}
//Retain the Original source and destinations
$remote_source = $args['source'];
$local_destination = $destination;
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
$remote_destination = $wp_filesystem->find_folder( $local_destination );
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents.
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
} elseif ( count( $source_files ) == 0 ) {
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
} else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
$source = trailingslashit( $args['source'] );
}
/**
* Filters the source file location for the upgrade package.
*
* @since 2.8.0
* @since 4.4.0 The $hook_extra parameter became available.
*
* @param string $source File source location.
* @param string $remote_source Remote file source location.
* @param WP_Upgrader $this WP_Upgrader instance.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
if ( is_wp_error( $source ) ) {
return $source;
}
// Has the source location changed? If so, we need a new source_files list.
if ( $source !== $remote_source ) {
$source_files = array_keys( $wp_filesystem->dirlist( $source ) );
}
/*
* Protection against deleting files in any important base directories.
* Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
* destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
* to copy the directory into the directory, whilst they pass the source
* as the actual files to copy.
*/
$protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
if ( is_array( $wp_theme_directories ) ) {
$protected_directories = array_merge( $protected_directories, $wp_theme_directories );
}
if ( in_array( $destination, $protected_directories ) ) {
$remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
$destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
}
if ( $clear_destination ) {
// We're going to clear the destination if there's something there.
//$this->skin->feedback( 'remove_old' );
$removed = $this->clear_destination( $remote_destination );
/**
* Filters whether the upgrader cleared the destination.
*
* @since 2.8.0
*
* @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure
* @param string $local_destination The local package destination.
* @param string $remote_destination The remote package destination.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
if ( is_wp_error( $removed ) ) {
return $removed;
}
} elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) {
//If we're not clearing the destination folder and something exists there already, Bail.
//But first check to see if there are actually any files in the folder.
$_files = $wp_filesystem->dirlist( $remote_destination );
if ( ! empty( $_files ) ) {
$wp_filesystem->delete( $remote_source, true ); //Clear out the source files.
return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination );
}
}
//Create destination if needed
if ( ! $wp_filesystem->exists( $remote_destination ) ) {
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
}
}
// Copy new version of item into place.
$result = copy_dir( $source, $remote_destination );
if ( is_wp_error( $result ) ) {
if ( $args['clear_working'] ) {
$wp_filesystem->delete( $remote_source, true );
}
return $result;
}
//Clear the Working folder?
if ( $args['clear_working'] ) {
$wp_filesystem->delete( $remote_source, true );
}
$destination_name = basename( str_replace( $local_destination, '', $destination ) );
if ( '.' == $destination_name ) {
$destination_name = '';
}
$this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' );
/**
* Filters the installation response after the installation has finished.
*
* @since 2.8.0
*
* @param bool $response Installation response.
* @param array $hook_extra Extra arguments passed to hooked filters.
* @param array $result Installation result data.
*/
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
if ( is_wp_error( $res ) ) {
$this->result = $res;
return $res;
}
//Bombard the calling function will all the info which we've just used.
return $this->result;
}
}