wp_notify_postauthor( int|WP_Comment $comment_id, string $deprecated = null )
Notify an author (and/or others) of a comment/trackback/pingback on a post.
Description
Parameters
- $comment_id
-
(Required) Comment ID or WP_Comment object.
- $deprecated
-
(Optional) Not used
Default value: null
Return
(bool) True on completion. False if no email addresses were specified.
Source
File: bp-core/bp-core-wp-emails.php
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | function wp_notify_postauthor( $comment_id , $deprecated = null ) { if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__ , '3.8.0' ); } $comment = get_comment( $comment_id ); if ( empty ( $comment ) || empty ( $comment ->comment_post_ID ) ) return false; $post = get_post( $comment ->comment_post_ID ); $author = get_userdata( $post ->post_author ); // Who to notify? By default, just the post author, but others can be added. $emails = array (); if ( $author ) { $emails [] = $author ->user_email; } /** * Filters the list of email addresses to receive a comment notification. * * By default, only post authors are notified of comments. This filter allows * others to be added. * * @since BuddyPress 3.7.0 * * @param array $emails An array of email addresses to receive a comment notification. * @param int $comment_id The comment ID. */ $emails = apply_filters( 'comment_notification_recipients' , $emails , $comment ->comment_ID ); $emails = array_filter ( $emails ); // If there are no addresses to send the comment to, bail. if ( ! count ( $emails ) ) { return false; } // Facilitate unsetting below without knowing the keys. $emails = array_flip ( $emails ); /** * Filters whether to notify comment authors of their comments on their own posts. * * By default, comment authors aren't notified of their comments on their own * posts. This filter allows you to override that. * * @since BuddyPress 3.8.0 * * @param bool $notify Whether to notify the post author of their own comment. * Default false. * @param int $comment_id The comment ID. */ $notify_author = apply_filters( 'comment_notification_notify_author' , false, $comment ->comment_ID ); // The comment was left by the author if ( $author && ! $notify_author && $comment ->user_id == $post ->post_author ) { unset( $emails [ $author ->user_email ] ); } // The author moderated a comment on their own post if ( $author && ! $notify_author && $post ->post_author == get_current_user_id() ) { unset( $emails [ $author ->user_email ] ); } // The post author is no longer a member of the blog if ( $author && ! $notify_author && ! user_can( $post ->post_author, 'read_post' , $post ->ID ) ) { unset( $emails [ $author ->user_email ] ); } // If there's no email to send the comment to, bail, otherwise flip array back around for use below if ( ! count ( $emails ) ) { return false; } else { $emails = array_flip ( $emails ); } $switched_locale = switch_to_locale( get_locale() ); $comment_author_domain = @ gethostbyaddr ( $comment ->comment_author_IP); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option( 'blogname' ), ENT_QUOTES); $comment_content = wp_specialchars_decode( $comment ->comment_content ); // Get customizer setting options $settings = bp_email_get_appearance_settings(); switch ( $comment ->comment_type ) { case 'trackback' : $title = __( 'added trackback on your post' , 'buddyboss' ); $footer_message = sprintf( __( '<a href="%s">Click here</a> to see all trackbacks on this post.' , 'buddyboss' ), get_permalink( $comment ->comment_post_ID ) . '#comments' ); $moderate_text = __( 'Moderate this trackback: ' , 'buddyboss' ); /* translators: 1: blog name, 2: post title */ $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' , 'buddyboss' ), $blogname , $post ->post_title ); break ; case 'pingback' : $title = __( 'added pingback on your post' , 'buddyboss' ); $footer_message = sprintf( __( '<a href="%s">Click here</a> to see all pingbacks on this post.' , 'buddyboss' ), get_permalink( $comment ->comment_post_ID ) . '#comments' ); $moderate_text = __( 'Moderate this pingback: ' , 'buddyboss' ); /* translators: 1: blog name, 2: post title */ $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' , 'buddyboss' ), $blogname , $post ->post_title ); break ; default : // Comments $title = __( 'added comment on your post' , 'buddyboss' ); $footer_message = sprintf( __( '<a href="%s">Click here</a> to see all comments on this post.' , 'buddyboss' ), get_permalink( $comment ->comment_post_ID ) . '#comments' ); $moderate_text = __( 'Moderate this comment: ' , 'buddyboss' ); /* translators: 1: blog name, 2: post title */ $subject = sprintf( __( '[%1$s] Comment: "%2$s"' , 'buddyboss' ), $blogname , $post ->post_title ); break ; } ob_start(); ?> <p> <?php if ( ! empty ( $comment ->user_id ) ) { ?> <a href= "<?php echo esc_attr( bp_core_get_user_domain( $comment->user_id ) ); ?>" > <?php echo $comment ->comment_author; ?> </a> <?php } else { echo $comment ->comment_author; } ?> <?php echo $title ; ?> <a href= "<?php echo get_permalink($comment->comment_post_ID); ?>" ><?php echo $post ->post_title; ?></a> </p> <table cellspacing= "0" cellpadding= "0" border= "0" width= "100%" > <?php if ( ! empty ( $comment ->user_id ) ) { ?> <tr> <td align= "center" > <table cellpadding= "0" cellspacing= "0" border= "0" width= "100%" > <tbody> <tr> <td valign= "middle" width= "65px" style= "vertical-align: middle;" > <a style= "display: block; width: 47px;" href= "<?php echo esc_attr( bp_core_get_user_domain( $comment->user_id ) ); ?>" target= "_blank" rel= "nofollow" > <?php $avatar_url = bp_core_fetch_avatar( array ( 'item_id' => $comment ->user_id, 'width' => 100, 'height' => 100, 'type' => 'full' , 'html' => false, ) ); ?> <img src= "<?php echo esc_attr( $avatar_url ); ?>" width= "47" height= "47" style= "margin:0; padding:0; border:none; display:block; max-width: 47px; border-radius: 50%;" border= "0" > </a> </td> <td width= "88%" style= "vertical-align: middle;" > <div style= "color: <?php echo esc_attr( $settings['body_secondary_text_color'] ); ?>; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: <?php echo esc_attr( $settings['body_text_size'] . 'px' ); ?>; line-height: <?php echo esc_attr( $settings['body_text_size'] . 'px' ); ?>; letter-spacing: -0.24px;" > <?php echo bp_core_get_user_displayname( $comment ->user_id ); ?> </div> </td> </tr> </tbody> </table> </td> </tr> <tr> <td height= "24px" style= "font-size: 24px; line-height: 24px;" > </td> </tr> <?php } ?> <tr> <td> <table cellspacing= "0" cellpadding= "0" border= "0" width= "100%" style= "background: <?php echo esc_attr( $settings['quote_bg'] ); ?>; border: 1px solid <?php echo esc_attr( $settings['body_border_color'] ); ?>; border-radius: 4px; border-collapse: separate !important" > <tbody> <tr> <td height= "5px" style= "font-size: 5px; line-height: 5px;" > </td> </tr> <tr> <td align= "center" > <table cellpadding= "0" cellspacing= "0" border= "0" width= "88%" style= "width: 88%;" > <tbody> <tr> <td> <div style= "color: <?php echo esc_attr( $settings['body_text_color'] ); ?>; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: <?php echo esc_attr( $settings['body_text_size'] . 'px' ); ?>; letter-spacing: -0.24px; line-height: <?php echo esc_attr( floor( $settings['body_text_size'] * 1.625 ) . 'px' ) ?>;" > <?php echo wpautop( $comment_content ); ?> </div> </td> </tr> </tbody> </table> </td> </tr> <tr> <td height= "5px" style= "font-size: 5px; line-height: 5px;" > </td> </tr> </tbody> </table> </td> </tr> <tr> <td height= "24px" style= "font-size: 24px; line-height: 24px;" > </td> </tr> <tr> <td> <a href= "<?php echo get_comment_link( $comment ); ?>" target= "_blank" rel= "nofollow" style= "font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; color: <?php echo $settings['highlight_color']; ?>; text-decoration: none; display: block; border: 1px solid <?php echo $settings['highlight_color']; ?>; border-radius: 100px; width: 84px; text-align: center; height: 32px; line-height: 32px;" ><?php _e( 'Reply' , 'buddyboss' ); ?></a> </td> </tr> <tr> <td> <div style= "color: <?php echo esc_attr( $settings['body_text_color'] ); ?>; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: <?php echo esc_attr( $settings['body_text_size'] . 'px' ); ?>; letter-spacing: -0.24px; line-height: <?php echo esc_attr( floor( $settings['body_text_size'] * 1.625 ) . 'px' ) ?>;" > <p><?php echo $footer_message ; ?></p> <?php $approve_comment = sprintf( __( '<a href="%s">Approve</a>' , 'buddyboss' ), admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ); $trash_comment = '' ; $delete_comment = '' ; $spam_comment = '' ; if ( user_can( $post ->post_author, 'edit_comment' , $comment ->comment_ID ) ) { if ( EMPTY_TRASH_DAYS ) { /* translators: Comment moderation. 1: Comment action URL */ $trash_comment = sprintf( __( '<a href="%s">Trash</a>' , 'buddyboss' ), admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ); } else { /* translators: Comment moderation. 1: Comment action URL */ $delete_comment = sprintf( __( '<a href="%s">Delete</a>' , 'buddyboss' ), admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ); } /* translators: Comment moderation. 1: Comment action URL */ $spam_comment = sprintf( __( '<a href="%s">Spam</a>' , 'buddyboss' ), admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ); } ?> <p><?php echo $moderate_text ; ?><?php echo $approve_comment ; ?><?php if ( ! empty ( $trash_comment ) ) { echo ', ' . $trash_comment ; } ?><?php if ( ! empty ( $delete_comment ) ) { echo ', ' . $delete_comment ; } ?><?php if ( ! empty ( $spam_comment ) ) { echo ', ' . $spam_comment ; } ?></p> </div> </td> </tr> </table> <?php $notify_message = ob_get_clean(); $wp_email = 'wordpress@' . preg_replace( '#^www\.#' , '' , strtolower ( $_SERVER [ 'SERVER_NAME' ])); if ( '' == $comment ->comment_author ) { $from = "From: \"$blogname\" <$wp_email>" ; if ( '' != $comment ->comment_author_email ) $reply_to = "Reply-To: $comment->comment_author_email" ; } else { $from = "From: \"$comment->comment_author\" <$wp_email>" ; if ( '' != $comment ->comment_author_email ) $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>" ; } $message_headers = "$from\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n" ; if ( isset( $reply_to ) ) $message_headers .= $reply_to . "\n" ; /** * Filters the comment notification email text. * * @since BuddyPress 1.5.2 * * @param string $notify_message The comment notification email text. * @param int $comment_id Comment ID. */ $notify_message = apply_filters( 'comment_notification_text' , $notify_message , $comment ->comment_ID ); /** * Filters the comment notification email subject. * * @since BuddyPress 1.5.2 * * @param string $subject The comment notification email subject. * @param int $comment_id Comment ID. */ $subject = apply_filters( 'comment_notification_subject' , $subject , $comment ->comment_ID ); /** * Filters the comment notification email headers. * * @since BuddyPress 1.5.2 * * @param string $message_headers Headers for the comment notification email. * @param int $comment_id Comment ID. */ $message_headers = apply_filters( 'comment_notification_headers' , $message_headers , $comment ->comment_ID ); add_filter( 'wp_mail_content_type' , 'bp_email_set_content_type' ); foreach ( $emails as $email ) { $email_notify_message = bp_email_core_wp_get_template( $notify_message , get_user_by( 'email' , $email ) ); @wp_mail( $email , wp_specialchars_decode( $subject ), $email_notify_message , $message_headers ); } remove_filter( 'wp_mail_content_type' , 'bp_email_set_content_type' ); if ( $switched_locale ) { restore_previous_locale(); } return true; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.