Make WordPress Core

Ticket #61146: 61146.diff

File 61146.diff, 2.3 KB (added by realloc, 5 months ago)

Proposal to use a short circuit filter

  • src/wp-admin/network/users.php

    diff --git a/src/wp-admin/network/users.php b/src/wp-admin/network/users.php
    index d0b40e710d..be718ea5cd 100644
    a b if ( isset( $_GET['action'] ) ) { 
    9191                                                                }
    9292
    9393                                                                $userfunction = 'all_spam';
    94                                                                 $blogs        = get_blogs_of_user( $user_id, true );
    9594
    96                                                                 foreach ( (array) $blogs as $details ) {
    97                                                                         if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!
    98                                                                                 update_blog_status( $details->userblog_id, 'spam', '1' );
     95                                                                /**
     96                                                                 * Filters whether the blog status for all of a user's blogs should be updated.
     97                                                                 *
     98                                                                 * @since 6.7
     99                                                                 *
     100                                                                 * @param bool $update_blog_status Whether to update the blog status. Default true.
     101                                                                 */
     102                                                                if ( apply_filters( 'handle_allusers_update_blog_status', true ) ) {
     103                                                                        $blogs = get_blogs_of_user( $user_id, true );
     104
     105                                                                        foreach ( (array) $blogs as $details ) {
     106                                                                                if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!
     107                                                                                        update_blog_status( $details->userblog_id, 'spam', '1' );
     108                                                                                }
    99109                                                                        }
    100110                                                                }
    101111
    if ( isset( $_GET['action'] ) ) { 
    107117
    108118                                                        case 'notspam':
    109119                                                                $user = get_userdata( $user_id );
     120                                                                if ( is_super_admin( $user->ID ) ) {
     121                                                                        wp_die(
     122                                                                                sprintf(
     123                                                                                /* translators: %s: User login. */
     124                                                                                        __( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
     125                                                                                        esc_html( $user->user_login )
     126                                                                                )
     127                                                                        );
     128                                                                }
    110129
    111130                                                                $userfunction = 'all_notspam';
    112                                                                 $blogs        = get_blogs_of_user( $user_id, true );
    113131
    114                                                                 foreach ( (array) $blogs as $details ) {
    115                                                                         update_blog_status( $details->userblog_id, 'spam', '0' );
     132                                                                /** This filter is documented in wp-admin/network/users.php#L95 */
     133                                                                if ( apply_filters( 'handle_allusers_blog_status', true ) ) {
     134                                                                        $blogs = get_blogs_of_user( $user_id, true );
     135
     136                                                                        foreach ( (array) $blogs as $details ) {
     137                                                                                if ( ! is_main_site( $details->userblog_id ) ) { // Main site is never a spam!
     138                                                                                        update_blog_status( $details->userblog_id, 'spam', '0' );
     139                                                                                }
     140                                                                        }
    116141                                                                }
    117142
    118143                                                                $user_data         = $user->to_array();