From 4348074f3a75a1d0b29890860e146f5e310114c6 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 13 Jun 2015 17:11:26 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@32757 git-svn-id: http://core.svn.wordpress.org/trunk@32728 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-ms-users-list-table.php | 313 +++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 187 insertions(+), 128 deletions(-) diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php index 0ab08054bc..df5fb66b6a 100644 --- a/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/wp-admin/includes/class-wp-ms-users-list-table.php @@ -175,149 +175,208 @@ class WP_MS_Users_List_Table extends WP_List_Table { } /** + * @since 4.3.0 + * + * @param object $user + */ + public function column_cb( $user ) { + ?> + + + user_email, 32 ); + $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); + + echo $avatar; + + ?>user_login; ?>user_login, $super_admins ) ) { + echo ' - ' . __( 'Super Admin' ); + } + ?> + first_name $user->last_name"; + } + + /** + * @since 4.3.0 + * + * @param object $user + */ + public function column_email( $user ) { + echo "$user->user_email"; + } + + /** + * @since 4.3.0 * * @global string $mode + * + * @param object $user */ - public function display_rows() { + public function column_registered( $user ) { global $mode; + if ( 'list' == $mode ) { + $date = __( 'Y/m/d' ); + } else { + $date = __( 'Y/m/d g:i:s a' ); + } + echo mysql2date( $date, $user->user_registered ); + } - $super_admins = get_super_admins(); + /** + * @since 4.3.0 + * + * @param object $user + */ + public function column_blogs( $user ) { + $blogs = get_blogs_of_user( $user->ID, true ); + if ( ! is_array( $blogs ) ) { + return; + } + + foreach ( $blogs as $val ) { + if ( ! can_edit_network( $val->site_id ) ) { + continue; + } + + $path = ( $val->path == '/' ) ? '' : $val->path; + echo ''; + echo '' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . ''; + echo ' '; + $actions = array(); + $actions['edit'] = '' . __( 'Edit' ) . ''; + + $class = ''; + if ( $val->spam == 1 ) { + $class .= 'site-spammed '; + } + if ( $val->mature == 1 ) { + $class .= 'site-mature '; + } + if ( $val->deleted == 1 ) { + $class .= 'site-deleted '; + } + if ( $val->archived == 1 ) { + $class .= 'site-archived '; + } + + $actions['view'] = '' . __( 'View' ) . ''; + + /** + * Filter the action links displayed next the sites a user belongs to + * in the Network Admin Users list table. + * + * @since 3.1.0 + * + * @param array $actions An array of action links to be displayed. + * Default 'Edit', 'View'. + * @param int $userblog_id The site ID. + */ + $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); + + $i=0; + $action_count = count( $actions ); + foreach ( $actions as $action => $link ) { + ++$i; + $sep = ( $i == $action_count ) ? '' : ' | '; + echo "$link$sep"; + } + echo '
'; + } + } + + /** + * @since 4.3.0 + * + * @param object $user + * @param string $column_name + */ + public function column_default( $user, $column_name ) { + /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ + echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); + } + + /** + * @since 4.3.0 + * + * @param object $item + */ + public function single_row_columns( $item ) { + list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); + + foreach ( $columns as $column_name => $column_display_name ) { + $classes = "$column_name column-$column_name"; + if ( $primary === $column_name || 'blogs' === $column_name ) { + $classes .= ' has-row-actions'; + } + + if ( $primary === $column_name ) { + $classes .= ' column-primary'; + } + + if ( in_array( $column_name, $hidden ) ) { + $classes .= ' hidden'; + } + + $attributes = "class='$classes'"; + + if ( 'cb' === $column_name ) { + echo ''; + + $this->column_cb( $item ); + + echo ''; + } elseif ( method_exists( $this, 'column_' . $column_name ) ) { + echo ""; + + call_user_func( array( $this, 'column_' . $column_name ), $item ); + + echo $this->handle_row_actions( $item, $column_name, $primary ); + echo ""; + } else { + echo ""; + + $this->column_default( $item, $column_name ); + + echo $this->handle_row_actions( $item, $column_name, $primary ); + echo ""; + } + } + } + + public function display_rows() { foreach ( $this->items as $user ) { $class = ''; $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); foreach ( $status_list as $status => $col ) { - if ( $user->$status ) + if ( $user->$status ) { $class .= " $col"; + } } ?> - get_column_info(); - - foreach ( $columns as $column_name => $column_display_name ) : - $classes = "$column_name column-$column_name"; - if ( $primary === $column_name || 'blogs' === $column_name ) { - $classes .= ' has-row-actions'; - } - - if ( $primary === $column_name ) { - $classes .= ' column-primary'; - } - - if ( in_array( $column_name, $hidden ) ) { - $classes .= ' hidden'; - } - - $attributes = "class='$classes'"; - - if ( 'cb' === $column_name ){ - ?> - - - - - "; - - switch ( $column_name ) { - case 'username': - $avatar = get_avatar( $user->user_email, 32 ); - $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); - - echo $avatar; ?>user_login; ?>user_login, $super_admins ) ) - echo ' - ' . __( 'Super Admin' ); - ?> - first_name $user->last_name"; - break; - - case 'email': - echo "$user->user_email"; - break; - - case 'registered': - if ( 'list' == $mode ) - $date = __( 'Y/m/d' ); - else - $date = __( 'Y/m/d g:i:s a' ); - - echo mysql2date( $date, $user->user_registered ); - break; - - case 'blogs': - $blogs = get_blogs_of_user( $user->ID, true ); - if ( is_array( $blogs ) ) { - foreach ( (array) $blogs as $key => $val ) { - if ( !can_edit_network( $val->site_id ) ) - continue; - - $path = ( $val->path == '/' ) ? '' : $val->path; - echo ''; - echo '' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . ''; - echo ' '; - $actions = array(); - $actions['edit'] = '' . __( 'Edit' ) . ''; - - $class = ''; - if ( $val->spam == 1 ) { - $class .= 'site-spammed '; - } - if ( $val->mature == 1 ) { - $class .= 'site-mature '; - } - if ( $val->deleted == 1 ) { - $class .= 'site-deleted '; - } - if ( $val->archived == 1 ) { - $class .= 'site-archived '; - } - - $actions['view'] = '' . __( 'View' ) . ''; - - /** - * Filter the action links displayed next the sites a user belongs to - * in the Network Admin Users list table. - * - * @since 3.1.0 - * - * @param array $actions An array of action links to be displayed. - * Default 'Edit', 'View'. - * @param int $userblog_id The site ID. - */ - $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); - - $i=0; - $action_count = count( $actions ); - foreach ( $actions as $action => $link ) { - ++$i; - ( $i == $action_count ) ? $sep = '' : $sep = ' | '; - echo "$link$sep"; - } - echo '
'; - } - } - break; - - default: - /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ - echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); - break; - } - - echo $this->handle_row_actions( $user, $column_name, $primary ); - echo ''; - } - endforeach - ?> + single_row_columns( $user ); ?>