settings menu in order to send email using Easy WP SMTP plugin.', 'easy-wp-smtp' ), esc_url( $settings_url ) ); ?>
'',
'from_name_field' => '',
'force_from_name_replace' => 0,
'smtp_settings' => array(
'host' => 'smtp.example.com',
'type_encryption' => 'none',
'port' => 25,
'autentication' => 'yes',
'username' => '',
'password' => ''
)
);
/* install the default plugin options if needed */
$swpsmtp_options = get_option( 'swpsmtp_options' );
if ( ! $swpsmtp_options ) {
$swpsmtp_options = $swpsmtp_options_default;
}
$swpsmtp_options = array_merge( $swpsmtp_options_default, $swpsmtp_options );
update_option( 'swpsmtp_options', $swpsmtp_options, 'yes' );
//add current domain to allowed domains list
if ( ! isset( $swpsmtp_options[ 'allowed_domains' ] ) ) {
$domain = parse_url( get_site_url(), PHP_URL_HOST );
if ( $domain ) {
$swpsmtp_options[ 'allowed_domains' ] = base64_encode( $domain );
update_option( 'swpsmtp_options', $swpsmtp_options );
}
} else { // let's check if existing value should be base64 encoded
if ( ! empty( $swpsmtp_options[ 'allowed_domains' ] ) ) {
if ( base64_decode_maybe( $swpsmtp_options[ 'allowed_domains' ] ) === $swpsmtp_options[ 'allowed_domains' ] ) {
$swpsmtp_options[ 'allowed_domains' ] = base64_encode( $swpsmtp_options[ 'allowed_domains' ] );
update_option( 'swpsmtp_options', $swpsmtp_options );
}
}
}
// Encrypt password if needed
if ( ! get_option( 'swpsmtp_pass_encrypted' ) ) {
if ( extension_loaded( 'openssl' ) ) {
if ( $swpsmtp_options[ 'smtp_settings' ][ 'password' ] !== '' ) {
$swpsmtp_options[ 'smtp_settings' ][ 'password' ] = swpsmtp_encrypt_password( swpsmtp_get_password() );
update_option( 'swpsmtp_options', $swpsmtp_options );
}
}
}
}
function swpsmtp_is_domain_blocked() {
$swpsmtp_options = get_option( 'swpsmtp_options' );
//check if Domain Check enabled
if ( isset( $swpsmtp_options[ 'enable_domain_check' ] ) && $swpsmtp_options[ 'enable_domain_check' ] ) {
//check if allowed domains list is not blank
if ( isset( $swpsmtp_options[ 'allowed_domains' ] ) && ! empty( $swpsmtp_options[ 'allowed_domains' ] ) ) {
$swpsmtp_options[ 'allowed_domains' ] = base64_decode_maybe( $swpsmtp_options[ 'allowed_domains' ] );
//let's see if we have one domain or coma-separated domains
$domains_arr = explode( ',', $swpsmtp_options[ 'allowed_domains' ] );
if ( is_array( $domains_arr ) && ! empty( $domains_arr ) ) {
//we have coma-separated list
} else {
//it's single domain
unset( $domains_arr );
$domains_arr = array( $swpsmtp_options[ 'allowed_domains' ] );
}
$site_domain = parse_url( get_site_url(), PHP_URL_HOST );
$match_found = false;
foreach ( $domains_arr as $domain ) {
if ( strtolower( trim( $domain ) ) === strtolower( trim( $site_domain ) ) ) {
$match_found = true;
break;
}
}
if ( ! $match_found ) {
return $site_domain;
}
}
}
return false;
}
function swpsmtp_wp_mail( $args ) {
$swpsmtp_options = get_option( 'swpsmtp_options' );
$domain = swpsmtp_is_domain_blocked();
if ( $domain !== false && (isset( $swpsmtp_options[ 'block_all_emails' ] ) && $swpsmtp_options[ 'block_all_emails' ] === 1) ) {
swpsmtp_write_to_log(
"\r\n------------------------------------------------------------------------------------------------------\r\n" .
"Domain check failed: website domain (" . $domain . ") is not in allowed domains list.\r\n" .
"Following email not sent (block all emails option is enabled):\r\n" .
"To: " . $args[ 'to' ] . "; Subject: " . $args[ 'subject' ] . "\r\n" .
"------------------------------------------------------------------------------------------------------\r\n\r\n" );
}
return $args;
}
class swpsmtp_gag_mailer extends stdClass {
public function Send() {
return true;
}
}
/**
* Add all hooks
*/
add_filter( 'plugin_action_links', 'swpsmtp_plugin_action_links', 10, 2 );
add_action( 'plugins_loaded', 'swpsmtp_plugins_loaded_handler' );
add_filter( 'plugin_row_meta', 'swpsmtp_register_plugin_links', 10, 2 );
add_filter( 'wp_mail', 'swpsmtp_wp_mail', 2147483647 );
add_action( 'phpmailer_init', 'swpsmtp_init_smtp', 999 );
add_action( 'admin_menu', 'swpsmtp_admin_default_setup' );
add_action( 'admin_init', 'swpsmtp_admin_init' );
add_action( 'admin_enqueue_scripts', 'swpsmtp_admin_head' );
add_action( 'admin_notices', 'swpsmtp_admin_notice' );
register_activation_hook( __FILE__, 'swpsmtp_activate' );
register_uninstall_hook( plugin_basename( __FILE__ ), 'swpsmtp_send_uninstall' );