| | 2394 | |
| | 2395 | /** |
| | 2396 | * Notify a comment author when his comment gets approved. |
| | 2397 | * |
| | 2398 | * @since 4.4.0 |
| | 2399 | * |
| | 2400 | * @param string $new_status New comment status. |
| | 2401 | * @param string $old_status Previous comment status. |
| | 2402 | * @param WP_Comment $comment Comment object. |
| | 2403 | * @return bool Whether the email was sent successfully. |
| | 2404 | */ |
| | 2405 | function wp_notify_commenter( $new_status, $old_status, $comment ) { |
| | 2406 | /** |
| | 2407 | * Filter whether to notify comment authors when their comment gets approved. |
| | 2408 | * |
| | 2409 | * @since 4.4.0 |
| | 2410 | * |
| | 2411 | * @param bool $notify Whether to notify the comment author. Default true. |
| | 2412 | * @param WP_Comment $comment Comment object. |
| | 2413 | */ |
| | 2414 | $notify_commenter = apply_filters( 'comment_notification_notify_commenter', true, $comment ); |
| | 2415 | |
| | 2416 | if ( ! $notify_commenter ) { |
| | 2417 | return false; |
| | 2418 | } |
| | 2419 | |
| | 2420 | $post = get_post( $comment->comment_post_ID ); |
| | 2421 | |
| | 2422 | if ( ! $post ) { |
| | 2423 | return false; |
| | 2424 | } |
| | 2425 | |
| | 2426 | // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
| | 2427 | // we want to reverse this for the plain text arena of emails. |
| | 2428 | $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
| | 2429 | |
| | 2430 | /* translators: 1: blog name, 2: post title */ |
| | 2431 | $subject = sprintf( __( '[%1$s] Your comment on "%2$s" got approved' ), $blogname, $post->post_title ); |
| | 2432 | |
| | 2433 | $notify_message = sprintf( __( 'Howdy %s,' ), $comment->comment_author ) . "\r\n\r\n"; |
| | 2434 | $notify_message .= sprintf( __( 'Your comment on the post "%1$s" got approved.' ), $post->post_title ) . "\r\n\r\n"; |
| | 2435 | /* translators: 1: comment author, 2: author IP, 3: author domain */ |
| | 2436 | $notify_message .= sprintf( __( 'View comment: %s' ), get_comment_link( $comment ) ) . "\r\n"; |
| | 2437 | |
| | 2438 | /** |
| | 2439 | * Filter the comment approval notification email text. |
| | 2440 | * |
| | 2441 | * @since 4.4.0 |
| | 2442 | * |
| | 2443 | * @param string $notify_message The comment notification email text. |
| | 2444 | * @param WP_Comment $comment Comment object. |
| | 2445 | */ |
| | 2446 | $notify_message = apply_filters( 'comment_approval_notification_text', $notify_message, $comment ); |
| | 2447 | |
| | 2448 | /** |
| | 2449 | * Filter the comment approval notification email subject. |
| | 2450 | * |
| | 2451 | * @since 4.4.0 |
| | 2452 | * |
| | 2453 | * @param string $subject The comment notification email subject. |
| | 2454 | * @param WP_Comment $comment Comment object. |
| | 2455 | */ |
| | 2456 | $subject = apply_filters( 'comment_approval_notification_subject', $subject, $comment ); |
| | 2457 | |
| | 2458 | return wp_mail( $comment->comment_author_email, wp_specialchars_decode( $subject ), $notify_message ); |
| | 2459 | } |