WordPress.org

Make WordPress Core

Ticket #20007: admin-notifications-4.4.patch

File admin-notifications-4.4.patch, 4.6 KB (added by Veraxus, 3 years ago)

Adds options for admins to toggle admin notifications for new user and password resets.

  • src/wp-admin/includes/schema.php

     
    506506
    507507        // 4.3.0
    508508        'finished_splitting_shared_terms' => 1,
     509
     510        // 4.4
     511        'registration_notify' => 1,
     512        'password_reset_notify' => 1,
    509513        );
    510514
    511515        // 3.3
  • src/wp-admin/options-general.php

     
    8888</fieldset></td>
    8989</tr>
    9090<tr>
     91<th scope="row"><?php _e('Email me whenever'); ?></th>
     92<td><fieldset><legend class="screen-reader-text"><span><?php _e('Email me whenever'); ?></span></legend>
     93<label for="registration_notify">
     94<input name="registration_notify" type="checkbox" id="registration_notify" value="1" <?php checked('1', get_option('registration_notify','1')); ?> />
     95<?php _e('Anyone registers'); ?> </label>
     96<br />
     97<label for="password_reset_notify">
     98<input name="password_reset_notify" type="checkbox" id="password_reset_notify" value="1" <?php checked('1', get_option('password_reset_notify','1')); ?> />
     99<?php _e('Anyone resets their password'); ?> </label>
     100<tr>
    91101<th scope="row"><label for="default_role"><?php _e('New User Default Role') ?></label></th>
    92102<td>
    93103<select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option('default_role') ); ?></select>
  • src/wp-admin/options.php

     
    8282}
    8383
    8484$whitelist_options = array(
    85         'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
     85        'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG', 'registration_notify', 'password_reset_notify' ),
    8686        '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', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
    8787        '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' ),
    8888        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
  • src/wp-includes/pluggable.php

     
    16911691 * @param WP_User $user User object.
    16921692 */
    16931693function wp_password_change_notification( $user ) {
     1694       
    16941695        // send a copy of password change notification to the admin
    1695         // but check to see if it's the admin whose password we're changing, and skip this
    1696         if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
     1696        // but skip if it's the admin whose password we're changing or admin notices are disabled for this
     1697        if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) && '1' === get_option( 'password_reset_notify', '1' ) ) {
    16971698                $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
    16981699                // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    16991700                // we want to reverse this for the plain text arena of emails.
     
    17371738        $message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
    17381739        $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
    17391740        $message .= sprintf(__('Email: %s'), $user->user_email) . "\r\n";
    1740 
    1741         @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
    1742 
     1741       
     1742        // only send the admin notice if new user notifications are enabled
     1743        if ( '1' === get_option( 'registration_notify', '1' ) ) {
     1744                @wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message );
     1745        }
     1746               
    17431747        if ( 'admin' === $notify || empty( $notify ) ) {
    17441748                return;
    17451749        }