Make WordPress Core


Ignore:
Timestamp:
05/29/2015 02:40:52 AM (11 years ago)
Author:
helen
Message:

List tables: introduce the concept of a "primary" column.

This becomes the column that contains the row actions, and allows for a more flexibility, particularly with custom post types and list tables. To (re)define the primary column, use the list_table_primary_column filter, which receives the column name and the screen ID as arguments.

props stephdau, DaveAl, jesin.
see #25408.

File:
1 edited

Legend:

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

    r32642 r32644  
    390390                         */
    391391                        $actions = apply_filters( 'user_row_actions', $actions, $user_object );
    392                         $edit .= $this->row_actions( $actions );
    393392
    394393                        // Set up the checkbox ( because the user is editable, otherwise it's empty )
    … …  
    404403                $r = "<tr id='user-$user_object->ID'>";
    405404
    406                 list( $columns, $hidden ) = $this->get_column_info();
     405                list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
    407406
    408407                foreach ( $columns as $column_name => $column_display_name ) {
    409                         $class = "class=\"$column_name column-$column_name\"";
     408                        $classes = "$column_name column-$column_name";
     409                        if ( $primary === $column_name ) {
     410                                $classes .= ' has-row-actions column-primary';
     411                        }
    410412
    411413                        $style = '';
    412                         if ( in_array( $column_name, $hidden ) )
     414                        if ( in_array( $column_name, $hidden ) ) {
    413415                                $style = ' style="display:none;"';
    414 
    415                         $attributes = "$class$style";
    416 
    417                         switch ( $column_name ) {
    418                                 case 'cb':
    419                                         $r .= "<th scope='row' class='check-column'>$checkbox</th>";
    420                                         break;
    421                                 case 'username':
    422                                         $r .= "<td $attributes>$avatar $edit</td>";
    423                                         break;
    424                                 case 'name':
    425                                         $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
    426                                         break;
    427                                 case 'email':
    428                                         $r .= "<td $attributes><a href='mailto:$email' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a></td>";
    429                                         break;
    430                                 case 'role':
    431                                         $r .= "<td $attributes>$role_name</td>";
    432                                         break;
    433                                 case 'posts':
    434                                         $attributes = 'class="posts column-posts num"' . $style;
    435                                         $r .= "<td $attributes>";
    436                                         if ( $numposts > 0 ) {
    437                                                 $r .= "<a href='edit.php?author=$user_object->ID' title='" . esc_attr__( 'View posts by this author' ) . "' class='edit'>";
    438                                                 $r .= $numposts;
    439                                                 $r .= '</a>';
    440                                         } else {
    441                                                 $r .= 0;
    442                                         }
    443                                         $r .= "</td>";
    444                                         break;
    445                                 default:
    446                                         $r .= "<td $attributes>";
    447 
    448                                         /**
    449                                          * Filter the display output of custom columns in the Users list table.
    450                                          *
    451                                          * @since 2.8.0
    452                                          *
    453                                          * @param string $output      Custom column output. Default empty.
    454                                          * @param string $column_name Column name.
    455                                          * @param int    $user_id     ID of the currently-listed user.
    456                                          */
    457                                         $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
    458                                         $r .= "</td>";
     416                        }
     417
     418                        $attributes = "class='$classes'$style";
     419
     420                        if ( 'cb' === $column_name ) {
     421                                $r .= "<th scope='row' class='check-column'>$checkbox</th>";
     422                        } else {
     423                                $r .= "<td $attributes>";
     424                                switch ( $column_name ) {
     425                                        case 'username':
     426                                                $r .= "$avatar $edit";
     427                                                break;
     428                                        case 'name':
     429                                                $r .= "$user_object->first_name $user_object->last_name";
     430                                                break;
     431                                        case 'email':
     432                                                $r .= "<a href='mailto:$email' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a>";
     433                                                break;
     434                                        case 'role':
     435                                                $r .= $role_name;
     436                                                break;
     437                                        case 'posts':
     438                                                $attributes = 'class="posts column-posts num"' . $style;
     439                                                $r .= "";
     440                                                if ( $numposts > 0 ) {
     441                                                        $r .= "<a href='edit.php?author=$user_object->ID' title='" . esc_attr__( 'View posts by this author' ) . "' class='edit'>";
     442                                                        $r .= $numposts;
     443                                                        $r .= '</a>';
     444                                                } else {
     445                                                        $r .= 0;
     446                                                }
     447                                                break;
     448                                        default:
     449                                                /**
     450                                                 * Filter the display output of custom columns in the Users list table.
     451                                                 *
     452                                                 * @since 2.8.0
     453                                                 *
     454                                                 * @param string $output      Custom column output. Default empty.
     455                                                 * @param string $column_name Column name.
     456                                                 * @param int    $user_id     ID of the currently-listed user.
     457                                                 */
     458                                                $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
     459                                }
     460
     461                                if ( $primary === $column_name ) {
     462                                        $r .= $this->row_actions( $actions );
     463                                }
     464                                $r .= "</td>";
    459465                        }
    460466                }
    … …  
    463469                return $r;
    464470        }
     471
     472        /**
     473         * Get name of default primary column
     474         *
     475         * @since 4.3.0
     476         * @access protected
     477         *
     478         * @return string
     479         */
     480        protected function get_default_primary_column_name() {
     481                return 'username';
     482        }
    465483}
Note: See TracChangeset for help on using the changeset viewer.