Make WordPress Core


Ignore:
Timestamp:
06/13/2015 05:10:49 PM (11 years ago)
Author:
wonderboymusic
Message:

In WP_MS_Users_List_Table::display_rows():

  • Move the giant switch statement into methods
  • Call ->single_row_columns(), which we now override - there is a small amount of logic that requires overriding, otherwise it is largely the same as the parent method

See #29881.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-ms-users-list-table.php

    r32724 r32757  
    176176
    177177        /**
     178         * @since 4.3.0
     179         *
     180         * @param object $user
     181         */
     182        public function column_cb( $user ) {
     183                ?>
     184                <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
     185                <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
     186                <?php
     187        }
     188
     189        /**
     190         * @since 4.3.0
     191         *
     192         * @param object $user
     193         */
     194        public function column_username( $user ) {
     195                $super_admins = get_super_admins();
     196                $avatar = get_avatar( $user->user_email, 32 );
     197                $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
     198
     199                echo $avatar;
     200
     201                ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
     202                if ( in_array( $user->user_login, $super_admins ) ) {
     203                        echo ' - ' . __( 'Super Admin' );
     204                }
     205                ?></strong>
     206        <?php
     207        }
     208
     209        /**
     210         * @since 4.3.0
     211         *
     212         * @param object $user
     213         */
     214        public function column_name( $user ) {
     215                echo "$user->first_name $user->last_name";
     216        }
     217
     218        /**
     219         * @since 4.3.0
     220         *
     221         * @param object $user
     222         */
     223        public function column_email( $user ) {
     224                echo "<a href='mailto:$user->user_email'>$user->user_email</a>";
     225        }
     226
     227        /**
     228         * @since 4.3.0
    178229         *
    179230         * @global string $mode
    180          */
     231         *
     232         * @param object $user
     233         */
     234        public function column_registered( $user ) {
     235                global $mode;
     236                if ( 'list' == $mode ) {
     237                        $date = __( 'Y/m/d' );
     238                } else {
     239                        $date = __( 'Y/m/d g:i:s a' );
     240                }
     241                echo mysql2date( $date, $user->user_registered );
     242        }
     243
     244        /**
     245         * @since 4.3.0
     246         *
     247         * @param object $user
     248         */
     249        public function column_blogs( $user ) {
     250                $blogs = get_blogs_of_user( $user->ID, true );
     251                if ( ! is_array( $blogs ) ) {
     252                        return;
     253                }
     254
     255                foreach ( $blogs as $val ) {
     256                        if ( ! can_edit_network( $val->site_id ) ) {
     257                                continue;
     258                        }
     259
     260                        $path   = ( $val->path == '/' ) ? '' : $val->path;
     261                        echo '<span class="site-' . $val->site_id . '" >';
     262                        echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
     263                        echo ' <small class="row-actions">';
     264                        $actions = array();
     265                        $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
     266
     267                        $class = '';
     268                        if ( $val->spam == 1 ) {
     269                                $class .= 'site-spammed ';
     270                        }
     271                        if ( $val->mature == 1 ) {
     272                                $class .= 'site-mature ';
     273                        }
     274                        if ( $val->deleted == 1 ) {
     275                                $class .= 'site-deleted ';
     276                        }
     277                        if ( $val->archived == 1 ) {
     278                                $class .= 'site-archived ';
     279                        }
     280
     281                        $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
     282
     283                        /**
     284                         * Filter the action links displayed next the sites a user belongs to
     285                         * in the Network Admin Users list table.
     286                         *
     287                         * @since 3.1.0
     288                         *
     289                         * @param array $actions     An array of action links to be displayed.
     290                         *                           Default 'Edit', 'View'.
     291                         * @param int   $userblog_id The site ID.
     292                         */
     293                        $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
     294
     295                        $i=0;
     296                        $action_count = count( $actions );
     297                        foreach ( $actions as $action => $link ) {
     298                                ++$i;
     299                                $sep = ( $i == $action_count ) ? '' : ' | ';
     300                                echo "<span class='$action'>$link$sep</span>";
     301                        }
     302                        echo '</small></span><br/>';
     303                }
     304        }
     305
     306        /**
     307         * @since 4.3.0
     308         *
     309         * @param object $user
     310         * @param string $column_name
     311         */
     312        public function column_default( $user, $column_name ) {
     313                /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
     314                echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
     315        }
     316
     317        /**
     318         * @since 4.3.0
     319         *
     320         * @param object $item
     321         */
     322        public function single_row_columns( $item ) {
     323                list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
     324
     325                foreach ( $columns as $column_name => $column_display_name ) {
     326                        $classes = "$column_name column-$column_name";
     327                        if ( $primary === $column_name || 'blogs' === $column_name ) {
     328                                $classes .= ' has-row-actions';
     329                        }
     330
     331                        if ( $primary === $column_name ) {
     332                                $classes .= ' column-primary';
     333                        }
     334
     335                        if ( in_array( $column_name, $hidden ) ) {
     336                                $classes .= ' hidden';
     337                        }
     338
     339                        $attributes = "class='$classes'";
     340
     341                        if ( 'cb' === $column_name ) {
     342                                echo '<th scope="row" class="check-column">';
     343
     344                                $this->column_cb( $item );
     345
     346                                echo '</th>';
     347                        } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
     348                                echo "<td $attributes>";
     349
     350                                call_user_func( array( $this, 'column_' . $column_name ), $item );
     351
     352                                echo $this->handle_row_actions( $item, $column_name, $primary );
     353                                echo "</td>";
     354                        } else {
     355                                echo "<td $attributes>";
     356
     357                                $this->column_default( $item, $column_name );
     358
     359                                echo $this->handle_row_actions( $item, $column_name, $primary );
     360                                echo "</td>";
     361                        }
     362                }
     363        }
     364
    181365        public function display_rows() {
    182                 global $mode;
    183 
    184                 $super_admins = get_super_admins();
    185366                foreach ( $this->items as $user ) {
    186367                        $class = '';
    … …  
    189370
    190371                        foreach ( $status_list as $status => $col ) {
    191                                 if ( $user->$status )
     372                                if ( $user->$status ) {
    192373                                        $class .= " $col";
     374                                }
    193375                        }
    194376
    195377                        ?>
    196378                        <tr class="<?php echo trim( $class ); ?>">
    197                         <?php
    198 
    199                         list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
    200 
    201                         foreach ( $columns as $column_name => $column_display_name ) :
    202                                 $classes = "$column_name column-$column_name";
    203                                 if ( $primary === $column_name || 'blogs' === $column_name ) {
    204                                         $classes .= ' has-row-actions';
    205                                 }
    206 
    207                                 if ( $primary === $column_name ) {
    208                                         $classes .= ' column-primary';
    209                                 }
    210 
    211                                 if ( in_array( $column_name, $hidden ) ) {
    212                                         $classes .= ' hidden';
    213                                 }
    214 
    215                                 $attributes = "class='$classes'";
    216 
    217                                 if ( 'cb' === $column_name ){
    218                                         ?>
    219                                         <th scope="row" class="check-column">
    220                                                 <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
    221                                                 <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
    222                                         </th>
    223                                         <?php
    224                                 } else {
    225                                         echo "<td $attributes>";
    226 
    227                                         switch ( $column_name ) {
    228                                                 case 'username':
    229                                                         $avatar = get_avatar( $user->user_email, 32 );
    230                                                         $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
    231 
    232                                                         echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
    233                                                         if ( in_array( $user->user_login, $super_admins ) )
    234                                                                 echo ' - ' . __( 'Super Admin' );
    235                                                         ?></strong>
    236                                                 <?php
    237                                                 break;
    238 
    239                                                 case 'name':
    240                                                         echo "$user->first_name $user->last_name";
    241                                                 break;
    242 
    243                                                 case 'email':
    244                                                         echo "<a href='mailto:$user->user_email'>$user->user_email</a>";
    245                                                 break;
    246 
    247                                                 case 'registered':
    248                                                         if ( 'list' == $mode )
    249                                                                 $date = __( 'Y/m/d' );
    250                                                         else
    251                                                                 $date = __( 'Y/m/d g:i:s a' );
    252 
    253                                                         echo mysql2date( $date, $user->user_registered );
    254                                                 break;
    255 
    256                                                 case 'blogs':
    257                                                         $blogs = get_blogs_of_user( $user->ID, true );
    258                                                         if ( is_array( $blogs ) ) {
    259                                                                 foreach ( (array) $blogs as $key => $val ) {
    260                                                                         if ( !can_edit_network( $val->site_id ) )
    261                                                                                 continue;
    262 
    263                                                                         $path   = ( $val->path == '/' ) ? '' : $val->path;
    264                                                                         echo '<span class="site-' . $val->site_id . '" >';
    265                                                                         echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
    266                                                                         echo ' <small class="row-actions">';
    267                                                                         $actions = array();
    268                                                                         $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
    269 
    270                                                                         $class = '';
    271                                                                         if ( $val->spam == 1 ) {
    272                                                                                 $class .= 'site-spammed ';
    273                                                                         }
    274                                                                         if ( $val->mature == 1 ) {
    275                                                                                 $class .= 'site-mature ';
    276                                                                         }
    277                                                                         if ( $val->deleted == 1 ) {
    278                                                                                 $class .= 'site-deleted ';
    279                                                                         }
    280                                                                         if ( $val->archived == 1 ) {
    281                                                                                 $class .= 'site-archived ';
    282                                                                         }
    283 
    284                                                                         $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
    285 
    286                                                                         /**
    287                                                                          * Filter the action links displayed next the sites a user belongs to
    288                                                                          * in the Network Admin Users list table.
    289                                                                          *
    290                                                                          * @since 3.1.0
    291                                                                          *
    292                                                                          * @param array $actions     An array of action links to be displayed.
    293                                                                          *                           Default 'Edit', 'View'.
    294                                                                          * @param int   $userblog_id The site ID.
    295                                                                          */
    296                                                                         $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
    297 
    298                                                                         $i=0;
    299                                                                         $action_count = count( $actions );
    300                                                                         foreach ( $actions as $action => $link ) {
    301                                                                                 ++$i;
    302                                                                                 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
    303                                                                                 echo "<span class='$action'>$link$sep</span>";
    304                                                                         }
    305                                                                         echo '</small></span><br/>';
    306                                                                 }
    307                                                         }
    308                                                 break;
    309 
    310                                                 default:
    311                                                         /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
    312                                                         echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
    313                                                 break;
    314                                         }
    315 
    316                                         echo $this->handle_row_actions( $user, $column_name, $primary );
    317                                         echo '</td>';
    318                                 }
    319                         endforeach
    320                         ?>
     379                                <?php $this->single_row_columns( $user ); ?>
    321380                        </tr>
    322381                        <?php
Note: See TracChangeset for help on using the changeset viewer.