Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/includes/class-wp-ms-sites-list-table.php

    r41289 r42343  
    4040            'spam'     => array( 'site-spammed', _x( 'Spam', 'site' ) ),
    4141            'deleted'  => array( 'site-deleted', __( 'Deleted' ) ),
    42             'mature'   => array( 'site-mature', __( 'Mature' ) )
    43         );
    44 
    45         parent::__construct( array(
    46             'plural' => 'sites',
    47             'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    48         ) );
    49     }
    50 
    51     /**
    52      *
     42            'mature'   => array( 'site-mature', __( 'Mature' ) ),
     43        );
     44
     45        parent::__construct(
     46            array(
     47                'plural' => 'sites',
     48                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     49            )
     50        );
     51    }
     52
     53    /**
    5354     * @return bool
    5455     */
     
    8081        $pagenum = $this->get_pagenum();
    8182
    82         $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
     83        $s    = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
    8384        $wild = '';
    84         if ( false !== strpos($s, '*') ) {
     85        if ( false !== strpos( $s, '*' ) ) {
    8586            $wild = '*';
    86             $s = trim($s, '*');
     87            $s    = trim( $s, '*' );
    8788        }
    8889
     
    9192         * the latest sites with no paging in order to avoid expensive count queries.
    9293         */
    93         if ( !$s && wp_is_large_network() ) {
    94             if ( !isset($_REQUEST['orderby']) )
     94        if ( ! $s && wp_is_large_network() ) {
     95            if ( ! isset( $_REQUEST['orderby'] ) ) {
    9596                $_GET['orderby'] = $_REQUEST['orderby'] = '';
    96             if ( !isset($_REQUEST['order']) )
     97            }
     98            if ( ! isset( $_REQUEST['order'] ) ) {
    9799                $_GET['order'] = $_REQUEST['order'] = 'DESC';
     100            }
    98101        }
    99102
     
    104107        );
    105108
    106         if ( empty($s) ) {
     109        if ( empty( $s ) ) {
    107110            // Nothing to do.
    108111        } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
     
    111114                    preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
    112115            // IPv4 address
    113             $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
     116            $sql          = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
    114117            $reg_blog_ids = $wpdb->get_col( $sql );
    115118
     
    147150
    148151        if ( $order_by ) {
    149             $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
     152            $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
    150153        }
    151154
     
    172175        }
    173176
    174         $total_sites = get_sites( array_merge( $args, array(
    175             'count' => true,
    176             'offset' => 0,
    177             'number' => 0,
    178         ) ) );
    179 
    180         $this->set_pagination_args( array(
    181             'total_items' => $total_sites,
    182             'per_page' => $per_page,
    183         ) );
     177        $total_sites = get_sites(
     178            array_merge(
     179                $args, array(
     180                    'count'  => true,
     181                    'offset' => 0,
     182                    'number' => 0,
     183                )
     184            )
     185        );
     186
     187        $this->set_pagination_args(
     188            array(
     189                'total_items' => $total_sites,
     190                'per_page'    => $per_page,
     191            )
     192        );
    184193    }
    185194
     
    191200
    192201    /**
    193      *
    194202     * @return array
    195203     */
    196204    protected function get_bulk_actions() {
    197205        $actions = array();
    198         if ( current_user_can( 'delete_sites' ) )
     206        if ( current_user_can( 'delete_sites' ) ) {
    199207            $actions['delete'] = __( 'Delete' );
    200         $actions['spam'] = _x( 'Mark as Spam', 'site' );
     208        }
     209        $actions['spam']    = _x( 'Mark as Spam', 'site' );
    201210        $actions['notspam'] = _x( 'Not Spam', 'site' );
    202211
     
    214223        parent::pagination( $which );
    215224
    216         if ( 'top' === $which )
     225        if ( 'top' === $which ) {
    217226            $this->view_switcher( $mode );
     227        }
    218228    }
    219229
     
    267277            $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
    268278        ?>
    269             <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php
    270                 printf( __( 'Select %s' ), $blogname );
    271             ?></label>
    272             <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
    273         <?php endif;
     279            <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>">
     280                                                                    <?php
     281                                                                    printf( __( 'Select %s' ), $blogname );
     282            ?>
     283            </label>
     284            <input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" />
     285        <?php
     286        endif;
    274287    }
    275288
     
    297310        global $mode;
    298311
    299         $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
     312        $blogname    = untrailingslashit( $blog['domain'] . $blog['path'] );
    300313        $blog_states = array();
    301314        reset( $this->status_list );
     
    309322        if ( ! empty( $blog_states ) ) {
    310323            $state_count = count( $blog_states );
    311             $i = 0;
     324            $i           = 0;
    312325            $blog_state .= ' &mdash; ';
    313326            foreach ( $blog_states as $state ) {
    314327                ++$i;
    315                 $sep = ( $i == $state_count ) ? '' : ', ';
     328                $sep         = ( $i == $state_count ) ? '' : ', ';
    316329                $blog_state .= "<span class='post-state'>$state$sep</span>";
    317330            }
     
    394407        $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
    395408        if ( ! $user_count ) {
    396             $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) );
     409            $blog_users = get_users(
     410                array(
     411                    'blog_id' => $blog['blog_id'],
     412                    'fields'  => 'ID',
     413                )
     414            );
    397415            $user_count = count( $blog_users );
    398416            unset( $blog_users );
     
    450468
    451469    /**
    452      *
    453470     * @global string $mode
    454471     */
    455472    public function display_rows() {
    456473        foreach ( $this->items as $blog ) {
    457             $blog = $blog->to_array();
     474            $blog  = $blog->to_array();
    458475            $class = '';
    459476            reset( $this->status_list );
     
    503520        // Preordered.
    504521        $actions = array(
    505             'edit' => '', 'backend' => '',
    506             'activate' => '', 'deactivate' => '',
    507             'archive' => '', 'unarchive' => '',
    508             'spam' => '', 'unspam' => '',
    509             'delete' => '',
    510             'visit' => '',
    511         );
    512 
    513         $actions['edit']    = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>';
    514         $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>';
     522            'edit'       => '',
     523            'backend'    => '',
     524            'activate'   => '',
     525            'deactivate' => '',
     526            'archive'    => '',
     527            'unarchive'  => '',
     528            'spam'       => '',
     529            'unspam'     => '',
     530            'delete'     => '',
     531            'visit'      => '',
     532        );
     533
     534        $actions['edit']    = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>';
     535        $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>';
    515536        if ( get_network()->site_id != $blog['blog_id'] ) {
    516537            if ( $blog['deleted'] == '1' ) {
    517                 $actions['activate']   = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>';
     538                $actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>';
    518539            } else {
    519540                $actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
     
    523544                $actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>';
    524545            } else {
    525                 $actions['archive']   = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>';
     546                $actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>';
    526547            }
    527548
     
    529550                $actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>';
    530551            } else {
    531                 $actions['spam']   = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>';
     552                $actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>';
    532553            }
    533554
     
    537558        }
    538559
    539         $actions['visit']   = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>';
     560        $actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>';
    540561
    541562        /**
Note: See TracChangeset for help on using the changeset viewer.