}
// Empty out the values that may be set
- $phpmailer->ClearAddresses();
$phpmailer->ClearAllRecipients();
$phpmailer->ClearAttachments();
- $phpmailer->ClearBCCs();
- $phpmailer->ClearCCs();
$phpmailer->ClearCustomHeaders();
$phpmailer->ClearReplyTos();
$key = wp_hash($username . $pass_frag . '|' . $expiration, $scheme);
$hash = hash_hmac('md5', $username . '|' . $expiration, $key);
- if ( $hmac != $hash ) {
+ if ( hash_hmac( 'md5', $hmac, $key ) !== hash_hmac( 'md5', $hash, $key ) ) {
do_action('auth_cookie_bad_hash', $cookie_elements);
return false;
}
if ( ! function_exists('wp_notify_postauthor') ) :
/**
- * Notify an author of a comment/trackback/pingback to one of their posts.
+ * Notify an author (and/or others) of a comment/trackback/pingback on a post.
*
* @since 1.0.0
*
* @param int $comment_id Comment ID
- * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback'
- * @return bool False if user email does not exist. True on completion.
+ * @param string $deprecated Not used
+ * @return bool True on completion. False if no email addresses were specified.
*/
-function wp_notify_postauthor( $comment_id, $comment_type = '' ) {
+function wp_notify_postauthor( $comment_id, $deprecated = null ) {
+ if ( null !== $deprecated ) {
+ _deprecated_argument( __FUNCTION__, '3.8' );
+ }
+
$comment = get_comment( $comment_id );
if ( empty( $comment ) )
return false;
$post = get_post( $comment->comment_post_ID );
$author = get_userdata( $post->post_author );
- // The comment was left by the author
- if ( $comment->user_id == $post->post_author )
- return false;
+ // Who to notify? By default, just the post author, but others can be added.
+ $emails = array( $author->user_email );
+
+ /**
+ * Filter the list of emails to receive a comment notification.
+ *
+ * Normally just post authors are notified of emails.
+ * This filter lets you add others.
+ *
+ * @since 3.7.0
+ *
+ * @param array $emails Array of email addresses to receive a comment notification.
+ * @param int $comment_id The comment ID.
+ */
+ $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
+ $emails = array_filter( $emails );
- // The author moderated a comment on his own post
- if ( $post->post_author == get_current_user_id() )
+ // 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 );
+
+ /**
+ * Filter whether to notify comment authors of their comments on their own posts.
+ *
+ * By default, comment authors don't get notified of their comments
+ * on their own post. This lets you override that.
+ *
+ * @since 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_id );
+
+ // The comment was left by the author
+ if ( ! $notify_author && $comment->user_id == $post->post_author ) {
+ unset( $emails[ $author->user_email ] );
+ }
+
+ // The author moderated a comment on their own post
+ if ( ! $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 ( ! user_can( $post->post_author, 'read_post', $post->ID ) )
- return false;
+ if ( ! $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
- if ( '' == $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 );
+ }
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- if ( empty( $comment_type ) ) $comment_type = 'comment';
-
- if ('comment' == $comment_type) {
- $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
- /* translators: 1: comment author, 2: author IP, 3: author domain */
- $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
- $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
- $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
- $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
- $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
- $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
- /* translators: 1: blog name, 2: post title */
- $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
- } elseif ('trackback' == $comment_type) {
- $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
- /* translators: 1: website name, 2: author IP, 3: author domain */
- $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
- $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
- $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
- $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
- /* translators: 1: blog name, 2: post title */
- $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
- } elseif ('pingback' == $comment_type) {
- $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
- /* translators: 1: comment author, 2: author IP, 3: author domain */
- $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
- $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
- $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
- $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
- /* translators: 1: blog name, 2: post title */
- $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
+ switch ( $comment->comment_type ) {
+ case 'trackback':
+ $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
+ /* translators: 1: website name, 2: author IP, 3: author domain */
+ $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
+ $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
+ /* translators: 1: blog name, 2: post title */
+ $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
+ break;
+ case 'pingback':
+ $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
+ /* translators: 1: comment author, 2: author IP, 3: author domain */
+ $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
+ $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
+ /* translators: 1: blog name, 2: post title */
+ $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
+ break;
+ default: // Comments
+ $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
+ /* translators: 1: comment author, 2: author IP, 3: author domain */
+ $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+ $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
+ $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
+ $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
+ /* translators: 1: blog name, 2: post title */
+ $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
+ break;
}
$notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
$notify_message .= sprintf( __('Permalink: %s'), get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ) . "\r\n";
if ( isset($reply_to) )
$message_headers .= $reply_to . "\n";
- $emails = array( $author->user_email );
-
- $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
$notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id );
$subject = apply_filters( 'comment_notification_subject', $subject, $comment_id );
$message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id );
$post = get_post($comment->comment_post_ID);
$user = get_userdata( $post->post_author );
// Send to the administration and to the post author if the author can modify the comment.
- $emails = array( get_option('admin_email') );
- if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) )
- $emails[] = $user->user_email;
+ $emails = array( get_option( 'admin_email' ) );
+ if ( user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
+ if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) )
+ $emails[] = $user->user_email;
+ }
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- switch ($comment->comment_type)
- {
+ switch ( $comment->comment_type ) {
case 'trackback':
$notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
$notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
$notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
$notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
break;
- default: //Comments
+ default: // Comments
$notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
$notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
function wp_password_change_notification(&$user) {
// send a copy of password change notification to the admin
// but check to see if it's the admin whose password we're changing, and skip this
- if ( $user->user_email != get_option('admin_email') ) {
+ if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
$message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
// 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.
if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) )
return false;
- if ( !empty($id_or_email->user_id) ) {
+ if ( ! empty( $id_or_email->user_id ) ) {
$id = (int) $id_or_email->user_id;
$user = get_userdata($id);
- if ( $user)
+ if ( $user )
$email = $user->user_email;
- } elseif ( !empty($id_or_email->comment_author_email) ) {
- $email = $id_or_email->comment_author_email;
}
+
+ if ( ! $email && ! empty( $id_or_email->comment_author_email ) )
+ $email = $id_or_email->comment_author_email;
} else {
$email = $id_or_email;
}