403 ] ); } $settings = get_option( 'aio_options', [] ); $client_id = $settings['txtOAuthClientId'] ?? ''; $client_secret = $settings['txtOAuthClientSecret'] ?? ''; if ( ! empty( $client_secret ) ) { $client_secret = AIO_Crypto::decrypt( $client_secret ); } $redirect_uri = admin_url( 'admin.php?page=aio-settings&tab=smtp' ); if ( empty( $client_id ) || empty( $client_secret ) ) { return; } $token_url = $provider === 'google' ? 'https://oauth2.googleapis.com/token' : 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; $args = [ 'method' => 'POST', 'timeout' => 15, 'body' => [ 'client_id' => $client_id, 'client_secret' => $client_secret, 'code' => $code, 'redirect_uri' => $redirect_uri, 'grant_type' => 'authorization_code', ], ]; $response = wp_safe_remote_post( $token_url, $args ); if ( ! is_wp_error( $response ) ) { $body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $body['refresh_token'] ) ) { $settings[ 'optOAuthRefreshToken_' . $provider ] = AIO_Crypto::encrypt( $body['refresh_token'] ); update_option( 'aio_options', $settings ); wp_safe_redirect( $redirect_uri ); exit; } } } public function w2wSmtpCheckHandler(){ check_ajax_referer( 'aio-smtp-check-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You do not have sufficient permissions to access this page.', 'aio-tools' ) ); } $recipient = sanitize_email($_POST['your_email']); if ( ! is_email( $recipient ) ) { wp_send_json_error( __( 'Invalid email address.', 'aio-tools' ) ); } $subject = __('AIO Tool: SMTP Test Connection', 'aio-tools' ); $headers = array('Content-Type: text/html; charset=UTF-8'); $message = '
'; // Inject PHPMailer debug interceptor add_action( 'phpmailer_init', function( $phpmailer ) { $phpmailer->SMTPDebug = 2; // Enable verbose debug output $phpmailer->Debugoutput = 'html'; }); ob_start(); try { $result = wp_mail($recipient, $subject, $message, $headers); $debug_log = ob_get_clean(); $debug_log = wp_strip_all_tags(str_replace("