rebase from live enviornment
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace WPMailSMTP\Admin;
|
||||
|
||||
use Plugin_Upgrader;
|
||||
use WPMailSMTP\Admin\Pages\TestTab;
|
||||
use WPMailSMTP\Connect;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
@@ -81,7 +82,7 @@ class SetupWizard {
|
||||
isset( $_GET['page'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
Area::SLUG . '-setup-wizard' === $_GET['page'] && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$this->should_setup_wizard_load() &&
|
||||
current_user_can( 'manage_options' )
|
||||
current_user_can( wp_mail_smtp()->get_capability_manage_options() )
|
||||
)
|
||||
) {
|
||||
return;
|
||||
@@ -97,6 +98,10 @@ class SetupWizard {
|
||||
// Remove an action in the Gutenberg plugin ( not core Gutenberg ) which throws an error.
|
||||
remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
|
||||
|
||||
// Remove hooks for deprecated functions in WordPress 6.4.0.
|
||||
remove_action( 'admin_print_styles', 'print_emoji_styles' );
|
||||
remove_action( 'admin_head', 'wp_admin_bar_header' );
|
||||
|
||||
$this->load_setup_wizard();
|
||||
}
|
||||
|
||||
@@ -155,7 +160,7 @@ class SetupWizard {
|
||||
return;
|
||||
}
|
||||
|
||||
add_submenu_page( '', '', '', 'manage_options', Area::SLUG . '-setup-wizard', '' );
|
||||
add_submenu_page( '', '', '', wp_mail_smtp()->get_capability_manage_options(), Area::SLUG . '-setup-wizard', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -543,7 +548,7 @@ class SetupWizard {
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error( esc_html__( 'You don\'t have permission to change options for this WP site!', 'wp-mail-smtp' ) );
|
||||
}
|
||||
|
||||
@@ -561,7 +566,7 @@ class SetupWizard {
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error( esc_html__( 'You don\'t have permission to change options for this WP site!', 'wp-mail-smtp' ) );
|
||||
}
|
||||
|
||||
@@ -583,7 +588,7 @@ class SetupWizard {
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
@@ -625,7 +630,7 @@ class SetupWizard {
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error( esc_html__( 'You don\'t have permission to change options for this WP site!', 'wp-mail-smtp' ) );
|
||||
}
|
||||
|
||||
@@ -690,6 +695,7 @@ class SetupWizard {
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 3.10.0 Supply WPMS_AMAZONSES_DISPLAY_IDENTITIES constant value to control display of Amazon SES identity list.
|
||||
* @since 3.11.0 Removed WPMS_AMAZONSES_DISPLAY_IDENTITIES constant handling.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -710,10 +716,6 @@ class SetupWizard {
|
||||
if ( $provider->get_slug() === 'gmail' ) {
|
||||
$data['gmail']['redirect_uri'] = \WPMailSMTP\Providers\Gmail\Auth::get_oauth_redirect_url();
|
||||
}
|
||||
|
||||
if ( $provider->get_slug() === 'amazonses' ) {
|
||||
$data['amazonses']['display_identities'] = ! defined( 'WPMS_AMAZONSES_DISPLAY_IDENTITIES' ) || WPMS_AMAZONSES_DISPLAY_IDENTITIES === true;
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_admin_setup_wizard_prepare_mailer_options', $data );
|
||||
@@ -728,7 +730,7 @@ class SetupWizard {
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
@@ -738,7 +740,7 @@ class SetupWizard {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$settings = isset( $_POST['settings'] ) ? wp_slash( json_decode( wp_unslash( $_POST['settings'] ), true ) ) : [];
|
||||
|
||||
if ( empty( $mailer ) || empty( $settings ) ) {
|
||||
if ( empty( $mailer ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
@@ -749,7 +751,7 @@ class SetupWizard {
|
||||
|
||||
switch ( $mailer ) {
|
||||
case 'gmail':
|
||||
$auth = new \WPMailSMTP\Providers\Gmail\Auth();
|
||||
$auth = wp_mail_smtp()->get_providers()->get_auth( 'gmail' );
|
||||
|
||||
if ( $auth->is_clients_saved() && $auth->is_auth_required() ) {
|
||||
$data['oauth_url'] = $auth->get_auth_url();
|
||||
@@ -771,7 +773,7 @@ class SetupWizard {
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
@@ -784,20 +786,11 @@ class SetupWizard {
|
||||
|
||||
switch ( $mailer ) {
|
||||
case 'gmail':
|
||||
$auth = new \WPMailSMTP\Providers\Gmail\Auth();
|
||||
$auth = wp_mail_smtp()->get_providers()->get_auth( 'gmail' );
|
||||
|
||||
if ( $auth->is_clients_saved() && ! $auth->is_auth_required() ) {
|
||||
$user_info = $auth->get_user_info();
|
||||
$data['connected_email'] = $user_info['email'];
|
||||
$data['possible_send_from_addresses'] = array_map(
|
||||
function( $value ) {
|
||||
return [
|
||||
'value' => $value,
|
||||
'label' => $value,
|
||||
];
|
||||
},
|
||||
$auth->get_user_possible_send_from_addresses()
|
||||
);
|
||||
$user_info = $auth->get_user_info();
|
||||
$data['connected_email'] = $user_info['email'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -810,11 +803,11 @@ class SetupWizard {
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function remove_oauth_connection() {
|
||||
public function remove_oauth_connection() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
|
||||
check_ajax_referer( 'wpms-admin-nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
@@ -827,10 +820,21 @@ class SetupWizard {
|
||||
$options = Options::init();
|
||||
$old_opt = $options->get_all_raw();
|
||||
|
||||
foreach ( $old_opt[ $mailer ] as $key => $value ) {
|
||||
// Unset everything except Client ID, Client Secret and Domain (for Zoho).
|
||||
if ( ! in_array( $key, array( 'domain', 'client_id', 'client_secret' ), true ) ) {
|
||||
unset( $old_opt[ $mailer ][ $key ] );
|
||||
/*
|
||||
* Since Gmail mailer uses the same settings array for both the custom app and One-Click Setup,
|
||||
* we need to make sure we don't remove the wrong settings.
|
||||
*/
|
||||
if ( $mailer === 'gmail' ) {
|
||||
unset( $old_opt[ $mailer ]['access_token'] );
|
||||
unset( $old_opt[ $mailer ]['refresh_token'] );
|
||||
unset( $old_opt[ $mailer ]['user_details'] );
|
||||
unset( $old_opt[ $mailer ]['auth_code'] );
|
||||
} else {
|
||||
foreach ( $old_opt[ $mailer ] as $key => $value ) {
|
||||
// Unset everything except Client ID, Client Secret and Domain (for Zoho).
|
||||
if ( ! in_array( $key, [ 'domain', 'client_id', 'client_secret' ], true ) ) {
|
||||
unset( $old_opt[ $mailer ][ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -868,8 +872,16 @@ class SetupWizard {
|
||||
wp_send_json_error( esc_html__( 'Could not install the plugin. Plugin is not whitelisted.', 'wp-mail-smtp' ) );
|
||||
}
|
||||
|
||||
$url = esc_url_raw( WP::admin_url( 'admin.php?page=' . Area::SLUG . '-setup-wizard' ) );
|
||||
$url = esc_url_raw( WP::admin_url( 'admin.php?page=' . Area::SLUG . '-setup-wizard' ) );
|
||||
|
||||
/*
|
||||
* The `request_filesystem_credentials` function will output a credentials form in case of failure.
|
||||
* We don't want that, since it will break AJAX response. So just hide output with a buffer.
|
||||
*/
|
||||
ob_start();
|
||||
// phpcs:ignore WPForms.Formatting.EmptyLineAfterAssigmentVariables.AddEmptyLine
|
||||
$creds = request_filesystem_credentials( $url, '', false, false, null );
|
||||
ob_end_clean();
|
||||
|
||||
// Check for file system permissions.
|
||||
if ( false === $creds ) {
|
||||
@@ -883,8 +895,11 @@ class SetupWizard {
|
||||
// Do not allow WordPress to search/download translations, as this will break JS output.
|
||||
remove_action( 'upgrader_process_complete', [ 'Language_Pack_Upgrader', 'async_upgrade' ], 20 );
|
||||
|
||||
// Import the plugin upgrader.
|
||||
Helpers::include_plugin_upgrader();
|
||||
|
||||
// Create the plugin upgrader with our custom skin.
|
||||
$installer = new PluginsInstallUpgrader( new PluginsInstallSkin() );
|
||||
$installer = new Plugin_Upgrader( new PluginsInstallSkin() );
|
||||
|
||||
// Error check.
|
||||
if ( ! method_exists( $installer, 'install' ) || empty( $slug ) ) {
|
||||
|
||||
Reference in New Issue
Block a user