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' ) );
}
function admin_enqueue_scripts( $hook ) {
// Load only on ?page=swpsmtp_settings
if ( $hook != 'settings_page_swpsmtp_settings' ) {
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__ ) );
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,
'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' );
}
function admin_menu() {
//add_submenu_page( 'options-general.php', __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), $capabilities, 'swpsmtp_settings', 'swpsmtp_settings' );
add_options_page( __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), 'manage_options', 'swpsmtp_settings', 'swpsmtp_settings' );
}
}
new EasyWPSMTMAdmin();
/**
* Sanitizes textarea. Tries to use wp sanitize_textarea_field() function. If that's not available, uses its own methods
* @return string
*/
function swpsmtp_sanitize_textarea( $str ) {
if ( function_exists( 'sanitize_textarea_field' ) ) {
return sanitize_textarea_field( $str );
}
$filtered = wp_check_invalid_utf8( $str );
if ( strpos( $filtered, '<' ) !== false ) {
$filtered = wp_pre_kses_less_than( $filtered );
// This will strip extra whitespace for us.
$filtered = wp_strip_all_tags( $filtered, false );
// Use html entities in a special case to make sure no later
// newline stripping stage could lead to a functional tag
$filtered = str_replace( "<\n", "<\n", $filtered );
}
$filtered = trim( $filtered );
$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;
}
/**
* Renders the admin settings menu of the plugin.
* @return void
*/
function swpsmtp_settings() {
$EasyWPSMTP = 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 .= ' ' : '';
$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 '