sd_code = md5( uniqid( 'swpsmtp', true ) ); set_transient( 'easy_wp_smtp_sd_code', $this->sd_code, 12 * 60 * 60 ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); } public function admin_enqueue_scripts( $hook ) { // Load only on ?page=swpsmtp_settings if ( 'settings_page_swpsmtp_settings' !== $hook ) { return; } $core = EasyWPSMTP::get_instance(); $plugin_data = get_file_data( $core->plugin_file, array( 'Version' => 'Version' ), false ); $plugin_version = $plugin_data['Version']; wp_enqueue_style( 'swpsmtp_admin_css', plugins_url( 'css/style.css', __FILE__ ), array(), '1.0' ); wp_register_script( 'swpsmtp_admin_js', plugins_url( 'js/script.js', __FILE__ ), array(), $plugin_version, true ); $params = array( 'sd_redir_url' => get_admin_url(), 'sd_code' => $this->sd_code, 'clear_log_nonce' => wp_create_nonce( 'easy-wp-smtp-clear-log' ), 'str' => array( 'clear_log' => __( 'Are you sure want to clear log?', 'easy-wp-smtp' ), 'log_cleared' => __( 'Log cleared.', 'easy-wp-smtp' ), 'error_occured' => __( 'Error occurred:', 'easy-wp-smtp' ), 'sending' => __( 'Sending...', 'easy-wp-smtp' ), 'confirm_self_destruct' => __( 'Are you sure you want to delete ALL your settings and deactive plugin?', 'easy-wp-smtp' ), 'self_destruct_completed' => __( 'All settings have been deleted and plugin is deactivated.', 'easy-wp-smtp' ), ), ); wp_localize_script( 'swpsmtp_admin_js', 'easywpsmtp', $params ); wp_enqueue_script( 'swpsmtp_admin_js' ); } public function admin_menu() { add_options_page( __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), 'manage_options', 'swpsmtp_settings', 'swpsmtp_settings' ); } } new EasyWPSMTP_Admin(); /** * Renders the admin settings menu of the plugin. * @return void */ function swpsmtp_settings() { $easy_wp_smtp = EasyWPSMTP::get_instance(); $enc_req_met = true; $enc_req_err = ''; //check if OpenSSL PHP extension is loaded and display warning if it's not if ( ! extension_loaded( 'openssl' ) ) { $class = 'notice notice-warning'; $message = __( "PHP OpenSSL extension is not installed on the server. It's required by Easy WP SMTP plugin to operate properly. Please contact your server administrator or hosting provider and ask them to install it.", 'easy-wp-smtp' ); printf( '

%2$s

', esc_attr( $class ), esc_html( $message ) ); //also show encryption error message $enc_req_err .= __( 'PHP OpenSSL extension is not installed on the server. It is required for encryption to work properly. Please contact your server administrator or hosting provider and ask them to install it.', 'easy-wp-smtp' ) . '
'; $enc_req_met = false; } //check if server meets encryption requirements if ( version_compare( PHP_VERSION, '5.3.0' ) < 0 ) { $enc_req_err = ! empty( $enc_req_err ) ? $enc_req_err .= '
' : ''; // translators: %s is PHP version $enc_req_err .= sprintf( __( 'Your PHP version is %s, encryption function requires PHP version 5.3.0 or higher.', 'easy-wp-smtp' ), PHP_VERSION ); $enc_req_met = false; } echo '
'; echo '

' . esc_html( __( 'Easy WP SMTP Settings', 'easy-wp-smtp' ) ) . '

'; echo '
'; $message = ''; $error = ''; $swpsmtp_options = get_option( 'swpsmtp_options' ); $smtp_test_mail = get_option( 'smtp_test_mail' ); $gag_password = '#easywpsmtpgagpass#'; if ( empty( $smtp_test_mail ) ) { $smtp_test_mail = array( 'swpsmtp_to' => '', 'swpsmtp_subject' => '', 'swpsmtp_message' => '', ); } if ( isset( $_POST['swpsmtp_form_submit'] ) ) { // check nounce if ( ! check_admin_referer( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ) ) { $error .= ' ' . __( 'Nonce check failed.', 'easy-wp-smtp' ); } /* Update settings */ $swpsmtp_options['from_name_field'] = isset( $_POST['swpsmtp_from_name'] ) ? sanitize_text_field( wp_unslash( $_POST['swpsmtp_from_name'] ) ) : ''; $swpsmtp_options['force_from_name_replace'] = isset( $_POST['swpsmtp_force_from_name_replace'] ) ? 1 : false; $swpsmtp_options['sub_mode'] = isset( $_POST['swpsmtp_sub_mode'] ) ? 1 : false; if ( isset( $_POST['swpsmtp_from_email'] ) ) { if ( is_email( $_POST['swpsmtp_from_email'] ) ) { $swpsmtp_options['from_email_field'] = sanitize_email( $_POST['swpsmtp_from_email'] ); } else { $error .= ' ' . __( "Please enter a valid email address in the 'FROM' field.", 'easy-wp-smtp' ); } } if ( isset( $_POST['swpsmtp_reply_to_email'] ) ) { $swpsmtp_options['reply_to_email'] = sanitize_email( $_POST['swpsmtp_reply_to_email'] ); } if ( isset( $_POST['swpsmtp_email_ignore_list'] ) ) { $swpsmtp_options['email_ignore_list'] = sanitize_text_field( $_POST['swpsmtp_email_ignore_list'] ); } $swpsmtp_options['smtp_settings']['host'] = stripslashes( $_POST['swpsmtp_smtp_host'] ); $swpsmtp_options['smtp_settings']['type_encryption'] = ( isset( $_POST['swpsmtp_smtp_type_encryption'] ) ) ? sanitize_text_field( $_POST['swpsmtp_smtp_type_encryption'] ) : 'none'; $swpsmtp_options['smtp_settings']['autentication'] = ( isset( $_POST['swpsmtp_smtp_autentication'] ) ) ? sanitize_text_field( $_POST['swpsmtp_smtp_autentication'] ) : 'yes'; $swpsmtp_options['smtp_settings']['username'] = stripslashes( $_POST['swpsmtp_smtp_username'] ); $swpsmtp_options['smtp_settings']['enable_debug'] = isset( $_POST['swpsmtp_enable_debug'] ) ? 1 : false; $swpsmtp_options['smtp_settings']['insecure_ssl'] = isset( $_POST['swpsmtp_insecure_ssl'] ) ? 1 : false; $swpsmtp_options['smtp_settings']['encrypt_pass'] = isset( $_POST['swpsmtp_encrypt_pass'] ) ? 1 : false; $smtp_password = $_POST['swpsmtp_smtp_password']; if ( $smtp_password !== $gag_password ) { $swpsmtp_options['smtp_settings']['password'] = $easy_wp_smtp->encrypt_password( $smtp_password ); } if ( $swpsmtp_options['smtp_settings']['encrypt_pass'] && ! get_option( 'swpsmtp_pass_encrypted', false ) ) { update_option( 'swpsmtp_options', $swpsmtp_options ); $pass = $easy_wp_smtp->get_password(); $swpsmtp_options['smtp_settings']['password'] = $easy_wp_smtp->encrypt_password( $pass ); update_option( 'swpsmtp_options', $swpsmtp_options ); } $swpsmtp_options['enable_domain_check'] = isset( $_POST['swpsmtp_enable_domain_check'] ) ? 1 : false; if ( isset( $_POST['swpsmtp_allowed_domains'] ) ) { $swpsmtp_options['block_all_emails'] = isset( $_POST['swpsmtp_block_all_emails'] ) ? 1 : false; $swpsmtp_options['allowed_domains'] = base64_encode( sanitize_text_field( $_POST['swpsmtp_allowed_domains'] ) ); //phpcs:ignore } elseif ( ! isset( $swpsmtp_options['allowed_domains'] ) ) { $swpsmtp_options['allowed_domains'] = ''; } /* Check value from "SMTP port" option */ if ( isset( $_POST['swpsmtp_smtp_port'] ) ) { if ( empty( $_POST['swpsmtp_smtp_port'] ) || 1 > intval( $_POST['swpsmtp_smtp_port'] ) || ( ! preg_match( '/^\d+$/', $_POST['swpsmtp_smtp_port'] ) ) ) { $swpsmtp_options['smtp_settings']['port'] = '25'; $error .= ' ' . __( "Please enter a valid port in the 'SMTP Port' field.", 'easy-wp-smtp' ); } else { $swpsmtp_options['smtp_settings']['port'] = sanitize_text_field( $_POST['swpsmtp_smtp_port'] ); } } /* Update settings in the database */ if ( empty( $error ) ) { update_option( 'swpsmtp_options', $swpsmtp_options ); $message .= __( 'Settings saved.', 'easy-wp-smtp' ); } else { $error .= ' ' . __( 'Settings are not saved.', 'easy-wp-smtp' ); } } /* Send test letter */ $swpsmtp_to = ''; if ( isset( $_POST['swpsmtp_test_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'swpsmtp_test_nonce_name' ) ) { if ( isset( $_POST['swpsmtp_to'] ) ) { $to_email = sanitize_text_field( $_POST['swpsmtp_to'] ); if ( is_email( $to_email ) ) { $swpsmtp_to = $to_email; } else { $error .= __( 'Please enter a valid email address in the recipient email field.', 'easy-wp-smtp' ); } } $swpsmtp_subject = isset( $_POST['swpsmtp_subject'] ) ? sanitize_text_field( $_POST['swpsmtp_subject'] ) : ''; $swpsmtp_message = isset( $_POST['swpsmtp_message'] ) ? EasyWPSMTP_Utils::sanitize_textarea( $_POST['swpsmtp_message'] ) : ''; //Save the test mail details so it doesn't need to be filled in everytime. $smtp_test_mail['swpsmtp_to'] = $swpsmtp_to; $smtp_test_mail['swpsmtp_subject'] = $swpsmtp_subject; $smtp_test_mail['swpsmtp_message'] = $swpsmtp_message; update_option( 'smtp_test_mail', $smtp_test_mail ); if ( ! empty( $swpsmtp_to ) ) { $test_res = $easy_wp_smtp->test_mail( $swpsmtp_to, $swpsmtp_subject, $swpsmtp_message ); } } ?>
>





' />


' />


' />



/>

/>

/>

/>

/>

|

' . esc_html__( 'Following error occurred when attempting to send test email:', 'easy-wp-smtp' ) . '
' . esc_html( $test_res['error'] ); } else { $errmsg_class = ' msg-success'; $errmsg_text = '' . esc_html__( 'Test email was successfully sent. No errors occurred during the process.', 'easy-wp-smtp' ) . ''; } ?>


:

:

:

Easy WP SMTP', 'easy-wp-smtp' ) ), 'Easy WP SMTP' ); ?>

%s', esc_html( __( 'Support Forum', 'easy-wp-smtp' ) ) ) ); ?>

%s', esc_html( __( 'rating', 'easy-wp-smtp' ) ) ) ); ?>
'; // echo '
'; // }