WordPress.org

Make WordPress Core

Ticket #6286: individual notifications.2.diff

File individual notifications.2.diff, 10.9 KB (added by simonwheatley, 8 years ago)

Individual notifications (removed stray error log calls)

  • Users/simon/Projects/WordPress-Bleeding/site/wp-includes/comment.php

     
    13501350
    13511351                $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
    13521352
    1353                 if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )
     1353                if ( get_user_option('comments_notify', $post->post_author) && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )
    13541354                        wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
    13551355        }
    13561356
     
    13861386                case 'approve':
    13871387                case '1':
    13881388                        $status = '1';
    1389                         if ( get_option('comments_notify') ) {
    1390                                 $comment = get_comment($comment_id);
     1389                        $comment = get_comment($comment_id);
     1390                        $post = get_post($comment->comment_post_ID);
     1391                        if ( get_user_option('comments_notify', $post->post_author) )
    13911392                                wp_notify_postauthor($comment_id, $comment->comment_type);
    1392                         }
    13931393                        break;
    13941394                case 'spam':
    13951395                        $status = 'spam';
     
    15751575        return true;
    15761576}
    15771577
     1578/**
     1579 * Gets the User IDs of the users who should be emailed if a
     1580 * particular comment is held for moderation.
     1581 *
     1582 * @param int $comment_id The ID of the comment we want moderation recipients for
     1583 * @return array An array of WP_User objects
     1584 **/
     1585function wp_get_moderation_recipients( $comment_id ) {
     1586        global $wpdb;
     1587
     1588        $comment = get_comment( $comment_id );
     1589        $post = get_post( $comment->comment_post_ID );
     1590
     1591        // Find the IDs of the users who have requested moderation notifications in
     1592        // one way or another.
     1593        $sql  = " SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s OR ( user_id = %d AND meta_key = %s ) ";
     1594        $moderation_notify = $wpdb->prefix . 'moderation_notify';
     1595        $moderation_notify_all = $wpdb->prefix . 'moderation_notify_all';
     1596        $user_ids = $wpdb->get_col( $wpdb->prepare( $sql, $comments_notify, $post->post_author, $comments_notify_all ) );
     1597
     1598        $user_ids = array_unique( $user_ids );
     1599       
     1600        $users = array();
     1601        foreach ( $user_ids as $user_id )
     1602                $users[] = new WP_User( $user_id );
     1603
     1604        return $users;
     1605}
     1606
    15781607//
    15791608// Ping and trackback functions.
    15801609//
  • Users/simon/Projects/WordPress-Bleeding/site/wp-includes/pluggable.php

     
    11021102function wp_notify_moderator($comment_id) {
    11031103        global $wpdb;
    11041104
    1105         if ( 0 == get_option( 'moderation_notify' ) )
     1105        if ( ! $recipients = wp_get_moderation_recipients( $comment_id ) )
    11061106                return true;
    11071107
     1108        $email_to = array();
     1109        foreach ( $recipients as $recipient )
     1110                $email_to[] = $recipient->user_email;
     1111
    11081112        $comment = get_comment($comment_id);
    11091113        $post = get_post($comment->comment_post_ID);
    1110         $user = get_userdata( $post->post_author );
    1111         // Send to the administation and to the post author if the author can modify the comment.
    1112         $email_to = array( get_option('admin_email') );
    1113         if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) )
    1114                 $email_to[] = $user->user_email;
    11151114
    11161115        $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
    11171116        $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
  • Users/simon/Projects/WordPress-Bleeding/site/wp-admin/includes/schema.php

     
    206206        'use_balanceTags' => 0,
    207207        'use_smilies' => 1,
    208208        'require_name_email' => 1,
    209         'comments_notify' => 1,
    210209        'posts_per_rss' => 10,
    211210        'rss_use_excerpt' => 0,
    212211        'mailserver_url' => 'mail.example.com',
     
    229228        'links_recently_updated_append' => '</em>',
    230229        'links_recently_updated_time' => 120,
    231230        'comment_moderation' => 0,
    232         'moderation_notify' => 1,
    233231        'permalink_structure' => '',
    234232        'gzipcompression' => 0,
    235233        'hack_file' => 0,
  • Users/simon/Projects/WordPress-Bleeding/site/wp-admin/includes/user.php

     
    185185                $user_id = wp_insert_user( get_object_vars( $user ) );
    186186                wp_new_user_notification( $user_id, isset($_POST['send_password']) ? $pass1 : '' );
    187187        }
     188
     189        // Per site email notification settings
     190        // Only change these if the user can moderate comments
     191        if ( user_can( $user_id, 'moderate_comments' ) ) {
     192                // @TODO: Some of these options probably need to be defaulted on when the first user in a site is created
     193                $comments_notify = (bool) @ $_POST['comments_notify'];
     194                $moderation_notify = (bool) @ $_POST['moderation_notify'];
     195                $moderation_notify_all = (bool) @ $_POST['moderation_notify_all'];
     196                update_user_option( $user_id, 'comments_notify', $comments_notify );
     197                update_user_option( $user_id, 'moderation_notify', $moderation_notify );
     198                update_user_option( $user_id, 'moderation_notify_all', $moderation_notify_all );
     199        }
     200
    188201        return $user_id;
    189202}
    190203
  • Users/simon/Projects/WordPress-Bleeding/site/wp-admin/options-discussion.php

     
    113113</fieldset></td>
    114114</tr>
    115115<tr valign="top">
    116 <th scope="row"><?php _e('E-mail me whenever') ?></th>
    117 <td><fieldset><legend class="screen-reader-text"><span><?php _e('E-mail me whenever') ?></span></legend>
    118 <label for="comments_notify">
    119 <input name="comments_notify" type="checkbox" id="comments_notify" value="1" <?php checked('1', get_option('comments_notify')); ?> />
    120 <?php _e('Anyone posts a comment') ?> </label>
    121 <br />
    122 <label for="moderation_notify">
    123 <input name="moderation_notify" type="checkbox" id="moderation_notify" value="1" <?php checked('1', get_option('moderation_notify')); ?> />
    124 <?php _e('A comment is held for moderation') ?> </label>
    125 </fieldset></td>
    126 </tr>
    127 <tr valign="top">
    128116<th scope="row"><?php _e('Before a comment appears') ?></th>
    129117<td><fieldset><legend class="screen-reader-text"><span><?php _e('Before a comment appears') ?></span></legend>
    130118<label for="comment_moderation">
  • Users/simon/Projects/WordPress-Bleeding/site/wp-admin/options.php

     
    5656
    5757$whitelist_options = array(
    5858        'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string' ),
    59         'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
     59        'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
    6060        'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type', 'embed_autourls', 'embed_size_w', 'embed_size_h' ),
    6161        'privacy' => array( 'blog_public' ),
    6262        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ),
  • Users/simon/Projects/WordPress-Bleeding/site/wp-admin/user-edit.php

     
    211211<th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th>
    212212<td><label for="comment_shortcuts"><input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php if ( !empty($profileuser->comment_shortcuts) ) checked('true', $profileuser->comment_shortcuts); ?> /> <?php _e('Enable keyboard shortcuts for comment moderation.'); ?></label> <?php _e('<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>'); ?></td>
    213213</tr>
     214<?php if ( user_can( $profileuser->ID, 'moderate_comments' ) ) : ?>
     215        <input type="hidden" name="email_notifications" value="1" />
     216        <tr valign="top">
     217        <th scope="row"><?php _e('E-mail me whenever') ?></th>
     218        <td><fieldset><legend class="screen-reader-text"><span><?php _e('E-mail me whenever') ?></span></legend>
     219        <label for="comments_notify">
     220        <input name="comments_notify" type="checkbox" id="comments_notify" value="1" <?php checked('1', get_user_option('comments_notify', $profileuser->ID)); ?> />
     221        <?php _e('A comment is posted on one of my posts') ?>
     222        </label>
     223        <br />
     224        <br />
     225        <label for="moderation_notify">
     226        <input name="moderation_notify" type="checkbox" id="moderation_notify" value="1" <?php checked('1', get_user_option('moderation_notify', $profileuser->ID)); ?> />
     227        <?php _e('A comment on one of my posts is held for moderation') ?> </label>
     228        <br />
     229        <label for="moderation_notify_all">
     230        <input name="moderation_notify_all" type="checkbox" id="moderation_notify_all" value="1" <?php checked('1', get_user_option('moderation_notify_all', $profileuser->ID)); ?> />
     231        <?php _e('Any comment is held for moderation') ?> </label>
     232        </fieldset></td>
     233        </tr>
     234<?php endif; // current_user_can moderate_comments ?>
    214235<?php
    215236endif;
    216237do_action('personal_options', $profileuser);