Add gravity flow demo
This commit is contained in:
452
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/AM_Notification.php
Executable file
452
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/AM_Notification.php
Executable file
@@ -0,0 +1,452 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Awesome Motive Notifications
|
||||
*
|
||||
* This creates a custom post type (if it doesn't exist) and calls the API to
|
||||
* retrieve notifications for this product.
|
||||
*
|
||||
* @package AwesomeMotive
|
||||
* @author Benjamin Rojas
|
||||
* @license GPL-2.0+
|
||||
* @copyright Copyright (c) 2017, Retyp LLC
|
||||
* @version 1.0.2
|
||||
*/
|
||||
class AM_Notification {
|
||||
/**
|
||||
* The api url we are calling.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $api_url = 'https://api.awesomemotive.com/v1/notification/';
|
||||
|
||||
/**
|
||||
* A unique slug for this plugin.
|
||||
* (Not the WordPress plugin slug)
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* The current plugin version.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin_version;
|
||||
|
||||
/**
|
||||
* Flag if a notice has been registered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $registered = false;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $plugin The plugin slug.
|
||||
* @param mixed $version The version of the plugin.
|
||||
*/
|
||||
public function __construct( $plugin = '', $version = 0 ) {
|
||||
$this->plugin = $plugin;
|
||||
$this->plugin_version = $version;
|
||||
|
||||
add_action( 'init', array( $this, 'custom_post_type' ) );
|
||||
add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
|
||||
add_action( 'admin_notices', array( $this, 'display_notifications' ) );
|
||||
add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom post type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function custom_post_type() {
|
||||
register_post_type( 'amn_' . $this->plugin, array(
|
||||
'label' => $this->plugin . ' Announcements',
|
||||
'can_export' => false,
|
||||
'supports' => false,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the remote notifications if the time has expired.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_remote_notifications() {
|
||||
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
|
||||
|
||||
if ( $last_checked < strtotime( 'today midnight' ) ) {
|
||||
$plugin_notifications = $this->get_plugin_notifications( 1 );
|
||||
$notification_id = null;
|
||||
|
||||
if ( ! empty( $plugin_notifications ) ) {
|
||||
// Unset it from the array.
|
||||
$notification = $plugin_notifications[0];
|
||||
$notification_id = get_post_meta( $notification->ID, 'notification_id', true );
|
||||
}
|
||||
|
||||
$response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
|
||||
'body' => array(
|
||||
'slug' => $this->plugin,
|
||||
'version' => $this->plugin_version,
|
||||
'last_notification' => $notification_id,
|
||||
),
|
||||
) ) );
|
||||
|
||||
$data = json_decode( $response );
|
||||
|
||||
if ( ! empty( $data->id ) ) {
|
||||
$notifications = array();
|
||||
|
||||
foreach ( (array) $data->slugs as $slug ) {
|
||||
$notifications = array_merge(
|
||||
$notifications,
|
||||
(array) get_posts(
|
||||
array(
|
||||
'post_type' => 'amn_' . $slug,
|
||||
'post_status' => 'all',
|
||||
'meta_key' => 'notification_id',
|
||||
'meta_value' => $data->id,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( $notifications ) ) {
|
||||
$new_notification_id = wp_insert_post( array(
|
||||
'post_content' => wp_kses_post( $data->content ),
|
||||
'post_type' => 'amn_' . $this->plugin,
|
||||
) );
|
||||
|
||||
update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
|
||||
update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
|
||||
update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
|
||||
update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
|
||||
update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
|
||||
update_post_meta( $new_notification_id, 'viewed', 0 );
|
||||
update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
|
||||
update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Possibly revoke notifications.
|
||||
if ( ! empty( $data->revoked ) ) {
|
||||
$this->revoke_notifications( $data->revoked );
|
||||
}
|
||||
|
||||
// Set the option now so we can't run this again until after 24 hours.
|
||||
update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local plugin notifications that have already been set.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param integer $limit Set the limit for how many posts to retrieve.
|
||||
* @param array $args Any top-level arguments to add to the array.
|
||||
*
|
||||
* @return WP_Post[] WP_Post that match the query.
|
||||
*/
|
||||
public function get_plugin_notifications( $limit = -1, $args = array() ) {
|
||||
return get_posts(
|
||||
array(
|
||||
'posts_per_page' => $limit,
|
||||
'post_type' => 'amn_' . $this->plugin,
|
||||
) + $args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display any notifications that should be displayed.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display_notifications() {
|
||||
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin_notifications = $this->get_plugin_notifications( -1, array(
|
||||
'post_status' => 'all',
|
||||
'meta_key' => 'viewed',
|
||||
'meta_value' => '0',
|
||||
) );
|
||||
|
||||
$plugin_notifications = $this->validate_notifications( $plugin_notifications );
|
||||
|
||||
if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
|
||||
foreach ( $plugin_notifications as $notification ) {
|
||||
$dismissable = get_post_meta( $notification->ID, 'dismissable', true );
|
||||
$type = get_post_meta( $notification->ID, 'type', true );
|
||||
?>
|
||||
<div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
|
||||
<?php echo $notification->post_content; ?>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
|
||||
$.post(ajaxurl, {
|
||||
action: 'am_notification_dismiss',
|
||||
notification_id: '<?php echo $notification->ID; ?>'
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
self::$registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the notifications before displaying them.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $plugin_notifications An array of plugin notifications.
|
||||
*
|
||||
* @return array A filtered array of plugin notifications.
|
||||
*/
|
||||
public function validate_notifications( $plugin_notifications ) {
|
||||
global $pagenow;
|
||||
|
||||
foreach ( $plugin_notifications as $key => $notification ) {
|
||||
// Location validation.
|
||||
$location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
|
||||
$continue = false;
|
||||
if ( ! in_array( 'everywhere', $location, true ) ) {
|
||||
if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
|
||||
$continue = true;
|
||||
}
|
||||
|
||||
if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
|
||||
$continue = true;
|
||||
}
|
||||
|
||||
if ( ! $continue ) {
|
||||
unset( $plugin_notifications[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin validation (OR conditional).
|
||||
$plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
|
||||
$continue = false;
|
||||
if ( ! empty( $plugins ) ) {
|
||||
foreach ( $plugins as $plugin ) {
|
||||
if ( is_plugin_active( $plugin ) ) {
|
||||
$continue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $continue ) {
|
||||
unset( $plugin_notifications[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Theme validation.
|
||||
$theme = get_post_meta( $notification->ID, 'theme', true );
|
||||
$continue = (string) wp_get_theme() === $theme;
|
||||
|
||||
if ( ! empty( $theme ) && ! $continue ) {
|
||||
unset( $plugin_notifications[ $key ] );
|
||||
}
|
||||
|
||||
// Version validation.
|
||||
$version = get_post_meta( $notification->ID, 'version', true );
|
||||
$continue = false;
|
||||
if ( ! empty( $version ) ) {
|
||||
if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
|
||||
$continue = true;
|
||||
}
|
||||
|
||||
if ( ! $continue ) {
|
||||
unset( $plugin_notifications[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Expiration validation.
|
||||
$expiration = get_post_meta( $notification->ID, 'expiration', true );
|
||||
$continue = false;
|
||||
if ( ! empty( $expiration ) ) {
|
||||
if ( $expiration > time() ) {
|
||||
$continue = true;
|
||||
}
|
||||
|
||||
if ( ! $continue ) {
|
||||
unset( $plugin_notifications[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Plan validation.
|
||||
$plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
|
||||
$continue = false;
|
||||
if ( ! empty( $plans ) ) {
|
||||
$level = $this->get_plan_level();
|
||||
if ( in_array( $level, $plans, true ) ) {
|
||||
$continue = true;
|
||||
}
|
||||
|
||||
if ( ! $continue ) {
|
||||
unset( $plugin_notifications[ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $plugin_notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the current plan level.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string The current plan level.
|
||||
*/
|
||||
public function get_plan_level() {
|
||||
// Prepare variables.
|
||||
$key = '';
|
||||
$level = '';
|
||||
$option = false;
|
||||
switch ( $this->plugin ) {
|
||||
case 'wpforms' :
|
||||
$option = get_option( 'wpforms_license' );
|
||||
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
||||
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
||||
|
||||
// Possibly check for a constant.
|
||||
if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
|
||||
$key = WPFORMS_LICENSE_KEY;
|
||||
}
|
||||
break;
|
||||
case 'mi' :
|
||||
$option = get_option( 'monsterinsights_license' );
|
||||
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
||||
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
||||
|
||||
// Possibly check for a constant.
|
||||
if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
|
||||
$key = MONSTERINSIGHTS_LICENSE_KEY;
|
||||
}
|
||||
break;
|
||||
case 'sol' :
|
||||
$option = get_option( 'soliloquy' );
|
||||
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
||||
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
||||
|
||||
// Possibly check for a constant.
|
||||
if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
|
||||
$key = SOLILOQUY_LICENSE_KEY;
|
||||
}
|
||||
break;
|
||||
case 'envira' :
|
||||
$option = get_option( 'envira_gallery' );
|
||||
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
||||
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
||||
|
||||
// Possibly check for a constant.
|
||||
if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
|
||||
$key = ENVIRA_LICENSE_KEY;
|
||||
}
|
||||
break;
|
||||
case 'om' :
|
||||
$option = get_option( 'optin_monster_api' );
|
||||
$key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
|
||||
|
||||
// Possibly check for a constant.
|
||||
if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
|
||||
$key = OPTINMONSTER_REST_API_LICENSE_KEY;
|
||||
}
|
||||
|
||||
// If the key is still empty, check for the old legacy key.
|
||||
if ( empty( $key ) ) {
|
||||
$key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Possibly set the level to 'none' if the key is empty and no level has been set.
|
||||
if ( empty( $key ) && empty( $level ) ) {
|
||||
$level = 'none';
|
||||
}
|
||||
|
||||
// Normalize the level.
|
||||
switch ( $level ) {
|
||||
case 'bronze' :
|
||||
case 'personal' :
|
||||
$level = 'basic';
|
||||
break;
|
||||
case 'silver' :
|
||||
case 'multi' :
|
||||
$level = 'plus';
|
||||
break;
|
||||
case 'gold' :
|
||||
case 'developer' :
|
||||
$level = 'pro';
|
||||
break;
|
||||
case 'platinum' :
|
||||
case 'master' :
|
||||
$level = 'ultimate';
|
||||
break;
|
||||
}
|
||||
|
||||
// Return the plan level.
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss the notification via AJAX.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function dismiss_notification() {
|
||||
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
$notification_id = intval( $_POST['notification_id'] );
|
||||
update_post_meta( $notification_id, 'viewed', 1 );
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes notifications.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $ids An array of notification IDs to revoke.
|
||||
*/
|
||||
public function revoke_notifications( $ids ) {
|
||||
// Loop through each of the IDs and find the post that has it as meta.
|
||||
foreach ( (array) $ids as $id ) {
|
||||
$notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
|
||||
if ( $notifications ) {
|
||||
foreach ( $notifications as $notification ) {
|
||||
update_post_meta( $notification->ID, 'viewed', 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
457
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Area.php
Executable file
457
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Area.php
Executable file
@@ -0,0 +1,457 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Admin;
|
||||
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Area registers and process all wp-admin display functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Area {
|
||||
|
||||
/**
|
||||
* @var string Slug of the admin area page.
|
||||
*/
|
||||
const SLUG = 'wp-mail-smtp';
|
||||
|
||||
/**
|
||||
* @var string Admin page unique hook.
|
||||
*/
|
||||
public $hook;
|
||||
|
||||
/**
|
||||
* @var PageAbstract[]
|
||||
*/
|
||||
private $pages;
|
||||
|
||||
/**
|
||||
* 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' ) );
|
||||
|
||||
// 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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display custom notices based on the error/success codes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display_custom_auth_notices() {
|
||||
|
||||
$error = isset( $_GET['error'] ) ? $_GET['error'] : '';
|
||||
$success = isset( $_GET['success'] ) ? $_GET['success'] : '';
|
||||
|
||||
if ( empty( $error ) && empty( $success ) ) {
|
||||
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':
|
||||
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 Google.', 'wp-mail-smtp' ),
|
||||
WP::ADMIN_NOTICE_SUCCESS
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin area menu item.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function add_admin_options_page() {
|
||||
|
||||
$this->hook = add_options_page(
|
||||
esc_html__( 'WP Mail SMTP Options', 'wp-mail-smtp' ),
|
||||
esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
|
||||
'manage_options',
|
||||
self::SLUG,
|
||||
array( $this, 'display' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue admin area scripts and styles.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $hook
|
||||
*/
|
||||
public function enqueue_assets( $hook ) {
|
||||
|
||||
if ( $hook !== $this->hook ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style(
|
||||
'wp-mail-smtp-admin',
|
||||
wp_mail_smtp()->plugin_url . '/assets/css/smtp-admin.min.css',
|
||||
false,
|
||||
WPMS_PLUGIN_VER
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'wp-mail-smtp-admin',
|
||||
wp_mail_smtp()->plugin_url . '/assets/js/smtp-admin' . WP::asset_min() . '.js',
|
||||
array( 'jquery' ),
|
||||
WPMS_PLUGIN_VER
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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">
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<img class="wp-mail-smtp-header-logo" src="<?php echo wp_mail_smtp()->plugin_url; ?>/assets/images/logo.png" 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(
|
||||
/* 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">★★★★★</a> on <a href="%2$s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the WP Mail SMTP team!', 'wp-mail-smtp' ),
|
||||
$url,
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display content of the admin area page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display() {
|
||||
?>
|
||||
|
||||
<div class="wrap" id="wp-mail-smtp">
|
||||
|
||||
<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() ? 'class="active"' : '';
|
||||
?>
|
||||
|
||||
<a href="<?php echo $page->get_link(); ?>" <?php echo $class; ?>><?php echo $label; ?></a>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div class="wp-mail-smtp-page wp-mail-smtp-tab-<?php echo $this->get_current_tab(); ?>">
|
||||
<h1 class="screen-reader-text"><?php echo $this->get_current_tab_title(); ?></h1>
|
||||
|
||||
<?php $this->display_current_tab_content(); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current tab title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display_current_tab_content() {
|
||||
|
||||
if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->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() ) {
|
||||
$current = ! empty( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings';
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of default registered tabs for plugin admin area.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \WPMailSMTP\Admin\PageAbstract[]
|
||||
*/
|
||||
public function get_pages() {
|
||||
|
||||
if ( empty( $this->pages ) ) {
|
||||
$this->pages = array(
|
||||
'settings' => new Pages\Settings(),
|
||||
'test' => new Pages\Test(),
|
||||
'misc' => new Pages\Misc(),
|
||||
'auth' => new Pages\Auth(),
|
||||
);
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->pages[ $this->get_current_tab() ]->get_title();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we are on an admin page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_admin_page() {
|
||||
|
||||
$page = isset( $_GET['page'] ) ? $_GET['page'] : '';
|
||||
|
||||
return self::SLUG === $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* All possible plugin forms manipulation will be done here.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function process_actions() {
|
||||
|
||||
// Allow to process only own tabs.
|
||||
if ( ! array_key_exists( $this->get_current_tab(), $this->get_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();
|
||||
}
|
||||
|
||||
$this->pages[ $this->get_current_tab() ]->process_post( $post );
|
||||
}
|
||||
|
||||
// This won't do anything for most pages.
|
||||
$this->pages[ $this->get_current_tab() ]->process_auth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link to Settings page of a plugin on Plugins page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $links
|
||||
* @param string $file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function add_plugin_action_link( $links, $file ) {
|
||||
|
||||
if ( strpos( $file, 'wp-mail-smtp' ) === false ) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
$settings_link = '<a href="' . $this->get_admin_page_url() . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
|
||||
|
||||
array_unshift( $links, $settings_link );
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin admin area page URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_admin_page_url() {
|
||||
return add_query_arg(
|
||||
'page',
|
||||
self::SLUG,
|
||||
admin_url( 'options-general.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 a 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 ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
66
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/PageAbstract.php
Executable file
66
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/PageAbstract.php
Executable file
@@ -0,0 +1,66 @@
|
||||
<?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( 'options-general.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 );
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
59
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Auth.php
Executable file
59
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Auth.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Admin\Pages;
|
||||
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\Providers\AuthAbstract;
|
||||
|
||||
/**
|
||||
* Class Auth.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Auth {
|
||||
|
||||
/**
|
||||
* @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 ) {
|
||||
$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() {
|
||||
}
|
||||
}
|
||||
99
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Misc.php
Executable file
99
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Misc.php
Executable file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Admin\Pages;
|
||||
|
||||
use WPMailSMTP\Admin\PageAbstract;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Misc is part of Area, displays different plugin-related settings of the plugin (not related to emails).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Misc 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(); ?>
|
||||
|
||||
<!-- General 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( 'General', 'wp-mail-smtp' ); ?></h2>
|
||||
</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>
|
||||
|
||||
<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>
|
||||
|
||||
</form>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function process_post( $data ) {
|
||||
|
||||
$this->check_admin_referer();
|
||||
|
||||
$options = new Options();
|
||||
|
||||
// Unchecked checkbox doesn't exist in $_POST, so we need to ensure we actually have it.
|
||||
if ( empty( $data['general']['am_notifications_hidden'] ) ) {
|
||||
$data['general']['am_notifications_hidden'] = 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
|
||||
);
|
||||
}
|
||||
}
|
||||
255
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Settings.php
Executable file
255
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Settings.php
Executable file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Admin\Pages;
|
||||
|
||||
use WPMailSMTP\Admin\PageAbstract;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Settings is part of Area, displays general settings of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Settings extends PageAbstract {
|
||||
|
||||
/**
|
||||
* @var string Slug of a tab.
|
||||
*/
|
||||
protected $slug = 'settings';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_label() {
|
||||
return esc_html__( 'Settings', 'wp-mail-smtp' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return $this->get_label();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display() {
|
||||
|
||||
$options = new Options();
|
||||
$mailer = $options->get( 'mail', 'mailer' );
|
||||
?>
|
||||
|
||||
<form method="POST" action="">
|
||||
<?php $this->wp_nonce_field(); ?>
|
||||
|
||||
<!-- 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' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-from_email" spellcheck="false"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'You can specify the email address that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - default email address. */
|
||||
esc_html__( 'If you leave this blank, the default one will be used: %s.', 'wp-mail-smtp' ),
|
||||
'<code>' . wp_mail_smtp()->get_processor()->get_default_email() . '</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Please note if you are sending using an email provider (Gmail, Yahoo, Hotmail, Outlook.com, etc) this setting should be your email address for that account.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</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' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-from_name" spellcheck="false"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'You can specify the name that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - WordPress. */
|
||||
esc_html__( 'If you leave this blank, the emails will be sent from %s.', 'wp-mail-smtp' ),
|
||||
'<code>WordPress</code>'
|
||||
);
|
||||
?>
|
||||
</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 <?php echo $mailer === $provider->get_slug() ? 'active' : ''; ?>">
|
||||
<div class="wp-mail-smtp-mailer-image">
|
||||
<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">
|
||||
<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' ) ? 'disabled' : ''; ?>
|
||||
/>
|
||||
<label for="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"><?php echo $provider->get_title(); ?></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</div>
|
||||
</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.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mailer Options -->
|
||||
<div class="wp-mail-smtp-mailer-options">
|
||||
<?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
|
||||
|
||||
<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 Option Title -->
|
||||
<?php $provider_desc = $provider->get_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">
|
||||
<h2><?php echo $provider->get_title(); ?></h2>
|
||||
<?php if ( ! empty( $provider_desc ) ) : ?>
|
||||
<p class="desc"><?php echo $provider_desc; ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $provider->display_options(); ?>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
||||
</form>
|
||||
|
||||
<?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']['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 ( $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' &&
|
||||
(
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
||||
216
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Test.php
Executable file
216
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Admin/Pages/Test.php
Executable file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Admin\Pages;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
use WPMailSMTP\Admin\PageAbstract;
|
||||
|
||||
/**
|
||||
* Class Test is part of Area, displays email testing page of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Test extends PageAbstract {
|
||||
|
||||
/**
|
||||
* @var string Slug of a tab.
|
||||
*/
|
||||
protected $slug = 'test';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_label() {
|
||||
return esc_html__( 'Email Test', 'wp-mail-smtp' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return $this->get_label();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display() {
|
||||
?>
|
||||
|
||||
<form method="POST" action="">
|
||||
<?php $this->wp_nonce_field(); ?>
|
||||
|
||||
<!-- Test Email 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( 'Send a Test Email', 'wp-mail-smtp' ); ?></h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Test Email -->
|
||||
<div id="wp-mail-smtp-setting-row-test_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-test_email"><?php esc_html_e( 'Send To', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[test_email]" type="email" id="wp-mail-smtp-setting-test_email" spellcheck="false" required />
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Type an email address here and then click a button below to generate a test email.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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( 'Send Email', 'wp-mail-smtp' ); ?></button>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function process_post( $data ) {
|
||||
|
||||
$this->check_admin_referer();
|
||||
|
||||
if ( isset( $data['test_email'] ) ) {
|
||||
$data['test_email'] = filter_var( $data['test_email'], FILTER_VALIDATE_EMAIL );
|
||||
}
|
||||
|
||||
if ( empty( $data['test_email'] ) ) {
|
||||
WP::add_admin_notice(
|
||||
esc_html__( 'Test failed. Please use a valid email address and try to resend the test email.', 'wp-mail-smtp' ),
|
||||
WP::ADMIN_NOTICE_WARNING
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
global $phpmailer;
|
||||
|
||||
// Make sure the PHPMailer class has been instantiated.
|
||||
if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
|
||||
require_once ABSPATH . WPINC . '/class-phpmailer.php';
|
||||
$phpmailer = new MailCatcher( true );
|
||||
}
|
||||
|
||||
// Set SMTPDebug level, default is 3 (commands + data + connection status).
|
||||
$phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 3 );
|
||||
|
||||
// Start output buffering to grab smtp debugging output.
|
||||
ob_start();
|
||||
|
||||
// Send the test mail.
|
||||
$result = wp_mail(
|
||||
$data['test_email'],
|
||||
/* translators: %s - email address a test email will be sent to. */
|
||||
'WP Mail SMTP: ' . sprintf( esc_html__( 'Test email to %s', 'wp-mail-smtp' ), $data['test_email'] ),
|
||||
sprintf(
|
||||
/* translators: %s - mailer name. */
|
||||
esc_html__( 'This email was sent by %s mailer, and generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' ),
|
||||
wp_mail_smtp()->get_providers()->get_options( Options::init()->get( 'mail', 'mailer' ) )->get_title()
|
||||
)
|
||||
);
|
||||
|
||||
// Grab the smtp debugging output.
|
||||
$smtp_debug = ob_get_clean();
|
||||
|
||||
/*
|
||||
* Notify a user about the results.
|
||||
*/
|
||||
if ( $result ) {
|
||||
WP::add_admin_notice(
|
||||
esc_html__( 'Your email was sent successfully!', 'wp-mail-smtp' ),
|
||||
WP::ADMIN_NOTICE_SUCCESS
|
||||
);
|
||||
} else {
|
||||
$error = $this->get_debug_messages( $phpmailer, $smtp_debug );
|
||||
|
||||
WP::add_admin_notice(
|
||||
'<p><strong>' . esc_html__( 'There was a problem while sending a test email. Related debugging output is shown below:', 'wp-mail-smtp' ) . '</strong></p>' .
|
||||
'<blockquote style="border-left:1px solid orange;padding-left:10px">' . $error . '</blockquote>' .
|
||||
'<p class="description">' . esc_html__( 'Please copy only the content of the error debug message above, identified with an orange left border, into the support forum topic if you experience any issues.', 'wp-mail-smtp' ) . '</p>',
|
||||
WP::ADMIN_NOTICE_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare debug information, that will help users to identify the error.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcher $phpmailer
|
||||
* @param string $smtp_debug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_debug_messages( $phpmailer, $smtp_debug ) {
|
||||
|
||||
$options = new Options();
|
||||
|
||||
/*
|
||||
* Versions Debug.
|
||||
*/
|
||||
|
||||
$versions_text = '<strong>Versions:</strong><br>';
|
||||
|
||||
$versions_text .= '<strong>WordPress:</strong> ' . get_bloginfo( 'version' ) . '<br>';
|
||||
$versions_text .= '<strong>WordPress MS:</strong> ' . ( is_multisite() ? 'Yes' : 'No' ) . '<br>';
|
||||
$versions_text .= '<strong>PHP:</strong> ' . PHP_VERSION . '<br>';
|
||||
$versions_text .= '<strong>WP Mail SMTP:</strong> ' . WPMS_PLUGIN_VER . '<br>';
|
||||
|
||||
/*
|
||||
* Mailer Debug.
|
||||
*/
|
||||
|
||||
$mailer_text = '<strong>Params:</strong><br>';
|
||||
|
||||
$mailer_text .= '<strong>Mailer:</strong> ' . $options->get( 'mail', 'mailer' ) . '<br>';
|
||||
$mailer_text .= '<strong>Constants:</strong> ' . ( $options->is_const_enabled() ? 'Yes' : 'No' ) . '<br>';
|
||||
|
||||
// Display different debug info based on the mailer.
|
||||
$mailer = wp_mail_smtp()->get_providers()->get_mailer( $options->get( 'mail', 'mailer' ), $phpmailer );
|
||||
|
||||
if ( $mailer ) {
|
||||
$mailer_text .= $mailer->get_debug_info();
|
||||
}
|
||||
|
||||
/*
|
||||
* General Debug.
|
||||
*/
|
||||
|
||||
$debug_text = implode( '<br>', Debug::get() );
|
||||
Debug::clear();
|
||||
if ( ! empty( $debug_text ) ) {
|
||||
$debug_text = '<br><strong>Debug:</strong><br>' . $debug_text . '<br>';
|
||||
}
|
||||
|
||||
/*
|
||||
* SMTP Debug.
|
||||
*/
|
||||
|
||||
$smtp_text = '';
|
||||
if ( $options->is_mailer_smtp() ) {
|
||||
$smtp_text = '<strong>SMTP Debug:</strong><br>';
|
||||
if ( ! empty( $smtp_debug ) ) {
|
||||
$smtp_text .= esc_textarea( $smtp_debug );
|
||||
} else {
|
||||
$smtp_text .= '[empty]';
|
||||
}
|
||||
}
|
||||
|
||||
$errors = apply_filters( 'wp_mail_smtp_admin_test_get_debug_messages', array(
|
||||
$versions_text,
|
||||
$mailer_text,
|
||||
$debug_text,
|
||||
$smtp_text,
|
||||
) );
|
||||
|
||||
return '<pre>' . implode( '<br>', array_filter( $errors ) ) . '</pre>';
|
||||
}
|
||||
}
|
||||
241
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Core.php
Executable file
241
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Core.php
Executable file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Core to handle all plugin initialization.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Core {
|
||||
|
||||
/**
|
||||
* Without trailing slash.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin_url;
|
||||
/**
|
||||
* Without trailing slash.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin_path;
|
||||
|
||||
/**
|
||||
* Core constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->plugin_url = rtrim( plugin_dir_url( __DIR__ ), '/\\' );
|
||||
$this->plugin_path = rtrim( plugin_dir_path( __DIR__ ), '/\\' );
|
||||
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign all hooks to proper places.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function hooks() {
|
||||
|
||||
// Activation hook.
|
||||
add_action( 'activate_wp-mail-smtp/wp_mail_smtp.php', array( $this, 'activate' ) );
|
||||
|
||||
add_action( 'plugins_loaded', array( $this, 'get_processor' ) );
|
||||
add_action( 'plugins_loaded', array( $this, 'replace_phpmailer' ) );
|
||||
add_action( 'plugins_loaded', array( $this, 'init_notifications' ) );
|
||||
|
||||
add_action( 'admin_notices', array( '\WPMailSMTP\WP', 'display_admin_notices' ) );
|
||||
|
||||
add_action( 'init', array( $this, 'init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial plugin actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
// Load translations just in case.
|
||||
load_plugin_textdomain( 'wp-mail-smtp', false, plugin_basename( wp_mail_smtp()->plugin_path ) . '/languages' );
|
||||
|
||||
/*
|
||||
* Constantly check in admin area, that we don't need to upgrade DB.
|
||||
* Do not wait for the `admin_init` hook, because some actions are already done
|
||||
* on `plugins_loaded`, so migration has to be done before.
|
||||
*/
|
||||
if ( WP::in_wp_admin() ) {
|
||||
$this->get_migration();
|
||||
$this->get_upgrade();
|
||||
$this->get_admin();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin core processor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Processor
|
||||
*/
|
||||
public function get_processor() {
|
||||
|
||||
static $processor;
|
||||
|
||||
if ( ! isset( $processor ) ) {
|
||||
$processor = apply_filters( 'wp_mail_smtp_core_get_processor', new Processor() );
|
||||
}
|
||||
|
||||
return $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin admin area.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Admin\Area
|
||||
*/
|
||||
public function get_admin() {
|
||||
|
||||
static $admin;
|
||||
|
||||
if ( ! isset( $admin ) ) {
|
||||
$admin = apply_filters( 'wp_mail_smtp_core_get_admin', new Admin\Area() );
|
||||
}
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin providers loader.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Providers\Loader
|
||||
*/
|
||||
public function get_providers() {
|
||||
|
||||
static $providers;
|
||||
|
||||
if ( ! isset( $providers ) ) {
|
||||
$providers = apply_filters( 'wp_mail_smtp_core_get_providers', new Providers\Loader() );
|
||||
}
|
||||
|
||||
return $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin option migrator.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Migration
|
||||
*/
|
||||
public function get_migration() {
|
||||
|
||||
static $migration;
|
||||
|
||||
if ( ! isset( $migration ) ) {
|
||||
$migration = apply_filters( 'wp_mail_smtp_core_get_migration', new Migration() );
|
||||
}
|
||||
|
||||
return $migration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin upgrader.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*
|
||||
* @return Upgrade
|
||||
*/
|
||||
public function get_upgrade() {
|
||||
|
||||
static $upgrade;
|
||||
|
||||
if ( ! isset( $upgrade ) ) {
|
||||
$upgrade = apply_filters( 'wp_mail_smtp_core_get_upgrade', new Upgrade() );
|
||||
}
|
||||
|
||||
return $upgrade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Awesome Motive Notifications.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function init_notifications() {
|
||||
|
||||
if ( Options::init()->get( 'general', 'am_notifications_hidden' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
static $notification;
|
||||
|
||||
if ( ! isset( $notification ) ) {
|
||||
$notification = new AM_Notification( 'smtp', WPMS_PLUGIN_VER );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the \PHPMailer replacement.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \WPMailSMTP\MailCatcher
|
||||
*/
|
||||
public function replace_phpmailer() {
|
||||
global $phpmailer;
|
||||
|
||||
return $this->replace_w_fake_phpmailer( $phpmailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite default PhpMailer with out MailCatcher.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param null $obj
|
||||
*
|
||||
* @return \WPMailSMTP\MailCatcher
|
||||
*/
|
||||
protected function replace_w_fake_phpmailer( &$obj = null ) {
|
||||
|
||||
$obj = new MailCatcher();
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to do on plugin activation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function activate() {
|
||||
|
||||
// Store the plugin version activated to reference with upgrades.
|
||||
update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
|
||||
|
||||
// Create and store initial plugin settings.
|
||||
$options = array(
|
||||
'mail' => array(
|
||||
'from_email' => get_option( 'admin_email' ),
|
||||
'from_name' => get_bloginfo( 'name' ),
|
||||
'mailer' => 'mail',
|
||||
'return_path' => false,
|
||||
),
|
||||
'smtp' => array(
|
||||
'autotls' => true,
|
||||
),
|
||||
);
|
||||
|
||||
Options::init()->set( $options, true );
|
||||
}
|
||||
}
|
||||
118
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Debug.php
Executable file
118
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Debug.php
Executable file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Debug that will save all errors or warnings generated by APIs or SMTP
|
||||
* and display in area for administrators.
|
||||
*
|
||||
* Usage example:
|
||||
* Debug::set( 'Some warning: %s', array( '%s' => $e->getMessage() );
|
||||
* $debug = Debug::get(); // array
|
||||
* $debug = Debug::get_last(); // string
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class Debug {
|
||||
|
||||
/**
|
||||
* Key for options table where all messages will be saved to.
|
||||
*/
|
||||
const OPTION_KEY = 'wp_mail_smtp_debug';
|
||||
|
||||
/**
|
||||
* Save the debug message to a debug log.
|
||||
* Adds one more to a list, at the end.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public static function set( $message ) {
|
||||
|
||||
if ( ! is_string( $message ) ) {
|
||||
$message = \json_encode( $message );
|
||||
}
|
||||
|
||||
$message = wp_strip_all_tags( $message, false );
|
||||
|
||||
$all = self::get();
|
||||
|
||||
array_push( $all, $message );
|
||||
|
||||
update_option( self::OPTION_KEY, $all, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all messages for a debug log.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public static function clear() {
|
||||
update_option( self::OPTION_KEY, array(), false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all messages from a debug log.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get() {
|
||||
|
||||
$all = get_option( self::OPTION_KEY, array() );
|
||||
|
||||
if ( ! is_array( $all ) ) {
|
||||
$all = (array) $all;
|
||||
}
|
||||
|
||||
return $all;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last message that was saved to a debug log.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_last() {
|
||||
|
||||
$all = self::get();
|
||||
|
||||
if ( ! empty( $all ) && is_array( $all ) ) {
|
||||
return (string) $all[ count( $all ) - 1 ];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the proper variable content output to debug.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pvar( $var = '' ) {
|
||||
|
||||
ob_start();
|
||||
|
||||
echo '<code>';
|
||||
|
||||
if ( is_bool( $var ) || empty( $var ) ) {
|
||||
var_dump( $var );
|
||||
} else {
|
||||
print_r( $var );
|
||||
}
|
||||
|
||||
echo '</code>';
|
||||
|
||||
$output = ob_get_clean();
|
||||
|
||||
return str_replace( array( "\r\n", "\r", "\n" ), '', $output );
|
||||
}
|
||||
}
|
||||
72
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/MailCatcher.php
Executable file
72
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/MailCatcher.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
// Load PHPMailer class, so we can subclass it.
|
||||
if ( ! class_exists( 'PHPMailer', false ) ) {
|
||||
require_once ABSPATH . WPINC . '/class-phpmailer.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class MailCatcher replaces the \PHPMailer and modifies the email sending logic.
|
||||
* Thus, we can use other mailers API to do what we need, or stop emails completely.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MailCatcher extends \PHPMailer {
|
||||
|
||||
/**
|
||||
* Modify the default send() behaviour.
|
||||
* For those mailers, that relies on PHPMailer class - call it directly.
|
||||
* For others - init the correct provider and process it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws \phpmailerException Throws when sending via PhpMailer fails for some reason.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
$options = new Options();
|
||||
$mail_mailer = $options->get( 'mail', 'mailer' );
|
||||
|
||||
// Define a custom header, that will be used in Gmail/SMTP mailers.
|
||||
$this->XMailer = 'WPMailSMTP/Mailer/' . $mail_mailer . ' ' . WPMS_PLUGIN_VER;
|
||||
|
||||
// Use the default PHPMailer, as we inject our settings there for certain providers.
|
||||
if (
|
||||
$mail_mailer === 'mail' ||
|
||||
$mail_mailer === 'smtp' ||
|
||||
$mail_mailer === 'pepipost'
|
||||
) {
|
||||
return parent::send();
|
||||
}
|
||||
|
||||
// We need this so that the \PHPMailer class will correctly prepare all the headers.
|
||||
$this->Mailer = 'mail';
|
||||
|
||||
// Prepare everything (including the message) for sending.
|
||||
if ( ! $this->preSend() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mailer = wp_mail_smtp()->get_providers()->get_mailer( $mail_mailer, $this );
|
||||
|
||||
if ( ! $mailer ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $mailer->is_php_compatible() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send the actual email.
|
||||
* We reuse everything, that was preprocessed for usage in \PHPMailer.
|
||||
*/
|
||||
$mailer->send();
|
||||
|
||||
return $mailer->is_email_sent();
|
||||
}
|
||||
}
|
||||
245
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Migration.php
Executable file
245
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Migration.php
Executable file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Migration helps migrate all plugin options saved into DB to a new storage location.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Migration {
|
||||
|
||||
/**
|
||||
* All old values for pre 1.0 version of a plugin.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $old_keys = array(
|
||||
'pepipost_ssl',
|
||||
'pepipost_port',
|
||||
'pepipost_pass',
|
||||
'pepipost_user',
|
||||
'smtp_pass',
|
||||
'smtp_user',
|
||||
'smtp_auth',
|
||||
'smtp_ssl',
|
||||
'smtp_port',
|
||||
'smtp_host',
|
||||
'mail_set_return_path',
|
||||
'mailer',
|
||||
'mail_from_name',
|
||||
'mail_from',
|
||||
'wp_mail_smtp_am_notifications_hidden',
|
||||
);
|
||||
|
||||
/**
|
||||
* Old values, taken from $old_keys options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $old_values = array();
|
||||
|
||||
/**
|
||||
* Converted array of data from previous option values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $new_values = array();
|
||||
|
||||
/**
|
||||
* Migration constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
if ( $this->is_migrated() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->old_values = $this->get_old_values();
|
||||
$this->new_values = $this->get_converted_options();
|
||||
|
||||
Options::init()->set( $this->new_values );
|
||||
|
||||
// Removing all options will be enabled some time in the future.
|
||||
// $this->clean_deprecated_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we already migrated or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_migrated() {
|
||||
|
||||
$is_migrated = false;
|
||||
$new_values = get_option( Options::META_KEY, array() );
|
||||
|
||||
if ( ! empty( $new_values ) ) {
|
||||
$is_migrated = true;
|
||||
}
|
||||
|
||||
return $is_migrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all old values from DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_old_values() {
|
||||
|
||||
$old_values = array();
|
||||
|
||||
foreach ( $this->old_keys as $old_key ) {
|
||||
$old_values[ $old_key ] = get_option( $old_key, '' );
|
||||
}
|
||||
|
||||
return $old_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert old values from key=>value to a multidimensional array of data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function get_converted_options() {
|
||||
|
||||
$converted = array();
|
||||
|
||||
foreach ( $this->old_keys as $old_key ) {
|
||||
|
||||
switch ( $old_key ) {
|
||||
case 'pepipost_user':
|
||||
case 'pepipost_pass':
|
||||
case 'pepipost_port':
|
||||
case 'pepipost_ssl':
|
||||
// Do not migrate pepipost options if it's not activated at the moment.
|
||||
if ( 'pepipost' === $this->old_values['mailer'] ) {
|
||||
$shortcut = explode( '_', $old_key );
|
||||
|
||||
if ( $old_key === 'pepipost_ssl' ) {
|
||||
$converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
|
||||
} else {
|
||||
$converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'smtp_host':
|
||||
case 'smtp_port':
|
||||
case 'smtp_ssl':
|
||||
case 'smtp_auth':
|
||||
case 'smtp_user':
|
||||
case 'smtp_pass':
|
||||
$shortcut = explode( '_', $old_key );
|
||||
|
||||
if ( $old_key === 'smtp_ssl' ) {
|
||||
$converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
|
||||
} elseif ( $old_key === 'smtp_auth' ) {
|
||||
$converted[ $shortcut[0] ][ $shortcut[1] ] = ( $this->old_values[ $old_key ] === 'true' ? 'yes' : 'no' );
|
||||
} else {
|
||||
$converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'mail_from':
|
||||
$converted['mail']['from_email'] = $this->old_values[ $old_key ];
|
||||
break;
|
||||
case 'mail_from_name':
|
||||
$converted['mail']['from_name'] = $this->old_values[ $old_key ];
|
||||
break;
|
||||
case 'mail_set_return_path':
|
||||
$converted['mail']['return_path'] = ( $this->old_values[ $old_key ] === 'true' );
|
||||
break;
|
||||
case 'mailer':
|
||||
$converted['mail']['mailer'] = $this->old_values[ $old_key ];
|
||||
break;
|
||||
case 'wp_mail_smtp_am_notifications_hidden':
|
||||
$converted['general']['am_notifications_hidden'] = ( $this->old_values[ $old_key ] === 'true' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$converted = $this->get_converted_constants_options( $converted );
|
||||
|
||||
return $converted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some users use constants in wp-config.php to define values.
|
||||
* We need to prioritize them and reapply data to options.
|
||||
* Use only those that are actually defined.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $converted
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_converted_constants_options( $converted ) {
|
||||
|
||||
// Are we configured via constants?
|
||||
if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) {
|
||||
return $converted;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mail settings.
|
||||
*/
|
||||
if ( defined( 'WPMS_MAIL_FROM' ) ) {
|
||||
$converted['mail']['from_email'] = WPMS_MAIL_FROM;
|
||||
}
|
||||
if ( defined( 'WPMS_MAIL_FROM_NAME' ) ) {
|
||||
$converted['mail']['from_name'] = WPMS_MAIL_FROM_NAME;
|
||||
}
|
||||
if ( defined( 'WPMS_MAILER' ) ) {
|
||||
$converted['mail']['return_path'] = WPMS_MAILER;
|
||||
}
|
||||
if ( defined( 'WPMS_SET_RETURN_PATH' ) ) {
|
||||
$converted['mail']['mailer'] = WPMS_SET_RETURN_PATH;
|
||||
}
|
||||
|
||||
/*
|
||||
* SMTP settings.
|
||||
*/
|
||||
if ( defined( 'WPMS_SMTP_HOST' ) ) {
|
||||
$converted['smtp']['host'] = WPMS_SMTP_HOST;
|
||||
}
|
||||
if ( defined( 'WPMS_SMTP_PORT' ) ) {
|
||||
$converted['smtp']['port'] = WPMS_SMTP_PORT;
|
||||
}
|
||||
if ( defined( 'WPMS_SSL' ) ) {
|
||||
$converted['smtp']['ssl'] = WPMS_SSL;
|
||||
}
|
||||
if ( defined( 'WPMS_SMTP_AUTH' ) ) {
|
||||
$converted['smtp']['auth'] = WPMS_SMTP_AUTH;
|
||||
}
|
||||
if ( defined( 'WPMS_SMTP_USER' ) ) {
|
||||
$converted['smtp']['user'] = WPMS_SMTP_USER;
|
||||
}
|
||||
if ( defined( 'WPMS_SMTP_PASS' ) ) {
|
||||
$converted['smtp']['pass'] = WPMS_SMTP_PASS;
|
||||
}
|
||||
|
||||
return $converted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all old values that are stored separately each.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function clean_deprecated_data() {
|
||||
|
||||
foreach ( $this->old_keys as $old_key ) {
|
||||
delete_option( $old_key );
|
||||
}
|
||||
}
|
||||
}
|
||||
607
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Options.php
Executable file
607
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Options.php
Executable file
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Options to handle all options management.
|
||||
* WordPress does all the heavy work for caching get_option() data,
|
||||
* so we don't have to do that. But we want to minimize cyclomatic complexity
|
||||
* of calling a bunch of WP functions, thus we will cache them in a class as well.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options {
|
||||
|
||||
/**
|
||||
* @var array Map of all the default options of the plugin.
|
||||
*/
|
||||
private static $map = array(
|
||||
'mail' => array(
|
||||
'from_name',
|
||||
'from_email',
|
||||
'mailer',
|
||||
'return_path',
|
||||
),
|
||||
'smtp' => array(
|
||||
'host',
|
||||
'port',
|
||||
'encryption',
|
||||
'autotls',
|
||||
'auth',
|
||||
'user',
|
||||
'pass',
|
||||
),
|
||||
'gmail' => array(
|
||||
'client_id',
|
||||
'client_secret',
|
||||
),
|
||||
'mailgun' => array(
|
||||
'api_key',
|
||||
'domain',
|
||||
),
|
||||
'sendgrid' => array(
|
||||
'api_key',
|
||||
),
|
||||
'pepipost' => array(
|
||||
'host',
|
||||
'port',
|
||||
'encryption',
|
||||
'auth',
|
||||
'user',
|
||||
'pass',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* That's where plugin options are saved in wp_options table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const META_KEY = 'wp_mail_smtp';
|
||||
|
||||
/**
|
||||
* All the plugin options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_options = array();
|
||||
|
||||
/**
|
||||
* Init the Options class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->populate_options();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all the options, used for chaining.
|
||||
*
|
||||
* One-liner:
|
||||
* Options::init()->get('smtp', 'host');
|
||||
* Options::init()->is_pepipost_active();
|
||||
*
|
||||
* Or multiple-usage:
|
||||
* $options = new Options();
|
||||
* $options->get('smtp', 'host');
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Options
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
static $instance;
|
||||
|
||||
if ( ! $instance ) {
|
||||
$instance = new self();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all options of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function populate_options() {
|
||||
$this->_options = get_option( self::META_KEY, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the options.
|
||||
*
|
||||
* Options::init()->get_all();
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_all() {
|
||||
|
||||
$options = $this->_options;
|
||||
|
||||
foreach ( $options as $group => $g_value ) {
|
||||
foreach ( $g_value as $key => $value ) {
|
||||
$options[ $group ][ $key ] = $this->get( $group, $key );
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_options_get_all', $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the options for a group.
|
||||
*
|
||||
* Options::init()->get_group('smtp') - will return only array of options (or empty array if a key doesn't exist).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_group( $group ) {
|
||||
|
||||
// Just to feel safe.
|
||||
$group = sanitize_key( $group );
|
||||
|
||||
if ( isset( $this->_options[ $group ] ) ) {
|
||||
|
||||
foreach ( $this->_options[ $group ] as $g_key => $g_value ) {
|
||||
$options[ $group ][ $g_key ] = $this->get( $group, $g_key );
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_options_get_group', $this->_options[ $group ], $group );
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options by a group and a key.
|
||||
*
|
||||
* Options::init()->get( 'smtp', 'host' ) - will return only SMTP 'host' option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $group, $key ) {
|
||||
|
||||
// Just to feel safe.
|
||||
$group = sanitize_key( $group );
|
||||
$key = sanitize_key( $key );
|
||||
|
||||
// Get the options group.
|
||||
if ( isset( $this->_options[ $group ] ) ) {
|
||||
|
||||
// Get the options key of a group.
|
||||
if ( isset( $this->_options[ $group ][ $key ] ) ) {
|
||||
$value = $this->get_const_value( $group, $key, $this->_options[ $group ][ $key ] );
|
||||
} else {
|
||||
$value = $this->postprocess_key_defaults( $group, $key );
|
||||
}
|
||||
} else {
|
||||
$value = $this->postprocess_key_defaults( $group, $key );
|
||||
}
|
||||
|
||||
if ( is_string( $value ) ) {
|
||||
$value = stripslashes( $value );
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_options_get', $value, $group, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Some options may be non-empty by default,
|
||||
* so we need to postprocess them to convert.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postprocess_key_defaults( $group, $key ) {
|
||||
|
||||
$value = '';
|
||||
|
||||
switch ( $key ) {
|
||||
case 'return_path':
|
||||
$value = $group === 'mail' ? false : true;
|
||||
break;
|
||||
|
||||
case 'encryption':
|
||||
$value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? 'none' : $value;
|
||||
break;
|
||||
|
||||
case 'auth':
|
||||
case 'autotls':
|
||||
$value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? false : true;
|
||||
break;
|
||||
|
||||
case 'pass':
|
||||
$value = $this->get_const_value( $group, $key, $value );
|
||||
break;
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_options_postprocess_key_defaults', $value, $group, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the options values through the constants check.
|
||||
* If we have defined associated constant - use it instead of a DB value.
|
||||
* Backward compatibility is hard.
|
||||
* General section of options won't have constants, so we are omitting those checks and just return default value.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_const_value( $group, $key, $value ) {
|
||||
|
||||
if ( ! $this->is_const_enabled() ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
switch ( $group ) {
|
||||
case 'mail':
|
||||
switch ( $key ) {
|
||||
case 'from_name':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_MAIL_FROM_NAME : $value;
|
||||
case 'from_email':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_MAIL_FROM : $value;
|
||||
case 'mailer':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_MAILER : $value;
|
||||
case 'return_path':
|
||||
return $this->is_const_defined( $group, $key ) ? true : $value;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'smtp':
|
||||
switch ( $key ) {
|
||||
case 'host':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_HOST : $value;
|
||||
case 'port':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_PORT : $value;
|
||||
case 'encryption':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key )
|
||||
? ( WPMS_SSL === '' ? 'none' : WPMS_SSL )
|
||||
: $value;
|
||||
case 'auth':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTH : $value;
|
||||
case 'autotls':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTOTLS : $value;
|
||||
case 'user':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_USER : $value;
|
||||
case 'pass':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_PASS : $value;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'gmail':
|
||||
switch ( $key ) {
|
||||
case 'client_id':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_GMAIL_CLIENT_ID : $value;
|
||||
case 'client_secret':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_GMAIL_CLIENT_SECRET : $value;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'mailgun':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_MAILGUN_API_KEY : $value;
|
||||
case 'domain':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_MAILGUN_DOMAIN : $value;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'sendgrid':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
return $this->is_const_defined( $group, $key ) ? WPMS_SENDGRID_API_KEY : $value;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Always return the default value if nothing from above matches the request.
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether constants redefinition is enabled or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_const_enabled() {
|
||||
return defined( 'WPMS_ON' ) && WPMS_ON === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need this check to reuse later in admin area,
|
||||
* to distinguish settings fields that were redefined,
|
||||
* and display them differently.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_const_defined( $group, $key ) {
|
||||
|
||||
if ( ! $this->is_const_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Just to feel safe.
|
||||
$group = sanitize_key( $group );
|
||||
$key = sanitize_key( $key );
|
||||
|
||||
switch ( $group ) {
|
||||
case 'mail':
|
||||
switch ( $key ) {
|
||||
case 'from_name':
|
||||
return defined( 'WPMS_MAIL_FROM_NAME' ) && WPMS_MAIL_FROM_NAME;
|
||||
case 'from_email':
|
||||
return defined( 'WPMS_MAIL_FROM' ) && WPMS_MAIL_FROM;
|
||||
case 'mailer':
|
||||
return defined( 'WPMS_MAILER' ) && WPMS_MAILER;
|
||||
case 'return_path':
|
||||
return defined( 'WPMS_SET_RETURN_PATH' ) && ( WPMS_SET_RETURN_PATH === 'true' || WPMS_SET_RETURN_PATH === true );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'smtp':
|
||||
switch ( $key ) {
|
||||
case 'host':
|
||||
return defined( 'WPMS_SMTP_HOST' ) && WPMS_SMTP_HOST;
|
||||
case 'port':
|
||||
return defined( 'WPMS_SMTP_PORT' ) && WPMS_SMTP_PORT;
|
||||
case 'encryption':
|
||||
return defined( 'WPMS_SSL' );
|
||||
case 'auth':
|
||||
return defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH;
|
||||
case 'autotls':
|
||||
return defined( 'WPMS_SMTP_AUTOTLS' ) && WPMS_SMTP_AUTOTLS;
|
||||
case 'user':
|
||||
return defined( 'WPMS_SMTP_USER' ) && WPMS_SMTP_USER;
|
||||
case 'pass':
|
||||
return defined( 'WPMS_SMTP_PASS' ) && WPMS_SMTP_PASS;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'gmail':
|
||||
switch ( $key ) {
|
||||
case 'client_id':
|
||||
return defined( 'WPMS_GMAIL_CLIENT_ID' ) && WPMS_GMAIL_CLIENT_ID;
|
||||
case 'client_secret':
|
||||
return defined( 'WPMS_GMAIL_CLIENT_SECRET' ) && WPMS_GMAIL_CLIENT_SECRET;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'mailgun':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
return defined( 'WPMS_MAILGUN_API_KEY' ) && WPMS_MAILGUN_API_KEY;
|
||||
case 'domain':
|
||||
return defined( 'WPMS_MAILGUN_DOMAIN' ) && WPMS_MAILGUN_DOMAIN;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'sendgrid':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
return defined( 'WPMS_SENDGRID_API_KEY' ) && WPMS_SENDGRID_API_KEY;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin options, all at once.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.3.0 Added $once argument to save option only if they don't exist already.
|
||||
*
|
||||
* @param array $options Plugin options to save.
|
||||
* @param bool $once Whether to update existing options or to add these options only once.
|
||||
*/
|
||||
public function set( $options, $once = false ) {
|
||||
|
||||
foreach ( (array) $options as $group => $keys ) {
|
||||
foreach ( $keys as $key_name => $key_value ) {
|
||||
switch ( $group ) {
|
||||
case 'mail':
|
||||
switch ( $key_name ) {
|
||||
case 'from_name':
|
||||
case 'mailer':
|
||||
$options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, wp_strip_all_tags( $options[ $group ][ $key_name ], true ) );
|
||||
break;
|
||||
case 'from_email':
|
||||
if ( filter_var( $options[ $group ][ $key_name ], FILTER_VALIDATE_EMAIL ) ) {
|
||||
$options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, sanitize_email( $options[ $group ][ $key_name ] ) );
|
||||
}
|
||||
break;
|
||||
case 'return_path':
|
||||
$options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, (bool) $options[ $group ][ $key_name ] );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'general':
|
||||
switch ( $key_name ) {
|
||||
case 'am_notifications_hidden':
|
||||
$options[ $group ][ $key_name ] = (bool) $options[ $group ][ $key_name ];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $options[ $options['mail']['mailer'] ] ) &&
|
||||
in_array( $options['mail']['mailer'], array( 'pepipost', 'smtp', 'sendgrid', 'mailgun', 'gmail' ), true )
|
||||
) {
|
||||
|
||||
$mailer = $options['mail']['mailer'];
|
||||
|
||||
foreach ( $options[ $mailer ] as $key_name => $key_value ) {
|
||||
switch ( $key_name ) {
|
||||
case 'host':
|
||||
case 'user':
|
||||
$options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, wp_strip_all_tags( $options[ $mailer ][ $key_name ], true ) );
|
||||
break;
|
||||
case 'port':
|
||||
$options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, intval( $options[ $mailer ][ $key_name ] ) );
|
||||
break;
|
||||
case 'encryption':
|
||||
$options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, wp_strip_all_tags( $options[ $mailer ][ $key_name ], true ) );
|
||||
break;
|
||||
case 'auth':
|
||||
case 'autotls':
|
||||
$value = $options[ $mailer ][ $key_name ] === 'yes' || $options[ $mailer ][ $key_name ] === true ? true : false;
|
||||
|
||||
$options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, $value );
|
||||
break;
|
||||
|
||||
case 'pass':
|
||||
case 'api_key':
|
||||
case 'domain':
|
||||
case 'client_id':
|
||||
case 'client_secret':
|
||||
case 'auth_code':
|
||||
case 'access_token':
|
||||
// Do not process as they may contain certain special characters, but allow to be overwritten using constants.
|
||||
$options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, $options[ $mailer ][ $key_name ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$options = apply_filters( 'wp_mail_smtp_options_set', $options );
|
||||
|
||||
// Whether to update existing options or to add these options only once if they don't exist yet.
|
||||
if ( $once ) {
|
||||
add_option( self::META_KEY, $options, '', 'no' ); // Do not autoload these options.
|
||||
} else {
|
||||
update_option( self::META_KEY, $options, 'no' );
|
||||
}
|
||||
|
||||
// Now we need to re-cache values.
|
||||
$this->populate_options();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge recursively, including a proper substitution of values in sub-arrays when keys are the same.
|
||||
* It's more like array_merge() and array_merge_recursive() combined.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function array_merge_recursive() {
|
||||
|
||||
$arrays = func_get_args();
|
||||
|
||||
if ( count( $arrays ) < 2 ) {
|
||||
return isset( $arrays[0] ) ? $arrays[0] : array();
|
||||
}
|
||||
|
||||
$merged = array();
|
||||
|
||||
while ( $arrays ) {
|
||||
$array = array_shift( $arrays );
|
||||
|
||||
if ( ! is_array( $array ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( empty( $array ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $array as $key => $value ) {
|
||||
if ( is_string( $key ) ) {
|
||||
if (
|
||||
is_array( $value ) &&
|
||||
array_key_exists( $key, $merged ) &&
|
||||
is_array( $merged[ $key ] )
|
||||
) {
|
||||
$merged[ $key ] = call_user_func( __METHOD__, $merged[ $key ], $value );
|
||||
} else {
|
||||
$merged[ $key ] = $value;
|
||||
}
|
||||
} else {
|
||||
$merged[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the site is using Pepipost or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_pepipost_active() {
|
||||
return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', $this->get( 'mail', 'mailer' ) === 'pepipost' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the site is using Pepipost/SMTP as a mailer or not.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_smtp() {
|
||||
return apply_filters( 'wp_mail_smtp_options_is_mailer_smtp', in_array( $this->get( 'mail', 'mailer' ), array( 'pepipost', 'smtp' ), true ) );
|
||||
}
|
||||
}
|
||||
175
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Processor.php
Executable file
175
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Processor.php
Executable file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Processor modifies the behaviour of wp_mail() function.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Processor {
|
||||
|
||||
/**
|
||||
* Processor constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign all hooks to proper places.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function hooks() {
|
||||
|
||||
add_action( 'phpmailer_init', array( $this, 'phpmailer_init' ) );
|
||||
|
||||
add_filter( 'wp_mail_from', array( $this, 'filter_mail_from_email' ) );
|
||||
add_filter( 'wp_mail_from_name', array( $this, 'filter_mail_from_name' ), 11 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine certain PHPMailer options with our custom ones.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \PHPMailer $phpmailer It's passed by reference, so no need to return anything.
|
||||
*/
|
||||
public function phpmailer_init( $phpmailer ) {
|
||||
|
||||
$options = new Options();
|
||||
$mailer = $options->get( 'mail', 'mailer' );
|
||||
|
||||
// Check that mailer is not blank, and if mailer=smtp, host is not blank.
|
||||
if (
|
||||
! $mailer ||
|
||||
( 'smtp' === $mailer && ! $options->get( 'smtp', 'host' ) )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the mailer is pepipost, make sure we have a username and password.
|
||||
if (
|
||||
'pepipost' === $mailer &&
|
||||
( ! $options->get( 'pepipost', 'user' ) && ! $options->get( 'pepipost', 'pass' ) )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the mailer type as per config above, this overrides the already called isMail method.
|
||||
// It's basically always 'smtp'.
|
||||
$phpmailer->Mailer = $mailer;
|
||||
|
||||
// Set the Sender (return-path) if required.
|
||||
if ( $options->get( 'mail', 'return_path' ) ) {
|
||||
$phpmailer->Sender = $phpmailer->From;
|
||||
}
|
||||
|
||||
// Set the SMTPSecure value, if set to none, leave this blank. Possible values: 'ssl', 'tls', ''.
|
||||
if ( 'none' === $options->get( $mailer, 'encryption' ) ) {
|
||||
$phpmailer->SMTPSecure = '';
|
||||
} else {
|
||||
$phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' );
|
||||
}
|
||||
|
||||
// Check if user has disabled SMTPAutoTLS.
|
||||
if ( $options->get( $mailer, 'encryption' ) !== 'tls' && ! $options->get( $mailer, 'autotls' ) ) {
|
||||
$phpmailer->SMTPAutoTLS = false;
|
||||
}
|
||||
|
||||
// If we're sending via SMTP, set the host.
|
||||
if ( 'smtp' === $mailer ) {
|
||||
// Set the other options.
|
||||
$phpmailer->Host = $options->get( $mailer, 'host' );
|
||||
$phpmailer->Port = $options->get( $mailer, 'port' );
|
||||
|
||||
// If we're using smtp auth, set the username & password.
|
||||
if ( $options->get( $mailer, 'auth' ) ) {
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->Username = $options->get( $mailer, 'user' );
|
||||
$phpmailer->Password = $options->get( $mailer, 'pass' );
|
||||
}
|
||||
} elseif ( 'pepipost' === $mailer ) {
|
||||
// Set the Pepipost settings for BC.
|
||||
$phpmailer->Mailer = 'smtp';
|
||||
$phpmailer->Host = 'smtp.pepipost.com';
|
||||
$phpmailer->Port = $options->get( $mailer, 'port' );
|
||||
$phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' ) === 'none' ? '' : $options->get( $mailer, 'encryption' );
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->Username = $options->get( $mailer, 'user' );
|
||||
$phpmailer->Password = $options->get( $mailer, 'pass' );
|
||||
}
|
||||
|
||||
// You can add your own options here.
|
||||
// See the phpmailer documentation for more info: https://github.com/PHPMailer/PHPMailer/tree/5.2-stable.
|
||||
/** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */
|
||||
$phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the email address that is used for sending emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $email
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_mail_from_email( $email ) {
|
||||
|
||||
// If the from email is not the default, return it unchanged.
|
||||
if ( $email !== $this->get_default_email() ) {
|
||||
return $email;
|
||||
}
|
||||
|
||||
$from_email = Options::init()->get( 'mail', 'from_email' );
|
||||
|
||||
if ( ! empty( $from_email ) ) {
|
||||
return $from_email;
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the sender name that is used for sending emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_mail_from_name( $name ) {
|
||||
|
||||
if ( 'WordPress' === $name ) {
|
||||
$name = Options::init()->get( 'mail', 'from_name' );
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default email address based on domain name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_email() {
|
||||
|
||||
// In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
|
||||
$server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
|
||||
|
||||
// Get the site domain and get rid of www.
|
||||
$sitename = strtolower( $server_name );
|
||||
if ( substr( $sitename, 0, 4 ) === 'www.' ) {
|
||||
$sitename = substr( $sitename, 4 );
|
||||
}
|
||||
|
||||
return 'wordpress@' . $sitename;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Class AuthAbstract.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class AuthAbstract implements AuthInterface {
|
||||
|
||||
/**
|
||||
* Get the url, that users will be redirected back to finish the OAuth process.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_auth_url() {
|
||||
return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface AuthInterface.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface AuthInterface {
|
||||
|
||||
/**
|
||||
* Do something for this Auth implementation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function process();
|
||||
|
||||
}
|
||||
321
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Auth.php
Executable file
321
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Auth.php
Executable file
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
use WPMailSMTP\Providers\AuthAbstract;
|
||||
|
||||
/**
|
||||
* Class Auth to request access and refresh tokens.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Auth extends AuthAbstract {
|
||||
|
||||
/**
|
||||
* Gmail options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $gmail;
|
||||
|
||||
/**
|
||||
* @var \Google_Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mailer;
|
||||
|
||||
/**
|
||||
* Auth constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$this->mailer = $options->get( 'mail', 'mailer' );
|
||||
|
||||
if ( $this->mailer !== 'gmail' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->gmail = $options->get_group( $this->mailer );
|
||||
|
||||
if ( $this->is_clients_saved() ) {
|
||||
|
||||
$this->include_google_lib();
|
||||
|
||||
$this->client = $this->get_client();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the composer autoloader to include the Google Library and all its dependencies.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function include_google_lib() {
|
||||
require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Init and get the Google Client object.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_client() {
|
||||
|
||||
// Doesn't load client twice + gives ability to overwrite.
|
||||
if ( ! empty( $this->client ) ) {
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
$client = new \Google_Client(
|
||||
array(
|
||||
'client_id' => $this->gmail['client_id'],
|
||||
'client_secret' => $this->gmail['client_secret'],
|
||||
'redirect_uris' => array(
|
||||
Auth::get_plugin_auth_url(),
|
||||
),
|
||||
)
|
||||
);
|
||||
$client->setAccessType( 'offline' );
|
||||
$client->setApprovalPrompt( 'force' );
|
||||
$client->setIncludeGrantedScopes( true );
|
||||
// We request only the sending capability, as it's what we only need to do.
|
||||
$client->setScopes( array( \Google_Service_Gmail::GMAIL_SEND ) );
|
||||
$client->setRedirectUri( self::get_plugin_auth_url() );
|
||||
|
||||
if (
|
||||
empty( $this->gmail['access_token'] ) &&
|
||||
! empty( $this->gmail['auth_code'] )
|
||||
) {
|
||||
try {
|
||||
$creds = $client->fetchAccessTokenWithAuthCode( $this->gmail['auth_code'] );
|
||||
} catch ( \Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
Debug::set( $e->getMessage() );
|
||||
}
|
||||
|
||||
// Bail if we have an error.
|
||||
if ( ! empty( $creds['error'] ) ) {
|
||||
// TODO: save this error to display to a user later.
|
||||
return $client;
|
||||
}
|
||||
|
||||
$this->update_access_token( $client->getAccessToken() );
|
||||
$this->update_refresh_token( $client->getRefreshToken() );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->gmail['access_token'] ) ) {
|
||||
$client->setAccessToken( $this->gmail['access_token'] );
|
||||
}
|
||||
|
||||
// Refresh the token if it's expired.
|
||||
if ( $client->isAccessTokenExpired() ) {
|
||||
$refresh = $client->getRefreshToken();
|
||||
if ( empty( $refresh ) && isset( $this->gmail['refresh_token'] ) ) {
|
||||
$refresh = $this->gmail['refresh_token'];
|
||||
}
|
||||
|
||||
if ( ! empty( $refresh ) ) {
|
||||
try {
|
||||
$creds = $client->fetchAccessTokenWithRefreshToken( $refresh );
|
||||
} catch ( \Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
Debug::set( $e->getMessage() );
|
||||
}
|
||||
|
||||
// Bail if we have an error.
|
||||
if ( ! empty( $creds['error'] ) ) {
|
||||
return $client;
|
||||
}
|
||||
|
||||
$this->update_access_token( $client->getAccessToken() );
|
||||
$this->update_refresh_token( $client->getRefreshToken() );
|
||||
}
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the auth code from the $_GET and save it.
|
||||
* Redirect user back to settings with an error message, if failed.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function process() {
|
||||
|
||||
// We can't process without saved client_id/secret.
|
||||
if ( ! $this->is_clients_saved() ) {
|
||||
Debug::set( 'There was an error while processing the Google authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.' );
|
||||
wp_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_no_clients',
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$code = '';
|
||||
$scope = '';
|
||||
$error = '';
|
||||
|
||||
if ( isset( $_GET['error'] ) ) {
|
||||
$error = sanitize_key( $_GET['error'] );
|
||||
}
|
||||
|
||||
// In case of any error: display a message to a user.
|
||||
if ( ! empty( $error ) ) {
|
||||
wp_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_' . $error,
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['code'] ) ) {
|
||||
$code = $_GET['code'];
|
||||
}
|
||||
if ( isset( $_GET['scope'] ) ) {
|
||||
$scope = urldecode( $_GET['scope'] );
|
||||
}
|
||||
|
||||
// Let's try to get the access token.
|
||||
if (
|
||||
! empty( $code ) &&
|
||||
(
|
||||
$scope === ( \Google_Service_Gmail::GMAIL_SEND . ' ' . \Google_Service_Gmail::MAIL_GOOGLE_COM ) ||
|
||||
$scope === \Google_Service_Gmail::GMAIL_SEND
|
||||
)
|
||||
) {
|
||||
// Save the auth code. So \Google_Client can reuse it to retrieve the access token.
|
||||
$this->update_auth_code( $code );
|
||||
} else {
|
||||
wp_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_no_code_scope',
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
wp_redirect(
|
||||
add_query_arg(
|
||||
'success',
|
||||
'google_site_linked',
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update access token in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $token
|
||||
*/
|
||||
protected function update_access_token( $token ) {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$all = $options->get_all();
|
||||
|
||||
$all[ $this->mailer ]['access_token'] = $token;
|
||||
$this->gmail['access_token'] = $token;
|
||||
|
||||
$options->set( $all );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update refresh token in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $token
|
||||
*/
|
||||
protected function update_refresh_token( $token ) {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$all = $options->get_all();
|
||||
|
||||
$all[ $this->mailer ]['refresh_token'] = $token;
|
||||
$this->gmail['refresh_token'] = $token;
|
||||
|
||||
$options->set( $all );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update auth code in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $code
|
||||
*/
|
||||
protected function update_auth_code( $code ) {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$all = $options->get_all();
|
||||
|
||||
$all[ $this->mailer ]['auth_code'] = $code;
|
||||
$this->gmail['auth_code'] = $code;
|
||||
|
||||
$options->set( $all );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the auth URL used to proceed to Google to request access to send emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_google_auth_url() {
|
||||
if (
|
||||
! empty( $this->client ) &&
|
||||
class_exists( 'Google_Client', false ) &&
|
||||
$this->client instanceof \Google_Client
|
||||
) {
|
||||
return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether user saved Client ID and Client Secret or not.
|
||||
* Both options are required.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_clients_saved() {
|
||||
return ! empty( $this->gmail['client_id'] ) && ! empty( $this->gmail['client_secret'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we have an access and refresh tokens or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_auth_required() {
|
||||
return empty( $this->gmail['access_token'] ) || empty( $this->gmail['refresh_token'] );
|
||||
}
|
||||
}
|
||||
168
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Mailer.php
Executable file
168
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Mailer.php
Executable file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
* Not used for Gmail, as we are using its API.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send';
|
||||
|
||||
/**
|
||||
* Gmail custom Auth library.
|
||||
*
|
||||
* @var Auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Gmail message.
|
||||
*
|
||||
* @var \Google_Service_Gmail_Message
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
if ( ! $this->is_php_compatible() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Include the Google library.
|
||||
require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
$this->auth = new Auth();
|
||||
$this->message = new \Google_Service_Gmail_Message();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer ) {
|
||||
// Make sure that we have access to MailCatcher class methods.
|
||||
if (
|
||||
! $phpmailer instanceof MailCatcher &&
|
||||
! $phpmailer instanceof \PHPMailer
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->phpmailer = $phpmailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use Google API Services to send emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
// Get the raw MIME email using \MailCatcher data.
|
||||
$base64 = base64_encode( $this->phpmailer->getSentMIMEMessage() );
|
||||
$base64 = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $base64 ); // url safe.
|
||||
$this->message->setRaw( $base64 );
|
||||
|
||||
$service = new \Google_Service_Gmail( $this->auth->get_client() );
|
||||
|
||||
try {
|
||||
$response = $service->users_messages->send( 'me', $this->message );
|
||||
|
||||
$this->process_response( $response );
|
||||
} catch ( \Exception $e ) {
|
||||
Debug::set( 'Error while sending via Gmail mailer: ' . $e->getMessage() );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save response from the API to use it later.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \Google_Service_Gmail_Message $response
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the email was sent.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
$is_sent = false;
|
||||
|
||||
if ( method_exists( $this->response, 'getId' ) ) {
|
||||
$message_id = $this->response->getId();
|
||||
if ( ! empty( $message_id ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $is_sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$gmail_text = array();
|
||||
|
||||
$options = new \WPMailSMTP\Options();
|
||||
$gmail = $options->get_group( 'gmail' );
|
||||
|
||||
$gmail_text[] = '<strong>Client ID/Secret:</strong> ' . ( ! empty( $gmail['client_id'] ) && ! empty( $gmail['client_secret'] ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>Auth Code:</strong> ' . ( ! empty( $gmail['auth_code'] ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>Access Token:</strong> ' . ( ! empty( $gmail['access_token'] ) ? 'Yes' : 'No' );
|
||||
|
||||
$gmail_text[] = '<br><strong>Server:</strong>';
|
||||
|
||||
$gmail_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.allow_url_fopen:</strong> ' . ( ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.stream_socket_client():</strong> ' . ( function_exists( 'stream_socket_client' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.fsockopen():</strong> ' . ( function_exists( 'fsockopen' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.curl_version():</strong> ' . ( function_exists( 'curl_version' ) ? 'Yes' : 'No' );
|
||||
if ( function_exists( 'apache_get_modules' ) ) {
|
||||
$modules = apache_get_modules();
|
||||
$gmail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'selinux_is_enabled' ) ) {
|
||||
$gmail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'grsecurity_is_enabled' ) ) {
|
||||
$gmail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
|
||||
return implode( '<br>', $gmail_text );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailgun constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/gmail.png',
|
||||
'slug' => 'gmail',
|
||||
'title' => esc_html__( 'Gmail', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - opening link tag; %2$s - closing link tag. */
|
||||
__( 'Send emails using your Gmail or G Suite (formerly Google Apps) account, all while keeping your login credentials safe. Other Google SMTP methods require enabling less secure apps in your account and entering your password. However, this integration uses the Google API to improve email delivery issues while keeping your site secure.<br><br>Read our %1$sGmail documentation%2$s to learn how to configure Gmail or G Suite.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
'php' => '5.5',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Client ID -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" 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-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"><?php esc_html_e( 'Client ID', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_id]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_id' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'client_id' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Client Secret -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" 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-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"><?php esc_html_e( 'Client Secret', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_secret' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'client_secret' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Authorized redirect URI -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect" 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-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"><?php esc_html_e( 'Authorized redirect URI', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input type="text" readonly="readonly"
|
||||
value="<?php echo esc_attr( Auth::get_plugin_auth_url() ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
|
||||
/>
|
||||
<button type="button" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-light-grey wp-mail-smtp-setting-copy"
|
||||
title="<?php esc_attr_e( 'Copy URL to clipboard', 'wp-mail-smtp' ); ?>"
|
||||
data-source_id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect">
|
||||
<span class="dashicons dashicons-admin-page"></span>
|
||||
</button>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'This is the path on your site that you will be redirected to after you have authenticated with Google.', 'wp-mail-smtp' ); ?>
|
||||
<br>
|
||||
<?php esc_html_e( 'You need to copy this URL into "Authorized redirect URIs" field for you web application on Google APIs site for your project there.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Auth users button -->
|
||||
<?php $auth = new Auth(); ?>
|
||||
<?php if ( $auth->is_clients_saved() && $auth->is_auth_required() ) : ?>
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Authorize', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<a href="<?php echo esc_url( $auth->get_google_auth_url() ); ?>" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange">
|
||||
<?php esc_html_e( 'Allow plugin to send emails using your Google account', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Click the button above to confirm authorization.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
188
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Providers/Loader.php
Executable file
188
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Providers/Loader.php
Executable file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Class Loader.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Loader {
|
||||
|
||||
/**
|
||||
* Key is the mailer option, value is the path to its classes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $providers = array(
|
||||
'mail' => 'WPMailSMTP\Providers\Mail\\',
|
||||
'gmail' => 'WPMailSMTP\Providers\Gmail\\',
|
||||
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
|
||||
'sendgrid' => 'WPMailSMTP\Providers\Sendgrid\\',
|
||||
'pepipost' => 'WPMailSMTP\Providers\Pepipost\\',
|
||||
'smtp' => 'WPMailSMTP\Providers\SMTP\\',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \WPMailSMTP\MailCatcher
|
||||
*/
|
||||
private $phpmailer;
|
||||
|
||||
/**
|
||||
* Get all the supported providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_providers() {
|
||||
|
||||
if ( ! Options::init()->is_pepipost_active() ) {
|
||||
unset( $this->providers['pepipost'] );
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers', $this->providers );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single provider FQN-path based on its name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_provider_path( $provider ) {
|
||||
$provider = sanitize_key( $provider );
|
||||
|
||||
return apply_filters(
|
||||
'wp_mail_smtp_providers_loader_get_provider_path',
|
||||
isset( $this->providers[ $provider ] ) ? $this->providers[ $provider ] : null,
|
||||
$provider
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider options, if exists.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
*
|
||||
* @return \WPMailSMTP\Providers\OptionsAbstract|null
|
||||
*/
|
||||
public function get_options( $provider ) {
|
||||
return $this->get_entity( $provider, 'Options' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all options of all providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \WPMailSMTP\Providers\OptionsAbstract[]
|
||||
*/
|
||||
public function get_options_all() {
|
||||
$options = array();
|
||||
|
||||
foreach ( $this->get_providers() as $provider => $path ) {
|
||||
|
||||
$option = $this->get_options( $provider );
|
||||
|
||||
if ( ! $option instanceof OptionsAbstract ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$slug = $option->get_slug();
|
||||
$title = $option->get_title();
|
||||
|
||||
if ( empty( $title ) || empty( $slug ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[] = $option;
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers_all', $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider mailer, if exists.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
* @param MailCatcher $phpmailer
|
||||
*
|
||||
* @return \WPMailSMTP\Providers\MailerAbstract|null
|
||||
*/
|
||||
public function get_mailer( $provider, $phpmailer ) {
|
||||
|
||||
if (
|
||||
$phpmailer instanceof MailCatcher ||
|
||||
$phpmailer instanceof \PHPMailer
|
||||
) {
|
||||
$this->phpmailer = $phpmailer;
|
||||
}
|
||||
|
||||
return $this->get_entity( $provider, 'Mailer' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider auth, if exists.
|
||||
*
|
||||
* @param string $provider
|
||||
*
|
||||
* @return \WPMailSMTP\Providers\AuthAbstract|null
|
||||
*/
|
||||
public function get_auth( $provider ) {
|
||||
return $this->get_entity( $provider, 'Auth' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a generic entity based on the request.
|
||||
*
|
||||
* @uses ReflectionClass
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
* @param string $request
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function get_entity( $provider, $request ) {
|
||||
|
||||
$provider = sanitize_key( $provider );
|
||||
$request = sanitize_text_field( $request );
|
||||
$path = $this->get_provider_path( $provider );
|
||||
$entity = null;
|
||||
|
||||
if ( empty( $path ) ) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
try {
|
||||
$reflection = new \ReflectionClass( $path . $request );
|
||||
|
||||
if ( file_exists( $reflection->getFileName() ) ) {
|
||||
$class = $path . $request;
|
||||
if ( $this->phpmailer ) {
|
||||
$entity = new $class( $this->phpmailer );
|
||||
} else {
|
||||
$entity = new $class();
|
||||
}
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
Debug::set( "There was a problem while retrieving {$request} for {$provider}: {$e->getMessage()}" );
|
||||
$entity = null;
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_entity', $entity, $provider, $request );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mail;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer inherits everything from parent abstract class.
|
||||
* This file is required for a proper work of Loader and \ReflectionClass.
|
||||
*
|
||||
* @package WPMailSMTP\Providers\Mail
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mail_text = array();
|
||||
|
||||
$mail_text[] = '<br><strong>Server:</strong>';
|
||||
|
||||
$disabled_functions = ini_get( 'disable_functions' );
|
||||
$disabled = (array) explode( ',', trim( $disabled_functions ) );
|
||||
|
||||
$mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
|
||||
if ( function_exists( 'apache_get_modules' ) ) {
|
||||
$modules = apache_get_modules();
|
||||
$mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'selinux_is_enabled' ) ) {
|
||||
$mail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'grsecurity_is_enabled' ) ) {
|
||||
$mail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
|
||||
return implode( '<br>', $mail_text );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mail;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mail constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/php.png',
|
||||
'slug' => 'mail',
|
||||
'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Class MailerAbstract.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class MailerAbstract implements MailerInterface {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
/**
|
||||
* @var MailCatcher
|
||||
*/
|
||||
protected $phpmailer;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $mailer = '';
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = '';
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $body = array();
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $response = array();
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( MailCatcher $phpmailer ) {
|
||||
|
||||
$this->options = new Options();
|
||||
$this->mailer = $this->options->get( 'mail', 'mailer' );
|
||||
|
||||
// Only non-SMTP mailers need URL.
|
||||
if ( ! $this->options->is_mailer_smtp() && empty( $this->url ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->process_phpmailer( $phpmailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcher $phpmailer
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer ) {
|
||||
|
||||
// Make sure that we have access to MailCatcher class methods.
|
||||
if (
|
||||
! $phpmailer instanceof MailCatcher &&
|
||||
! $phpmailer instanceof \PHPMailer
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->phpmailer = $phpmailer;
|
||||
|
||||
// Prevent working with those methods, as they are not needed for SMTP-like mailers.
|
||||
if ( $this->options->is_mailer_smtp() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_headers( $this->phpmailer->getCustomHeaders() );
|
||||
$this->set_from( $this->phpmailer->From, $this->phpmailer->FromName );
|
||||
$this->set_recipients(
|
||||
array(
|
||||
'to' => $this->phpmailer->getToAddresses(),
|
||||
'cc' => $this->phpmailer->getCcAddresses(),
|
||||
'bcc' => $this->phpmailer->getBccAddresses(),
|
||||
)
|
||||
);
|
||||
$this->set_subject( $this->phpmailer->Subject );
|
||||
$this->set_content(
|
||||
array(
|
||||
'html' => $this->phpmailer->Body,
|
||||
'text' => $this->phpmailer->AltBody,
|
||||
)
|
||||
);
|
||||
$this->set_return_path( $this->phpmailer->From );
|
||||
$this->set_reply_to( $this->phpmailer->getReplyToAddresses() );
|
||||
|
||||
/*
|
||||
* In some cases we will need to modify the internal structure
|
||||
* of the body content, if attachments are present.
|
||||
* So lets make this call the last one.
|
||||
*/
|
||||
$this->set_attachments( $this->phpmailer->getAttachments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'subject' => $subject,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request params, that goes to the body of the HTTP request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $param Key=>value of what should be sent to a 3rd party API.
|
||||
*
|
||||
* @internal param array $params
|
||||
*/
|
||||
protected function set_body_param( $param ) {
|
||||
$this->body = Options::array_merge_recursive( $this->body, $param );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
if ( empty( $name ) || empty( $value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->set_header( $name, $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_header( $name, $value ) {
|
||||
|
||||
$process_value = function ( $value ) {
|
||||
// Remove HTML tags.
|
||||
$filtered = wp_strip_all_tags( $value, false );
|
||||
// Remove multi-lines/tabs.
|
||||
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
|
||||
// Remove whitespaces.
|
||||
$filtered = trim( $filtered );
|
||||
|
||||
// Remove octets.
|
||||
$found = false;
|
||||
while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
|
||||
$filtered = str_replace( $match[0], '', $filtered );
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( $found ) {
|
||||
// Strip out the whitespace that may now exist after removing the octets.
|
||||
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
};
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value = $process_value( $value );
|
||||
|
||||
$this->headers[ $name ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_body() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_body', $this->body );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_headers() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_headers', $this->headers );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
$params = Options::array_merge_recursive( $this->get_default_params(), array(
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => $this->get_body(),
|
||||
) );
|
||||
|
||||
$response = wp_safe_remote_post( $this->url, $params );
|
||||
|
||||
$this->process_response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* We might need to do something after the email was sent to the API.
|
||||
* In this method we preprocess the response from the API.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array|\WP_Error $response
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
// Save the error text.
|
||||
$errors = $response->get_error_messages();
|
||||
foreach ( $errors as $error ) {
|
||||
Debug::set( $error );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $response['body'] ) && $this->is_json( $response['body'] ) ) {
|
||||
$response['body'] = \json_decode( $response['body'] );
|
||||
}
|
||||
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default params, required for wp_safe_remote_post().
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_params() {
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_default_params', array(
|
||||
'timeout' => 15,
|
||||
'httpversion' => '1.1',
|
||||
'blocking' => true,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
|
||||
$is_sent = true;
|
||||
} else {
|
||||
$error = $this->get_response_error();
|
||||
|
||||
if ( ! empty( $error ) ) {
|
||||
Debug::set( $error );
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be overwritten when appropriate.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_php_compatible() {
|
||||
|
||||
$options = wp_mail_smtp()->get_providers()->get_options( $this->mailer );
|
||||
|
||||
return version_compare( phpversion(), $options->get_php_version(), '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the string is a JSON or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_json( $string ) {
|
||||
return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( json_last_error() === JSON_ERROR_NONE ) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is relevant to SMTP and Pepipost.
|
||||
* All other custom mailers should override it with own information.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
global $phpmailer;
|
||||
|
||||
$smtp_text = array();
|
||||
|
||||
// Mail mailer has nothing to return.
|
||||
if ( $this->options->is_mailer_smtp() ) {
|
||||
$smtp_text[] = '<strong>ErrorInfo:</strong> ' . make_clickable( wp_strip_all_tags( $phpmailer->ErrorInfo ) );
|
||||
$smtp_text[] = '<strong>Host:</strong> ' . $phpmailer->Host;
|
||||
$smtp_text[] = '<strong>Port:</strong> ' . $phpmailer->Port;
|
||||
$smtp_text[] = '<strong>SMTPSecure:</strong> ' . Debug::pvar( $phpmailer->SMTPSecure );
|
||||
$smtp_text[] = '<strong>SMTPAutoTLS:</strong> ' . Debug::pvar( $phpmailer->SMTPAutoTLS );
|
||||
$smtp_text[] = '<strong>SMTPAuth:</strong> ' . Debug::pvar( $phpmailer->SMTPAuth );
|
||||
if ( ! empty( $phpmailer->SMTPOptions ) ) {
|
||||
$smtp_text[] = '<strong>SMTPOptions:</strong> <code>' . json_encode( $phpmailer->SMTPOptions ) . '</code>';
|
||||
}
|
||||
}
|
||||
|
||||
$smtp_text[] = '<br><strong>Server:</strong>';
|
||||
$smtp_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
|
||||
if ( function_exists( 'apache_get_modules' ) ) {
|
||||
$modules = apache_get_modules();
|
||||
$smtp_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'selinux_is_enabled' ) ) {
|
||||
$smtp_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'grsecurity_is_enabled' ) ) {
|
||||
$smtp_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
|
||||
return implode( '<br>', $smtp_text );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface MailerInterface.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface MailerInterface {
|
||||
|
||||
/**
|
||||
* Send the email.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function send();
|
||||
|
||||
/**
|
||||
* Whether the email is sent or not.
|
||||
* We basically check the response code from a request to provider.
|
||||
* Might not be 100% correct, not guarantees that email is delivered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent();
|
||||
|
||||
/**
|
||||
* Whether the mailer supports the current PHP version or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_compatible();
|
||||
|
||||
/**
|
||||
* Get the email body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_body();
|
||||
|
||||
/**
|
||||
* Get the email headers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_headers();
|
||||
|
||||
/**
|
||||
* Get an array of all debug information relevant to the mailer.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_debug_info();
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer );
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mailgun;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.mailgun.net/v3/';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
/*
|
||||
* Append the url with a domain,
|
||||
* to avoid passing the domain name as a query parameter with all requests.
|
||||
*/
|
||||
$this->url .= sanitize_text_field( $this->options->get( $this->mailer, 'domain' ) . '/messages' );
|
||||
|
||||
$this->set_header( 'Authorization', 'Basic ' . base64_encode( 'api:' . $this->options->get( $this->mailer, 'api_key' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $name . ' <' . $email . '>',
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $email,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$default = array( 'to', 'cc', 'bcc' );
|
||||
|
||||
foreach ( $recipients as $kind => $emails ) {
|
||||
if (
|
||||
! in_array( $kind, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$data[] = $name . ' <' . $addr . '>';
|
||||
} else {
|
||||
$data[] = $addr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$kind => implode( ', ', $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
$default = array( 'text', 'html' );
|
||||
|
||||
foreach ( $content as $type => $mail ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $mail )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$type => $mail,
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$type = 'text';
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/html' ) {
|
||||
$type = 'html';
|
||||
}
|
||||
|
||||
if ( ! empty( $content ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$type => $content,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It's the last one, so we can modify the whole body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = '';
|
||||
$data = array();
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] );
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'content' => $file,
|
||||
'name' => $attachment[1],
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
|
||||
// First, generate a boundary for the multipart message.
|
||||
$boundary = base_convert( uniqid( 'boundary', true ), 10, 36 );
|
||||
|
||||
// Iterate through pre-built params and build a payload.
|
||||
foreach ( $this->body as $key => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $child_key => $child_value ) {
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
|
||||
$payload .= $child_value;
|
||||
$payload .= "\r\n";
|
||||
}
|
||||
} else {
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n";
|
||||
$payload .= $value;
|
||||
$payload .= "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Now iterate through our attachments, and add them too.
|
||||
foreach ( $data as $key => $attachment ) {
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="attachment[' . $key . ']"; filename="' . $attachment['name'] . '"' . "\r\n\r\n";
|
||||
$payload .= $attachment['content'];
|
||||
$payload .= "\r\n";
|
||||
}
|
||||
|
||||
$payload .= '--' . $boundary . '--';
|
||||
|
||||
// Redefine the body the "dirty way".
|
||||
$this->body = $payload;
|
||||
|
||||
$this->set_header( 'Content-Type', 'multipart/form-data; boundary=' . $boundary );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $reply_to as $key => $emails ) {
|
||||
if (
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addr = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$data[] = $name . ' <' . $addr . '>';
|
||||
} else {
|
||||
$data[] = $addr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'h:Reply-To' => implode( ',', $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_return_path( $email ) {
|
||||
|
||||
if (
|
||||
$this->options->get( 'mail', 'return_path' ) !== true ||
|
||||
! filter_var( $email, FILTER_VALIDATE_EMAIL )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'sender' => $email,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Mailgun-specific response with a helpful error.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error_text = array();
|
||||
|
||||
if ( ! empty( $body['message'] ) ) {
|
||||
if ( is_string( $body['message'] ) ) {
|
||||
$error_text[] = $body['message'];
|
||||
} else {
|
||||
$error_text[] = \json_encode( $body['message'] );
|
||||
}
|
||||
} elseif ( ! empty( $body[0] ) ) {
|
||||
if ( is_string( $body[0] ) ) {
|
||||
$error_text[] = $body[0];
|
||||
} else {
|
||||
$error_text[] = \json_encode( $body[0] );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mg_text = array();
|
||||
|
||||
$options = new \WPMailSMTP\Options();
|
||||
$mailgun = $options->get_group( 'mailgun' );
|
||||
|
||||
$mg_text[] = '<strong>Api Key / Domain:</strong> ' . ( ! empty( $mailgun['api_key'] ) && ! empty( $mailgun['domain'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $mg_text );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mailgun;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailgun constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/mailgun.png',
|
||||
'slug' => 'mailgun',
|
||||
'title' => esc_html__( 'Mailgun', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
|
||||
__( '%1$sMailgun%2$s is one of the leading transactional email services trusted by over 10,000 website and application developers. They provide users 10,000 free emails per month.<br><br>Read our %3$sMailgun documentation%4$s to learn how to configure Mailgun and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<a href="https://www.mailgun.com" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>',
|
||||
'<a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" 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-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'Private API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from Mailgun: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.mailgun.com/app/account/security" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Private API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Domain -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-domain" 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-<?php echo esc_attr( $this->get_slug() ); ?>-domain"><?php esc_html_e( 'Domain Name', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][domain]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'domain' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'domain' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain" spellcheck="false"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - Domain Name link. */
|
||||
esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.mailgun.com/app/domains" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Abstract Class ProviderAbstract to contain common providers functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class OptionsAbstract implements OptionsInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $logo_url = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $slug = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $php = WPMS_PHP_VER;
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* ProviderAbstract constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $params ) {
|
||||
|
||||
if (
|
||||
empty( $params['slug'] ) ||
|
||||
empty( $params['title'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->slug = sanitize_key( $params['slug'] );
|
||||
$this->title = sanitize_text_field( $params['title'] );
|
||||
|
||||
if ( ! empty( $params['description'] ) ) {
|
||||
$this->description = wp_kses( $params['description'],
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $params['php'] ) ) {
|
||||
$this->php = sanitize_text_field( $params['php'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['logo_url'] ) ) {
|
||||
$this->logo_url = esc_url_raw( $params['logo_url'] );
|
||||
}
|
||||
|
||||
$this->options = new Options();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_logo_url() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_slug() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_description() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_php_version() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- SMTP Host -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" 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-<?php echo esc_attr( $this->get_slug() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'host' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Port -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'port' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Encryption -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'none', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'ssl', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'tls', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PHPMailer SMTPAutoTLS -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][autotls]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'autotls' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'autotls' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'By default TLS encryption is automatically used if the server supports it, which is recommended. In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Authentication -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][auth]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'auth' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'auth' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Username -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'user' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="off"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Password -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
|
||||
<input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
|
||||
<?php else : ?>
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'pass' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="off"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - wp-config.php. */
|
||||
esc_html__( 'The password is stored in plain text. We highly recommend you setup your password in your WordPress configuration file for improved security; to do this add the lines below to your %s file.', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', true );
|
||||
define( 'WPMS_SMTP_PASS', 'your_password' );
|
||||
</pre>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we can use this provider based on the PHP version.
|
||||
* Valid for those, that use SDK.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_php_correct() {
|
||||
return version_compare( phpversion(), $this->php, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*/
|
||||
protected function display_php_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
|
||||
esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
|
||||
$this->title,
|
||||
$this->php,
|
||||
phpversion()
|
||||
)
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to the "Other SMTP" Mailer option.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface ProviderInterface, shared between all current and future providers.
|
||||
* Defines required methods across all providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface OptionsInterface {
|
||||
|
||||
/**
|
||||
* Get the mailer provider slug.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_slug();
|
||||
|
||||
/**
|
||||
* Get the mailer provider title (or name).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title();
|
||||
|
||||
/**
|
||||
* Get the mailer provider description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description();
|
||||
|
||||
/**
|
||||
* Get the mailer provider minimum PHP version.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_php_version();
|
||||
|
||||
/**
|
||||
* Get the mailer provider logo URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_logo_url();
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display_options();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Pepipost;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer inherits everything from parent abstract class.
|
||||
* This file is required for a proper work of Loader and \ReflectionClass.
|
||||
*
|
||||
* @package WPMailSMTP\Providers\Pepipost
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Pepipost;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Pepipost constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/pepipost.png',
|
||||
'slug' => 'pepipost',
|
||||
'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer inherits everything from parent abstract class.
|
||||
* This file is required for a proper work of Loader and \ReflectionClass.
|
||||
*
|
||||
* @package WPMailSMTP\Providers\SMTP
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class SMTP.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* SMTP constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/smtp.png',
|
||||
'slug' => 'smtp',
|
||||
'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
|
||||
/* translators: %1$s - opening link tag; %2$s - closing link tag. */
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
__( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our %1$sSMTP documentation%2$s.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendgrid;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.sendgrid.com/v3/mail/send';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default we are sending an array of data.
|
||||
* SendGrid requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$from['email'] = $email;
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$from['name'] = $name;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $from,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow for now only these recipient types.
|
||||
$default = array( 'to', 'cc', 'bcc' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $type ] = array();
|
||||
|
||||
// Iterate over all emails for each type.
|
||||
// There might be multiple cc/to/bcc emails.
|
||||
foreach ( $emails as $email ) {
|
||||
$holder = array();
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
array_push( $data[ $type ], $holder );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'personalizations' => array( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
$default = array( 'text', 'html' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $content as $type => $body ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $body )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content_type = 'text/plain';
|
||||
$content_value = $body;
|
||||
|
||||
if ( $type === 'html' ) {
|
||||
$content_type = 'text/html';
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'type' => $content_type,
|
||||
'value' => $content_value,
|
||||
);
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => $data,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$data['type'] = 'text/plain';
|
||||
$data['value'] = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/html' ) {
|
||||
$data['type'] = 'text/html';
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => array( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SendGrid accepts an array of files content in body, so we will include all files and send.
|
||||
* Doesn't handle exceeding the limits etc, as this is done and reported be SendGrid API.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'content' => base64_encode( $file ),
|
||||
'type' => $attachment[4],
|
||||
'filename' => $attachment[1],
|
||||
'disposition' => $attachment[6],
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'attachments' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $reply_to as $key => $emails ) {
|
||||
if (
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addr = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$data['name'] = $name;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'reply_to' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SendGrid doesn't support sender or return_path params.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $email
|
||||
*/
|
||||
public function set_return_path( $email ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a SendGrid-specific response with a helpful error.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error_text = array();
|
||||
|
||||
if ( ! empty( $body['errors'] ) ) {
|
||||
foreach ( $body['errors'] as $error ) {
|
||||
if ( property_exists( $error, 'message' ) ) {
|
||||
// Prepare additional information from SendGrid API.
|
||||
$extra = '';
|
||||
if ( property_exists( $error, 'field' ) && ! empty( $error->field ) ) {
|
||||
$extra .= $error->field . '; ';
|
||||
}
|
||||
if ( property_exists( $error, 'help' ) && ! empty( $error->help ) ) {
|
||||
$extra .= $error->help;
|
||||
}
|
||||
|
||||
// Assign both the main message and perhaps extra information, if exists.
|
||||
$error_text[] = $error->message . ( ! empty( $extra ) ? ' - ' . $extra : '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mg_text = array();
|
||||
|
||||
$options = new \WPMailSMTP\Options();
|
||||
$mailgun = $options->get_group( 'sendgrid' );
|
||||
|
||||
$mg_text[] = '<strong>Api Key:</strong> ' . ( ! empty( $mailgun['api_key'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $mg_text );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendgrid;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/sendgrid.png',
|
||||
'slug' => 'sendgrid',
|
||||
'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
|
||||
__( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per month.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>',
|
||||
'<a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" 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-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
<br/>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - SendGrid access level. */
|
||||
esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
|
||||
'<code>Mail Send</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
71
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Upgrade.php
Executable file
71
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/Upgrade.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Upgrade helps upgrade plugin options and similar tasks when the
|
||||
* occasion arises.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class Upgrade {
|
||||
|
||||
/**
|
||||
* Upgrade constructor.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$upgrades = $this->upgrades();
|
||||
|
||||
if ( empty( $upgrades ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run any available upgrades.
|
||||
foreach ( $upgrades as $upgrade ) {
|
||||
$this->{$upgrade}();
|
||||
}
|
||||
|
||||
// Update version post upgrade(s).
|
||||
update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we need to perform an upgrade.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function upgrades() {
|
||||
|
||||
$version = get_option( 'wp_mail_smtp_version' );
|
||||
$upgrades = array();
|
||||
|
||||
// Version 1.1.0 upgrade; prior to this the option was not available.
|
||||
if ( empty( $version ) ) {
|
||||
$upgrades[] = 'v110_upgrade';
|
||||
}
|
||||
|
||||
return $upgrades;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade routine for v1.1.0.
|
||||
*
|
||||
* Set SMTPAutoTLS to true.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public function v110_upgrade() {
|
||||
|
||||
$values = Options::init()->get_all();
|
||||
|
||||
// Enable SMTPAutoTLS option.
|
||||
$values['smtp']['autotls'] = true;
|
||||
|
||||
Options::init()->set( $values );
|
||||
}
|
||||
}
|
||||
140
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/WP.php
Executable file
140
backend/wordpress/wp-content/plugins/wp-mail-smtp/src/WP.php
Executable file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class WP provides WordPress shortcuts.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class WP {
|
||||
|
||||
/**
|
||||
* The "queue" of notices.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $admin_notices = array();
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_SUCCESS = 'notice-success';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_ERROR = 'notice-error';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_INFO = 'notice-info';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_WARNING = 'notice-warning';
|
||||
|
||||
/**
|
||||
* True is WP is processing an AJAX call.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_doing_ajax() {
|
||||
|
||||
if ( function_exists( 'wp_doing_ajax' ) ) {
|
||||
return wp_doing_ajax();
|
||||
}
|
||||
|
||||
return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
|
||||
}
|
||||
|
||||
/**
|
||||
* True if I am in the Admin Panel, not doing AJAX.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function in_wp_admin() {
|
||||
return ( is_admin() && ! self::is_doing_ajax() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice to the "queue of notices".
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $message Message text (HTML is OK).
|
||||
* @param string $class Display class (severity).
|
||||
*/
|
||||
public static function add_admin_notice( $message, $class = self::ADMIN_NOTICE_INFO ) {
|
||||
|
||||
self::$admin_notices[] = array(
|
||||
'message' => $message,
|
||||
'class' => $class,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display all notices.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function display_admin_notices() {
|
||||
|
||||
foreach ( (array) self::$admin_notices as $notice ) : ?>
|
||||
|
||||
<div id="message" class="<?php echo esc_attr( $notice['class'] ); ?> notice is-dismissible">
|
||||
<p>
|
||||
<?php echo $notice['message']; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether WP_DEBUG is active.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_debug() {
|
||||
return defined( 'WP_DEBUG' ) && WP_DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to global $wpdb.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \wpdb
|
||||
*/
|
||||
public static function wpdb() {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
return $wpdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the postfix for assets files - ".min" or empty.
|
||||
* ".min" if in production mode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function asset_min() {
|
||||
|
||||
$min = '.min';
|
||||
|
||||
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
|
||||
$min = '';
|
||||
}
|
||||
|
||||
return $min;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user