Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/users.php

    r39551 r42343  
    1111require_once( dirname( __FILE__ ) . '/admin.php' );
    1212
    13 if ( ! current_user_can( 'manage_network_users' ) )
     13if ( ! current_user_can( 'manage_network_users' ) ) {
    1414    wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
     15}
    1516
    1617if ( isset( $_GET['action'] ) ) {
     
    2021    switch ( $_GET['action'] ) {
    2122        case 'deleteuser':
    22             if ( ! current_user_can( 'manage_network_users' ) )
     23            if ( ! current_user_can( 'manage_network_users' ) ) {
    2324                wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
     25            }
    2426
    2527            check_admin_referer( 'deleteuser' );
     
    2830            if ( $id != '0' && $id != '1' ) {
    2931                $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
    30                 $title = __( 'Users' );
    31                 $parent_file = 'users.php';
     32                $title             = __( 'Users' );
     33                $parent_file       = 'users.php';
    3234                require_once( ABSPATH . 'wp-admin/admin-header.php' );
    3335                echo '<div class="wrap">';
     
    4143
    4244        case 'allusers':
    43             if ( !current_user_can( 'manage_network_users' ) )
     45            if ( ! current_user_can( 'manage_network_users' ) ) {
    4446                wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    45 
    46             if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
     47            }
     48
     49            if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
    4750                check_admin_referer( 'bulk-users-network' );
    4851
    49                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
     52                $doaction     = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    5053                $userfunction = '';
    5154
    5255                foreach ( (array) $_POST['allusers'] as $user_id ) {
    53                     if ( !empty( $user_id ) ) {
     56                    if ( ! empty( $user_id ) ) {
    5457                        switch ( $doaction ) {
    5558                            case 'delete':
    56                                 if ( ! current_user_can( 'delete_users' ) )
     59                                if ( ! current_user_can( 'delete_users' ) ) {
    5760                                    wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    58                                 $title = __( 'Users' );
     61                                }
     62                                $title       = __( 'Users' );
    5963                                $parent_file = 'users.php';
    6064                                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     
    6771                            case 'spam':
    6872                                $user = get_userdata( $user_id );
    69                                 if ( is_super_admin( $user->ID ) )
     73                                if ( is_super_admin( $user->ID ) ) {
    7074                                    wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
     75                                }
    7176
    7277                                $userfunction = 'all_spam';
    73                                 $blogs = get_blogs_of_user( $user_id, true );
     78                                $blogs        = get_blogs_of_user( $user_id, true );
    7479                                foreach ( (array) $blogs as $details ) {
    75                                     if ( $details->userblog_id != get_network()->site_id ) // main blog not a spam !
     80                                    if ( $details->userblog_id != get_network()->site_id ) { // main blog not a spam !
    7681                                        update_blog_status( $details->userblog_id, 'spam', '1' );
     82                                    }
    7783                                }
    7884                                update_user_status( $user_id, 'spam', '1' );
    79                             break;
     85                                break;
    8086
    8187                            case 'notspam':
    8288                                $userfunction = 'all_notspam';
    83                                 $blogs = get_blogs_of_user( $user_id, true );
    84                                 foreach ( (array) $blogs as $details )
     89                                $blogs        = get_blogs_of_user( $user_id, true );
     90                                foreach ( (array) $blogs as $details ) {
    8591                                    update_blog_status( $details->userblog_id, 'spam', '0' );
     92                                }
    8693
    8794                                update_user_status( $user_id, 'spam', '0' );
    88                             break;
     95                                break;
    8996                        }
    9097                    }
     
    102109                }
    103110
    104                 wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
     111                wp_safe_redirect(
     112                    add_query_arg(
     113                        array(
     114                            'updated' => 'true',
     115                            'action'  => $userfunction,
     116                        ), wp_get_referer()
     117                    )
     118                );
    105119            } else {
    106120                $location = network_admin_url( 'users.php' );
    107121
    108                 if ( ! empty( $_REQUEST['paged'] ) )
     122                if ( ! empty( $_REQUEST['paged'] ) ) {
    109123                    $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
     124                }
    110125                wp_redirect( $location );
    111126            }
     
    114129        case 'dodelete':
    115130            check_admin_referer( 'ms-users-delete' );
    116             if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
     131            if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) {
    117132                wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
     133            }
    118134
    119135            if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
    120136                foreach ( $_POST['blog'] as $id => $users ) {
    121137                    foreach ( $users as $blogid => $user_id ) {
    122                         if ( ! current_user_can( 'delete_user', $id ) )
     138                        if ( ! current_user_can( 'delete_user', $id ) ) {
    123139                            continue;
    124 
    125                         if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
     140                        }
     141
     142                        if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) {
    126143                            remove_user_from_blog( $id, $blogid, $user_id );
    127                         else
     144                        } else {
    128145                            remove_user_from_blog( $id, $blogid );
     146                        }
    129147                    }
    130148                }
    131149            }
    132150            $i = 0;
    133             if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
     151            if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) {
    134152                foreach ( $_POST['user'] as $id ) {
    135                     if ( ! current_user_can( 'delete_user', $id ) )
     153                    if ( ! current_user_can( 'delete_user', $id ) ) {
    136154                        continue;
     155                    }
    137156                    wpmu_delete_user( $id );
    138157                    $i++;
    139158                }
    140 
    141             if ( $i == 1 )
     159            }
     160
     161            if ( $i == 1 ) {
    142162                $deletefunction = 'delete';
    143             else
     163            } else {
    144164                $deletefunction = 'all_delete';
    145 
    146             wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
     165            }
     166
     167            wp_redirect(
     168                add_query_arg(
     169                    array(
     170                        'updated' => 'true',
     171                        'action'  => $deletefunction,
     172                    ), network_admin_url( 'users.php' )
     173                )
     174            );
    147175            exit();
    148176    }
    149177}
    150178
    151 $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
    152 $pagenum = $wp_list_table->get_pagenum();
     179$wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' );
     180$pagenum       = $wp_list_table->get_pagenum();
    153181$wp_list_table->prepare_items();
    154182$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
     
    158186    exit;
    159187}
    160 $title = __( 'Users' );
     188$title       = __( 'Users' );
    161189$parent_file = 'users.php';
    162190
    163191add_screen_option( 'per_page' );
    164192
    165 get_current_screen()->add_help_tab( array(
    166     'id'      => 'overview',
    167     'title'   => __('Overview'),
    168     'content' =>
    169         '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
    170         '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
    171         '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
    172         '<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
    173         '<p>' . __('The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.') . '</p>' .
    174         '<p>' . __('You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.') . '</p>'
    175 ) );
     193get_current_screen()->add_help_tab(
     194    array(
     195        'id'      => 'overview',
     196        'title'   => __( 'Overview' ),
     197        'content' =>
     198            '<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' .
     199            '<p>' . __( 'Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.' ) . '</p>' .
     200            '<p>' . __( 'You can also go to the user&#8217;s profile page by clicking on the individual username.' ) . '</p>' .
     201            '<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
     202            '<p>' . __( 'The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.' ) . '</p>' .
     203            '<p>' . __( 'You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.' ) . '</p>',
     204    )
     205);
    176206
    177207get_current_screen()->set_help_sidebar(
    178     '<p><strong>' . __('For more information:') . '</strong></p>' .
    179     '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>') . '</p>' .
    180     '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
     208    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     209    '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' .
     210    '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    181211);
    182212
    183 get_current_screen()->set_screen_reader_content( array(
    184     'heading_views'      => __( 'Filter users list' ),
    185     'heading_pagination' => __( 'Users list navigation' ),
    186     'heading_list'       => __( 'Users list' ),
    187 ) );
     213get_current_screen()->set_screen_reader_content(
     214    array(
     215        'heading_views'      => __( 'Filter users list' ),
     216        'heading_pagination' => __( 'Users list navigation' ),
     217        'heading_list'       => __( 'Users list' ),
     218    )
     219);
    188220
    189221require_once( ABSPATH . 'wp-admin/admin-header.php' );
     
    196228            case 'delete':
    197229                _e( 'User deleted.' );
    198             break;
     230                break;
    199231            case 'all_spam':
    200232                _e( 'Users marked as spam.' );
    201             break;
     233                break;
    202234            case 'all_notspam':
    203235                _e( 'Users removed from spam.' );
    204             break;
     236                break;
    205237            case 'all_delete':
    206238                _e( 'Users deleted.' );
    207             break;
     239                break;
    208240            case 'add':
    209241                _e( 'User added.' );
    210             break;
     242                break;
    211243        }
    212244        ?>
     
    219251
    220252    <?php
    221     if ( current_user_can( 'create_users') ) : ?>
    222         <a href="<?php echo network_admin_url('user-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
     253    if ( current_user_can( 'create_users' ) ) :
     254    ?>
     255        <a href="<?php echo network_admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
     256                            <?php
    223257    endif;
    224258
Note: See TracChangeset for help on using the changeset viewer.