wp_notify_moderator

Notifies the moderator of the site about a new comment that is awaiting approval.

Description

wp_notify_moderator( (int) $comment_id ); 

Parameters (1)

0. $comment_id (int)
The comment id.

Usage

  1. if ( !function_exists( 'wp_notify_moderator' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable.php'; 
  3.  
  4. // The comment id. 
  5. $comment_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_notify_moderator($comment_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/pluggable.php  
  1. function wp_notify_moderator($comment_id) { 
  2. global $wpdb; 
  3.  
  4. $maybe_notify = get_option( 'moderation_notify' ); 
  5.  
  6. /** 
  7. * Filters whether to send the site moderator email notifications, overriding the site setting. 
  8. * @since 4.4.0 
  9. * @param bool $maybe_notify Whether to notify blog moderator. 
  10. * @param int $comment_ID The id of the comment for the notification. 
  11. */ 
  12. $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); 
  13.  
  14. if ( ! $maybe_notify ) { 
  15. return true; 
  16.  
  17. $comment = get_comment($comment_id); 
  18. $post = get_post($comment->comment_post_ID); 
  19. $user = get_userdata( $post->post_author ); 
  20. // Send to the administration and to the post author if the author can modify the comment. 
  21. $emails = array( get_option( 'admin_email' ) ); 
  22. if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { 
  23. if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) 
  24. $emails[] = $user->user_email; 
  25.  
  26. $switched_locale = switch_to_locale( get_locale() ); 
  27.  
  28. $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 
  29. $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 
  30.  
  31. // The blogname option is escaped with esc_html on the way into the database in sanitize_option 
  32. // we want to reverse this for the plain text arena of emails. 
  33. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
  34. $comment_content = wp_specialchars_decode( $comment->comment_content ); 
  35.  
  36. switch ( $comment->comment_type ) { 
  37. case 'trackback': 
  38. /** translators: 1: Post title */ 
  39. $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; 
  40. $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 
  41. /** translators: 1: Trackback/pingback website name, 2: website IP, 3: website hostname */ 
  42. $notify_message .= sprintf( __( 'Website: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
  43. /** translators: 1: Trackback/pingback/comment author URL */ 
  44. $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; 
  45. $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment_content . "\r\n\r\n"; 
  46. break; 
  47. case 'pingback': 
  48. /** translators: 1: Post title */ 
  49. $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; 
  50. $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 
  51. /** translators: 1: Trackback/pingback website name, 2: website IP, 3: website hostname */ 
  52. $notify_message .= sprintf( __( 'Website: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
  53. /** translators: 1: Trackback/pingback/comment author URL */ 
  54. $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; 
  55. $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment_content . "\r\n\r\n"; 
  56. break; 
  57. default: // Comments 
  58. /** translators: 1: Post title */ 
  59. $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; 
  60. $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 
  61. /** translators: 1: Comment author name, 2: comment author's IP, 3: comment author IP's hostname */ 
  62. $notify_message .= sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
  63. /** translators: 1: Comment author URL */ 
  64. $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; 
  65. /** translators: 1: Trackback/pingback/comment author URL */ 
  66. $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; 
  67. /** translators: 1: Comment text */ 
  68. $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; 
  69. break; 
  70.  
  71. /** translators: Comment moderation. 1: Comment action URL */ 
  72. $notify_message .= sprintf( __( 'Approve it: %s' ), admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ) . "\r\n"; 
  73.  
  74. if ( EMPTY_TRASH_DAYS ) { 
  75. /** translators: Comment moderation. 1: Comment action URL */ 
  76. $notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ) . "\r\n"; 
  77. } else { 
  78. /** translators: Comment moderation. 1: Comment action URL */ 
  79. $notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ) . "\r\n"; 
  80.  
  81. /** translators: Comment moderation. 1: Comment action URL */ 
  82. $notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ) . "\r\n"; 
  83.  
  84. /** translators: Comment moderation. 1: Number of comments awaiting approval */ 
  85. $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:',  
  86. 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; 
  87. $notify_message .= admin_url( "edit-comments.php?comment_status=moderated#wpbody-content" ) . "\r\n"; 
  88.  
  89. /** translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ 
  90. $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); 
  91. $message_headers = ''; 
  92.  
  93. /** 
  94. * Filters the list of recipients for comment moderation emails. 
  95. * @since 3.7.0 
  96. * @param array $emails List of email addresses to notify for comment moderation. 
  97. * @param int $comment_id Comment ID. 
  98. */ 
  99. $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); 
  100.  
  101. /** 
  102. * Filters the comment moderation email text. 
  103. * @since 1.5.2 
  104. * @param string $notify_message Text of the comment moderation email. 
  105. * @param int $comment_id Comment ID. 
  106. */ 
  107. $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); 
  108.  
  109. /** 
  110. * Filters the comment moderation email subject. 
  111. * @since 1.5.2 
  112. * @param string $subject Subject of the comment moderation email. 
  113. * @param int $comment_id Comment ID. 
  114. */ 
  115. $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); 
  116.  
  117. /** 
  118. * Filters the comment moderation email headers. 
  119. * @since 2.8.0 
  120. * @param string $message_headers Headers for the comment moderation email. 
  121. * @param int $comment_id Comment ID. 
  122. */ 
  123. $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); 
  124.  
  125. foreach ( $emails as $email ) { 
  126. @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); 
  127.  
  128. if ( $switched_locale ) { 
  129.  
  130. return true;