[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 <?php 2 class MP_WP_Pluggable 3 { 4 public static function wp_mail( $to, $subject, $message, $headers = '', $attachments = false ) 5 { 6 $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); 7 8 $atts['to'] = $atts['to'] ?? array(); 9 $atts['subject'] = $atts['subject'] ?? ''; 10 $atts['message'] = $atts['message'] ?? ''; 11 $atts['headers'] = $atts['headers'] ?? array(); 12 $atts['attachments'] = $atts['attachments'] ?? array(); 13 14 $mail = new stdClass(); 15 $mail->replacements = $mail->recipients = array(); 16 17 // attachments 18 $attachments = self::wp_mail_arg_in_array( $atts['attachments'], "\n" ); 19 20 if ( is_array( $attachments ) ) 21 { 22 foreach ( $attachments as $attachment ) 23 { 24 $attachment = @str_replace( "\\", "/", $attachment ); 25 if ( @is_file( $attachment ) ) 26 { 27 if ( !isset( $mail->id ) ) $mail->id = MP_Mail::get_id( 'wp_mail_5_4_a' ); 28 29 $object = array( 'name' => basename( $attachment ), 30 'mime_type' => 'application/octet-stream', 31 'file' => '', 32 'file_fullpath' => $attachment, 33 'guid' => '' 34 ); 35 MP_Mail_meta::add( $mail->id, '_MailPress_attached_file', $object ); 36 } 37 } 38 } 39 40 // headers 41 // 'to' can be headers AND string|array of comma separated list of emails ! 42 43 $to = self::wp_mail_arg_in_array( $atts['to'], ',' ); 44 $headers = self::wp_mail_arg_in_array( $atts['headers'], "\n" ); 45 46 $recipients = array(); 47 // 'to' always first 48 $_accepted_headers = array( 'to', 'bcc', 'cc', 'from', 'reply_to', 'return_path', ); 49 // custom headers starting with 'X-' are also accepted 50 $_headers = array(); 51 52 if ( !empty( $headers ) ) 53 { 54 if ( !isset( $mail->id ) ) $mail->id = MP_Mail::get_id( 'wp_mail_5_4_b' ); 55 MP_Mail_meta::add( $mail->id, '_MailPress_original_headers', $atts['headers'] ); 56 57 foreach ( (array) $headers as $header ) 58 { 59 list( $name, $content ) = explode( ':', $header, 2 ); 60 $name = trim( $name ); 61 $content = trim( $content ); 62 63 $_name = strtolower( str_replace( '-', '_', $name ) ); 64 65 switch ( true ) 66 { 67 case ( in_array( $_name, $_accepted_headers ) ) : 68 if ( !isset( $$_name ) ) $$_name = array(); 69 $$_name[] = $content; 70 break; 71 case ( strpos( $name, 'X-' ) === 0 ) : 72 $_headers['X'][][$name] = $content; 73 break; 74 } 75 } 76 } 77 78 foreach( $_accepted_headers as $_name ) 79 { 80 if ( !isset( $$_name ) ) continue; 81 $$_name = self::wp_mail_arg_in_array( $$_name, ',' ); 82 if ( empty( $$_name ) ) { unset( $$_name ); continue; } 83 84 switch( $_name ) 85 { 86 case 'from' : 87 list( $from_email, $from_name ) = self::wp_mail_header_to_email( array_shift( $$_name ) ); 88 break; 89 case 'return_path' : 90 list( $email, $ename ) = self::wp_mail_header_to_email( array_shift( $$_name ) ); 91 if ( $email ) $_headers[$_name][0] = $email; 92 break; 93 case 'to' : 94 case 'cc' : 95 case 'bcc' : 96 case 'reply_to' : 97 foreach( $$_name as $content ) 98 { 99 list( $email, $ename ) = self::wp_mail_header_to_email( $content ); 100 switch( $_name ) 101 { 102 case 'to' : 103 if ( $email && $ename ) $recipients[$email] = $ename; 104 elseif ( $email ) $recipients[$email] = ''; 105 break; 106 default : 107 if ( $email && $ename ) $_headers[$_name][$email] = $ename; 108 elseif ( $email ) $_headers[$_name][$email] = ''; 109 break; 110 } 111 } 112 break; 113 } 114 } 115 116 if ( !empty( $_headers ) ) 117 { 118 if ( !isset( $mail->id ) ) $mail->id = MP_Mail::get_id( 'wp_mail_5_4_c' ); 119 MP_Mail_meta::add( $mail->id, '_MailPress_accepted_headers', $_headers, true ); 120 } 121 122 ////////////////////////// 123 124 // filters for from 125 $from_email = apply_filters( 'wp_mail_from', $from_email ?? false ); 126 $from_name = apply_filters( 'wp_mail_from_name', $from_name ?? false ); 127 128 // from 129 $mail->fromemail = $from_email ?: NULL; 130 $mail->fromname = $from_name ?: NULL; 131 132 // to 133 $mail->recipients = $recipients; 134 135 // subject 136 $subject = $atts['subject'] ?? ''; 137 $mail->subject = $subject; 138 139 // message 140 $message = $atts['message']; 141 142 if ( is_array( $message ) ) 143 { 144 if ( isset( $message['plaintext'] ) ) $mail->plaintext = $message['plaintext']; 145 if ( isset( $message['text/plain'] ) ) $mail->plaintext = $message['text/plain']; 146 if ( isset( $message['html'] ) ) $mail->html = $message['html']; 147 if ( isset( $message['text/html'] ) ) $mail->html = $message['text/html']; 148 } 149 else 150 { 151 $mail->content = $message; 152 } 153 154 return MailPress::mail( $mail ); 155 } 156 157 public static function wp_mail_arg_in_array( $arg, $sep ) 158 { 159 if ( is_array( $arg ) ) $arg = implode( $sep, $arg ); 160 $arg = array_unique( array_filter( array_map( 'trim', explode( $sep, trim( str_replace( array( "\r\n", $sep.$sep, $sep.$sep, ' ', ' ', ), array( $sep, $sep, $sep, ' ', ' ', ), $arg ), $sep ) ) ) ) ); 161 if ( empty( $arg ) ) return array(); 162 return $arg; 163 } 164 165 public static function wp_mail_header_to_email( $string ) 166 { 167 $email = $name = false; 168 169 if ( !is_string( $string ) ) return array( $email, $name, ); 170 171 $string = trim( $string ); 172 173 if ( preg_match( '/(.*)<(.+)>/', $string, $matches ) && ( count( $matches ) == 3 ) ) 174 { 175 $name = trim( $matches[1] ); 176 177 $beg = substr( $name, 0, 1 ); 178 $end = substr( $name, -1, 1 ); 179 if ( ( $beg == '"' ) && ( $end == '"' ) ) $name = trim( substr( $name, 1, -1) ); 180 181 $email = trim( $matches[2] ); 182 } 183 else 184 { 185 $email = trim( $string ); 186 } 187 188 if ( !MailPress::is_email( $email ) ) $email = false; 189 190 return array( $email, ( $email ) ? $name : false, ); 191 } 192 193 public static function wp_notify_postauthor( $comment_id, $deprecated = null ) 194 { 195 $wp_mail_args = array( 196 'to' => array(), 197 'subject' => '', 198 'message' => '', 199 'headers' => array(), 200 ); 201 202 $comment = get_comment( $comment_id ); 203 if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) return false; 204 205 $post = get_post( $comment->comment_post_ID ); 206 $author = get_userdata( $post->post_author ); 207 208 // to 209 if ( $author ) $wp_mail_args['to'][] = $author->user_email; 210 211 $wp_mail_args['to'] = apply_filters( 'comment_notification_recipients', $wp_mail_args['to'], $comment_id ); 212 $wp_mail_args['to'] = array_filter( $wp_mail_args['to'] ); 213 214 if ( ! count( $wp_mail_args['to'] ) ) return false; 215 $wp_mail_args['to'] = array_flip( $wp_mail_args['to'] ); 216 217 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id ); 218 219 if ( $author && ! $notify_author ) 220 { 221 switch( true ) 222 { 223 case ( $comment->user_id == $post->post_author ) : // The comment was left by the author. 224 case ( get_current_user_id() == $post->post_author ) : // The author moderated a comment on their own post. 225 case ( ! user_can( $post->post_author, 'read_post', $post->ID ) ) : // The post author is no longer a member of the blog. 226 unset( $wp_mail_args['to'][$author->user_email] ); 227 break; 228 } 229 } 230 231 if ( ! count( $wp_mail_args['to'] ) ) return false; 232 $wp_mail_args['to'] = array_flip( $wp_mail_args['to'] ); 233 234 // subject 235 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 236 switch ( $comment->comment_type ) 237 { 238 case 'trackback' : 239 $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title ); 240 break; 241 case 'pingback' : 242 $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title ); 243 break; 244 default: //Comments 245 $subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title ); 246 break; 247 } 248 $wp_mail_args['subject'] = $subject; 249 250 // message 251 $comment->author_domain = ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) ? gethostbyaddr( $comment->comment_author_IP ) : ''; 252 $comment_content = wp_specialchars_decode( $comment->comment_content ); 253 254 $url['comments'] = get_permalink( $comment->comment_post_ID ) . '#comments'; 255 $url['permalink']= get_comment_link( $comment ); 256 $url['trash'] = admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ); 257 $url['delete'] = admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ); 258 $url['spam'] = admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ); 259 260 $_message = array(); 261 switch ( $comment->comment_type ) 262 { 263 case 'trackback' : 264 $_message[] = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ); 265 $_message[] = sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ); 266 $_message[] = sprintf( __( 'URL: %s' ), $comment->comment_author_url ); 267 $_message[] = sprintf( __( 'Comment: %s' ), '' ); 268 $_message[] = $comment_content; 269 $_message[] = ''; 270 $_message[] = __( 'You can see all trackbacks on this post here:' ); 271 break; 272 case 'pingback' : 273 $_message[] = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ); 274 $_message[] = sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ); 275 $_message[] = sprintf( __( 'URL: %s' ), $comment->comment_author_url ); 276 $_message[] = sprintf( __( 'Comment: %s' ), '' ); 277 $_message[] = $comment_content; 278 $_message[] = ''; 279 $_message[] = __( 'You can see all pingbacks on this post here:' ); 280 break; 281 default: //Comments 282 $_message[] = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ); 283 $_message[] = sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ); 284 $_message[] = sprintf( __( 'Email: %s' ), $comment->comment_author_email ); 285 $_message[] = sprintf( __( 'URL: %s' ), $comment->comment_author_url ); 286 if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) { 287 $_message[] = sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ); 288 } 289 $_message[] = sprintf( __( 'Comment: %s' ), '' ); 290 $_message[] = $comment_content; 291 $_message[] = ''; 292 $_message[] = __( 'You can see all comments on this post here:' ); 293 break; 294 } 295 296 $_message[] = ''; 297 $_message[] = $url['comments']; 298 $_message[] = sprintf( __( 'Permalink: %s' ), $url['permalink'] ); 299 if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) 300 { 301 $_message[] = ( EMPTY_TRASH_DAYS ) ? sprintf( __( 'Trash it: %s' ), $url['trash'] ) : sprintf( __( 'Delete it: %s' ), $url['delete'] ); 302 $_message[] = sprintf( __( 'Spam it: %s' ), $url['spam'] ); 303 } 304 $wp_mail_args['message'] = implode( "\r\n", $_message ); $wp_mail_args['message'] = implode( "\r\n", $_message ); 305 306 //headers 307 $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) ); 308 309 if ( '' == $comment->comment_author ) { 310 $wp_mail_args['headers'][] = "From: \"$blogname\" <$wp_email>"; 311 if ( '' != $comment->comment_author_email ) { 312 $wp_mail_args['headers'][] = "Reply-To: $comment->comment_author_email"; 313 } 314 } else { 315 $wp_mail_args['headers'][] = "From: \"$comment->comment_author\" <$wp_email>"; 316 if ( '' != $comment->comment_author_email ) { 317 $wp_mail_args['headers'][] = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; 318 } 319 } 320 $wp_mail_args['headers'][] = 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . '"'; 321 322 // filters 323 $wp_mail_args['to'] = apply_filters( 'comment_notification_recipients', $wp_mail_args['to'], $comment_id ); 324 $wp_mail_args['message'] = apply_filters( 'comment_notification_text', $wp_mail_args['message'], $comment_id ); 325 $wp_mail_args['subject'] = apply_filters( 'comment_notification_subject', $wp_mail_args['subject'], $comment_id ); 326 $wp_mail_args['headers'] = apply_filters( 'comment_notification_headers', $wp_mail_args['headers'], $comment_id ); 327 328 // mailpress 329 // multiple 'to' and headers skipped 330 331 $mail = new stdClass(); 332 $mail->Template = 'moderate'; 333 $mail->toemail = $author->user_email; 334 $mail->toname = $author->display_name; 335 $mail->subject = $wp_mail_args['subject']; 336 $mail->content = str_replace( "\r\n", "<br />\r\n", $wp_mail_args['message'] ); 337 338 $mail->advanced = new stdClass(); 339 $mail->advanced->comment = $comment; 340 $mail->advanced->user = $author; 341 unset ( $post->post_content, $post->post_excerpt ); 342 $mail->advanced->post = $post; 343 $mail->advanced->url = $url; 344 345 $mail->the_title = $post->post_title; 346 347 return MailPress::mail( $mail ); 348 } 349 350 public static function wp_notify_moderator( $comment_id ) 351 { 352 global $wpdb; 353 354 $wp_mail_args = array( 355 'to' => array(), 356 'subject' => '', 357 'message' => '', 358 'headers' => '', 359 ); 360 361 $maybe_notify = get_option( 'moderation_notify' ); 362 $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); 363 if ( ! $maybe_notify ) return true; 364 365 $comment = get_comment( $comment_id ); 366 if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) return false; 367 368 $post = get_post( $comment->comment_post_ID ); 369 $author = get_userdata( $post->post_author ); 370 371 // to 372 // Send to the administration and to the post author if the author can modify the comment. 373 $wp_mail_args['to'][] = get_option( 'admin_email' ); 374 if ( $author && !empty( $author->user_email ) && ( get_option( 'admin_email' ) != $author->user_email ) && user_can( $author->ID, 'edit_comment', $comment_id ) ) 375 $wp_mail_args['to'][] = $author->user_email; 376 377 // subject 378 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 379 $wp_mail_args['subject'] = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); 380 381 // message 382 $comment->author_domain = ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) ? gethostbyaddr( $comment->comment_author_IP ) : ''; 383 $comment->waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ); 384 $comment_content = wp_specialchars_decode( $comment->comment_content ); 385 386 $url['approve']= admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ); 387 $url['trash'] = admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ); 388 $url['delete'] = admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ); 389 $url['spam'] = admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ); 390 $url['moderate'] = admin_url( "edit-comments.php?comment_status=moderated#wpbody-content" ); 391 392 $_message = array(); 393 switch ( $comment->comment_type ) 394 { 395 case 'trackback': 396 $_message[] = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ); 397 $_message[] = get_permalink( $comment->comment_post_ID ); 398 $_message[] = ''; 399 $_message[] = sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ); 400 $_message[] = sprintf( __( 'URL: %s' ), $comment->comment_author_url ); 401 $_message[] = __( 'Trackback excerpt: ' ); 402 $_message[] = $comment_content; 403 break; 404 case 'pingback': 405 $_message[] = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ); 406 $_message[] = get_permalink( $comment->comment_post_ID ); 407 $_message[] = ''; 408 $_message[] = sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ); 409 $_message[] = sprintf( __( 'URL: %s' ), $comment->comment_author_url ); 410 $_message[] = __( 'Pingback excerpt: ' ); 411 $_message[] = $comment_content; 412 break; 413 default: //Comments 414 $_message[] = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ); 415 $_message[] = get_permalink( $comment->comment_post_ID ); 416 $_message[] = ''; 417 $_message[] = sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ); 418 $_message[] = sprintf( __( 'Email: %s' ), $comment->comment_author_email ); 419 $_message[] = sprintf( __( 'URL: %s' ), $comment->comment_author_url ); 420 if ( $comment->comment_parent ) { 421 $_message[] = sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ); 422 } 423 $_message[] = sprintf( __( 'Comment: %s' ), '' ); 424 $_message[] = $comment_content; 425 break; 426 } 427 428 $_message[] = ''; 429 $_message[] = sprintf( __( 'Approve it: %s' ), $url['approve'] ); 430 $_message[] = ( EMPTY_TRASH_DAYS ) ? sprintf( __( 'Trash it: %s' ), $url['trash'] ) : sprintf( __( 'Delete it: %s' ), $url['delete'] ); 431 $_message[] = sprintf( __( 'Spam it: %s' ), $url['spam'] ); 432 $_message[] = sprintf( 433 _n( 434 'Currently %s comment is waiting for approval. Please visit the moderation panel:', 435 'Currently %s comments are waiting for approval. Please visit the moderation panel:', 436 $comment->waiting 437 ), 438 number_format_i18n( $comment->waiting ) 439 ); 440 $_message[] = $url['moderate']; 441 442 $wp_mail_args['message'] = implode( "\r\n", $_message ); 443 444 // filters 445 $wp_mail_args['to'] = apply_filters( 'comment_moderation_recipients', $wp_mail_args['to'], $comment_id ); 446 $wp_mail_args['to'] = array_filter( $wp_mail_args['to'] ); 447 448 $wp_mail_args['message'] = apply_filters( 'comment_moderation_text', $wp_mail_args['message'], $comment_id ); 449 $wp_mail_args['subject'] = apply_filters( 'comment_moderation_subject', $wp_mail_args['subject'], $comment_id ); 450 $wp_mail_args['headers'] = apply_filters( 'comment_moderation_headers', $wp_mail_args['headers'], $comment_id ); 451 452 453 // mailpress 454 // multiple 'to' and headers skipped 455 456 $mail = new stdClass(); 457 $mail->Template = 'moderate'; 458 $mail->toemail = $author->user_email; 459 $mail->toname = $author->display_name; 460 $mail->subject = $wp_mail_args['subject']; 461 $mail->content = str_replace( "\r\n", "<br />\r\n", $wp_mail_args['message'] ); 462 463 $mail->advanced = new stdClass(); 464 $mail->advanced->comment = $comment; 465 $mail->advanced->user = $author; 466 unset ( $post->post_content, $post->post_excerpt ); 467 $mail->advanced->post = $post; 468 $mail->advanced->url = $url; 469 470 $mail->the_title = $post->post_title; 471 472 foreach ( $wp_mail_args['to'] as $email ) 473 { 474 $mail->toemail = $email; 475 MailPress::mail( $mail ); 476 } 477 return true; 478 } 479 480 public static function wp_password_change_notification( $user ) 481 { 482 if ( 0 === strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) return; 483 484 $wp_mail_args = array( 485 'to' => '', 486 'subject' => '', 487 'message' => '', 488 'headers' => '', 489 ); 490 491 // to 492 $wp_mail_args['to'] = get_option( 'admin_email' ); 493 // subject 494 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 495 $wp_mail_args['subject'] = __( '[%s] New User Registration' ); 496 497 // message 498 $_message = array(); 499 $_message[] = sprintf( __( 'Password changed for user: %s' ), $user->user_login ); 500 $_message[] = ''; 501 502 $wp_mail_args['message'] = implode( "\r\n", $_message ); 503 504 // filters 505 $wp_mail_args = apply_filters( 'wp_password_change_notification_email', $wp_mail_args, $user, $blogname ); 506 507 // mailpress 508 $mail = new stdClass(); 509 $mail->Template = 'changed_pwd'; 510 $mail->toemail = get_option( 'admin_email' ); // only one recipient 511 $mail->toname = ''; 512 $mail->subject = sprintf( $wp_mail_args['subject'], $blogname ); 513 $mail->content = str_replace( "\r\n", "<br />\r\n", $wp_mail_args['message'] ); 514 515 $mail->advanced = new stdClass(); 516 $mail->advanced->admin = $mail->toemail; 517 $mail->advanced->user = $user; 518 519 return MailPress::mail( $mail ); 520 } 521 522 public static function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) 523 { 524 // Accepts only 'user', 'admin' , 'both' or default '' as $notify. 525 if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) return; 526 527 $wp_mail_args = array( 528 'to' => '', 529 'subject' => '', 530 'message' => '', 531 'headers' => '', 532 ); 533 534 $user = get_userdata( $user_id ); 535 536 // to 537 $wp_mail_args['to'] = get_option( 'admin_email' ); 538 539 // subject 540 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 541 542 if ( 'user' !== $notify ) 543 { 544 $wp_mail_args['subject'] = __( '[%s] New User Registration' ); 545 546 // message 547 $_message = array(); 548 $_message[] = sprintf( __( 'New user registration on your site %s:' ), $blogname ); 549 $_message[] = ''; 550 $_message[] = sprintf( __( 'Username: %s' ), $user->user_login ); 551 $_message[] = ''; 552 $_message[] = sprintf( __( 'Email: %s' ), $user->user_email ); 553 554 $wp_mail_args['message'] = implode( "\r\n", $_message ); 555 556 // filters 557 $wp_mail_args = apply_filters( 'wp_new_user_notification_email_admin', $wp_mail_args, $user, $blogname ); 558 559 // mailpress 560 $mail = new stdClass(); 561 $mail->Template = 'new_user'; 562 $mail->toemail = get_option( 'admin_email' ); // only one recipient 563 $mail->toname = ''; 564 $mail->subject = sprintf( $wp_mail_args['subject'], $blogname ); 565 $mail->content = str_replace( "\r\n", "<br />\r\n", $wp_mail_args['message'] ); 566 567 $mail->advanced = new stdClass(); 568 $mail->advanced->admin = $mail->toemail; 569 $mail->advanced->user = $user; 570 571 MailPress::mail( $mail ); 572 } 573 574 $wp_mail_args = array( 575 'to' => '', 576 'subject' => '', 577 'message' => '', 578 'headers' => '', 579 ); 580 581 if ( 'admin' === $notify || empty( $notify ) ) return; 582 583 // to 584 $wp_mail_args['to'] = $user->user_email; 585 // subject 586 $wp_mail_args['subject'] = __( '[%s] Login Details' ); 587 // message 588 $key = get_password_reset_key( $user ); 589 if ( is_wp_error( $key ) ) return; 590 591 $url = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ); 592 $user->plaintext_pass = $url; 593 $user->password_url = $url; 594 595 $_message = array(); 596 $_message[] = sprintf( __( 'Username: %s' ), $user->user_login ); 597 $_message[] = ''; 598 $_message[] = __( 'To set your password, visit the following address:' ); 599 $_message[] = ''; 600 $_message[] = $url; 601 $_message[] = ''; 602 $_message[] = wp_login_url(); 603 604 $wp_mail_args['message'] = implode( "\r\n", $_message ); 605 606 // filters 607 $wp_mail_args = apply_filters( 'wp_new_user_notification_email', $wp_mail_args, $user, $blogname ); 608 609 // mailpress 610 $mail = new stdClass(); 611 $mail->Template = 'new_user'; 612 $mail->toemail = $user->user_email; // only one recipient 613 $mail->toname = ''; 614 $mail->subject = sprintf( $wp_mail_args['subject'], $blogname ); 615 $mail->content = str_replace( "\r\n", "<br />\r\n", $wp_mail_args['message'] ); 616 617 $mail->advanced = new stdClass(); 618 $mail->advanced->user = $user; 619 620 MailPress::mail( $mail ); 621 } 622 623 public static function retrieve_password_message( $message, $key, $user_login, $user_data ) 624 { 625 $wp_mail_args = array( 626 'to' => array(), 627 'subject' => '', 628 'message' => '', 629 'headers' => '', 630 ); 631 632 $user = $user_data; 633 634 // to 635 $wp_mail_args['to'] = $user_email = $user->user_email; 636 $user_login = $user->user_login; 637 638 // subject 639 $blogname = ( is_multisite() ) ? get_network()->site_name : wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 640 $wp_mail_args['subject'] = sprintf( __( '[%s] Password Reset' ), $blogname ); 641 642 // message 643 $key = get_password_reset_key( $user_data ); 644 if ( is_wp_error( $key ) ) return $key; 645 646 $url['site'] = network_site_url(); 647 $url['reset'] = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ); 648 649 $_message = array(); 650 $_message[] = __( 'Someone has requested a password reset for the following account:' ); 651 $_message[] = ''; 652 $_message[] = sprintf( __( 'Site Name: %s' ), $blogname ); 653 $_message[] = ''; 654 $_message[] = sprintf( __( 'Username: %s' ), $user_login ); 655 $_message[] = ''; 656 $_message[] = __( 'If this was a mistake, just ignore this email and nothing will happen.' ); 657 $_message[] = ''; 658 $_message[] = __( 'To reset your password, visit the following address:' ); 659 $_message[] = ''; 660 $_message[] = $url['reset'] . "<br />\r\n"; 661 662 $wp_mail_args['message'] = implode( "\r\n", $_message ); 663 664 // mailpress 665 // filters skipped because we are here through a filter, not a pluggable function 666 667 $mail = new stdClass(); 668 $mail->Template = 'retrieve_pwd'; 669 $mail->toemail = $user_email; 670 $mail->toname = $user->display_name; 671 $mail->subject = $wp_mail_args['subject']; 672 $mail->content = str_replace( "\r\n", "<br />\r\n", $wp_mail_args['message'] ); 673 674 $mail->advanced = new stdClass(); 675 $mail->advanced->user = $user; 676 $mail->advanced->url = $url; 677 678 if ( MailPress::mail( $mail ) ) return false; 679 return $message; 680 } 681 682 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |