| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
class Yeemail_New_User_Email{ |
| 4 |
function __construct(){ |
| 5 |
//New account |
| 6 |
add_filter( 'wp_new_user_notification_email', array($this,"wp_new_user_notification_email"),10,3 ); |
| 7 |
//New account to admin |
| 8 |
add_filter( 'wp_new_user_notification_email_admin', array($this,"wp_new_user_notification_email_admin"),10,3 ); |
| 9 |
// Password Changed |
| 10 |
add_filter( 'password_change_email', array($this,"password_change_email"),10,3 ); |
| 11 |
// Password Changed to admin |
| 12 |
add_filter( 'wp_password_change_notification_email', array($this,"wp_password_change_notification_email"),10,3 ); |
| 13 |
//Reset Password |
| 14 |
add_filter( 'retrieve_password_message', array($this,"retrieve_password_notification_email"),10,4 ); |
| 15 |
add_filter( 'retrieve_password_title', array($this,"retrieve_password_title"),10,3 ); |
| 16 |
//Reset Password admin |
| 17 |
//add_filter( 'new_admin_email_content', array($this,"new_admin_email_content"),10,3 ); |
| 18 |
//comment |
| 19 |
add_filter( 'comment_notification_text', array($this,"comment_notification_text"),10,2 ); |
| 20 |
add_filter( 'comment_notification_subject', array($this,"comment_notification_subject"),10,2 ); |
| 21 |
add_filter( 'comment_notification_notify_author', array($this,"comment_notification_notify_author"),10,2 ); |
| 22 |
} |
| 23 |
function comment_notification_notify_author($notify_message,$comment_id ){ |
| 24 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type("comment_notification"); |
| 25 |
if( $template_id && $template_id > 0) { |
| 26 |
return true; |
| 27 |
} |
| 28 |
return $notify_message; |
| 29 |
} |
| 30 |
function comment_notification_text($notify_message,$comment_id ){ |
| 31 |
$new_commnet_content = $notify_message; |
| 32 |
$comment = get_comment( $comment_id ); |
| 33 |
switch ( $comment->comment_type ) { |
| 34 |
case 'trackback': |
| 35 |
case 'pingback': |
| 36 |
break; |
| 37 |
default: |
| 38 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type("comment_notification"); |
| 39 |
if( $template_id && $template_id > 0) { |
| 40 |
$new_content_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"content_no_shortcode")); |
| 41 |
$data_key = array( |
| 42 |
"[yeemail_post_title]", |
| 43 |
"[yeemail_comment_author]", |
| 44 |
"[yeemail_comment_author_ip]", |
| 45 |
"[yeemail_comment_author_domain]", |
| 46 |
"[yeemail_comment_author_email]", |
| 47 |
"[yeemail_comment_author_url]", |
| 48 |
"[yeemail_comment_content]", |
| 49 |
"[yeemail_comment_link_url]", |
| 50 |
"[yeemail_comment_link]" |
| 51 |
); |
| 52 |
$post = get_post( $comment->comment_post_ID ); |
| 53 |
$author = get_userdata( $post->post_author ); |
| 54 |
$post_title = $post->post_title; |
| 55 |
$comment_author = $comment->comment_author; |
| 56 |
$comment_author_ip = $comment->comment_author_IP; |
| 57 |
$comment_author_domain = ''; |
| 58 |
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { |
| 59 |
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); |
| 60 |
} |
| 61 |
$comment_author_email = $comment->comment_author_email; |
| 62 |
$comment_author_url = $comment->comment_author_email; |
| 63 |
$comment_content = wp_specialchars_decode( $comment->comment_content ); |
| 64 |
$comment_link_url = get_permalink( $comment->comment_post_ID );; |
| 65 |
$comment_link = get_comment_link( $comment ); |
| 66 |
$data_value = array($post_title,$comment_author,$comment_author_ip,$comment_author_domain,$comment_author_email,$comment_author_url,$comment_content,$comment_link_url,$comment_link); |
| 67 |
$new_content_email = str_replace($data_key,$data_value,$new_content_email); |
| 68 |
$new_commnet_content = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"full","html"=>$new_content_email)); |
| 69 |
} |
| 70 |
break; |
| 71 |
} |
| 72 |
return $new_commnet_content; |
| 73 |
} |
| 74 |
function comment_notification_subject($subject,$comment_id ){ |
| 75 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type("comment_notification"); |
| 76 |
if( $template_id && $template_id > 0) { |
| 77 |
$custom_subject = get_post_meta( $template_id,'_yeemail_custom_subject',true); |
| 78 |
if($custom_subject != ""){ |
| 79 |
$subject = $custom_subject; |
| 80 |
} |
| 81 |
} |
| 82 |
return $subject; |
| 83 |
} |
| 84 |
function user_notification_email($type,$wp_new_user_notification_email, $user_data, $blogname ){ |
| 85 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type($type); |
| 86 |
if( $template_id && $template_id > 0) { |
| 87 |
$user_login = $user_data->user_login; |
| 88 |
$user_email = $user_data->user_email; |
| 89 |
$user_name = $user_login; |
| 90 |
$display_name = $user_data->display_name; |
| 91 |
$user_url = $user_data->user_url; |
| 92 |
$key = get_password_reset_key( $user_data ); |
| 93 |
$set_password_url = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_data->user_login ), 'login' ); |
| 94 |
$data_key = array("[yeemail_user_name]","[yeemail_user_login]","[yeemail_user_email]","[yeemail_set_password_url]","[yeemail_user_display_name]","[yeemail_user_url]"); |
| 95 |
$data_value = array($user_name,$user_login,$user_email,$set_password_url,$display_name,$user_url); |
| 96 |
$new_content_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"content_no_shortcode")); |
| 97 |
$new_content_email = str_replace($data_key,$data_value,$new_content_email); |
| 98 |
$notification_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"full","html"=>$new_content_email)); |
| 99 |
$wp_new_user_notification_email['message'] = $notification_email; |
| 100 |
$custom_subject = get_post_meta( $template_id,'_yeemail_custom_subject',true); |
| 101 |
if($custom_subject != ""){ |
| 102 |
$wp_new_user_notification_email['subject'] = $custom_subject; |
| 103 |
} |
| 104 |
} |
| 105 |
return $wp_new_user_notification_email; |
| 106 |
} |
| 107 |
function new_admin_email_content($email_text, $new_admin_email ){ |
| 108 |
return $email_text; |
| 109 |
} |
| 110 |
function retrieve_password_notification_email($notification_email, $key, $user_login, $user_data ){ |
| 111 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type("password_reset"); |
| 112 |
if( $template_id && $template_id > 0) { |
| 113 |
$user_email = $user_data->user_email; |
| 114 |
$user_name = $user_login; |
| 115 |
$display_name = $user_data->display_name; |
| 116 |
$user_url = $user_data->user_url; |
| 117 |
$locale = get_user_locale( $user_data ); |
| 118 |
$set_password_url = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . '&wp_lang=' . $locale ; |
| 119 |
$data_key = array("[yeemail_user_name]","[yeemail_user_login]","[yeemail_user_email]","[yeemail_set_password_url]","[yeemail_user_display_name]","[yeemail_user_url]"); |
| 120 |
$data_value = array($user_name,$user_login,$user_email,$set_password_url,$display_name,$user_url); |
| 121 |
$new_content_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"content_no_shortcode")); |
| 122 |
$new_content_email = str_replace($data_key,$data_value,$new_content_email); |
| 123 |
$notification_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"full","html"=>$new_content_email)); |
| 124 |
} |
| 125 |
return $notification_email; |
| 126 |
} |
| 127 |
function retrieve_password_title($title, $user_login, $user_data){ |
| 128 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type("password_reset"); |
| 129 |
if( $template_id && $template_id > 0) { |
| 130 |
$custom_subject = get_post_meta( $template_id,'_yeemail_custom_subject',true); |
| 131 |
if($custom_subject != ""){ |
| 132 |
$title = $custom_subject; |
| 133 |
} |
| 134 |
} |
| 135 |
return $title; |
| 136 |
} |
| 137 |
function password_change_email($pass_change_email, $user, $userdata){ |
| 138 |
$template_id = Yeemail_Builder_Frontend::get_email_id_template_by_type("password_change"); |
| 139 |
if( $template_id && $template_id > 0) { |
| 140 |
$user_login = $user['user_login']; |
| 141 |
$user_email = $user['user_email']; |
| 142 |
$user_name = $user['user_login']; |
| 143 |
$display_name = $userdata->display_name; |
| 144 |
$user_url = $userdata->user_url; |
| 145 |
$set_password_url = network_site_url( 'wp-login.php', 'login' ); |
| 146 |
$data_key = array("[yeemail_user_name]","[yeemail_user_login]","[yeemail_user_email]","[yeemail_set_password_url]","[yeemail_user_display_name]","[yeemail_user_url]",); |
| 147 |
$data_value = array($user_name,$user_login,$user_email,$set_password_url,$display_name,$user_url); |
| 148 |
$new_content_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"content_no_shortcode")); |
| 149 |
$new_content_email = str_replace($data_key,$data_value,$new_content_email); |
| 150 |
$notification_email = Yeemail_Builder_Frontend_Functions::creator_template(array("id_template"=>$template_id,"type"=>"full","html"=>$new_content_email)); |
| 151 |
$pass_change_email['message'] = $notification_email; |
| 152 |
$custom_subject = get_post_meta( $template_id,'_yeemail_custom_subject',true); |
| 153 |
if($custom_subject != ""){ |
| 154 |
$pass_change_email['subject'] = $custom_subject; |
| 155 |
} |
| 156 |
} |
| 157 |
return $pass_change_email; |
| 158 |
} |
| 159 |
function wp_password_change_notification_email($wp_new_user_notification_email, $user, $blogname ){ |
| 160 |
$wp_new_user_notification_email = $this->user_notification_email("password_change_admin",$wp_new_user_notification_email, $user, $blogname); |
| 161 |
return $wp_new_user_notification_email; |
| 162 |
} |
| 163 |
function wp_new_user_notification_email_admin($wp_new_user_notification_email, $user, $blogname ){ |
| 164 |
$wp_new_user_notification_email = $this->user_notification_email("new_user_notification_admin",$wp_new_user_notification_email, $user, $blogname); |
| 165 |
return $wp_new_user_notification_email; |
| 166 |
} |
| 167 |
function wp_new_user_notification_email($wp_new_user_notification_email, $user, $blogname ){ |
| 168 |
$wp_new_user_notification_email = $this->user_notification_email("new_user_notification",$wp_new_user_notification_email, $user, $blogname); |
| 169 |
return $wp_new_user_notification_email; |
| 170 |
} |
| 171 |
} |
| 172 |
new Yeemail_New_User_Email; |