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 '