Make WordPress Core

Ticket #49715: 49715.4.diff

File 49715.4.diff, 11.4 KB (added by audrasjb, 5 years ago)

Add extensibility via filters and action hooks

  • src/wp-admin/includes/class-wp-comments-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php
    index e3678b60d5..dd02be9c46 100644
    a b class WP_Comments_List_Table extends WP_List_Table { 
    124124                        $start += $_REQUEST['offset'];
    125125                }
    126126
     127                if ( ! empty( $_REQUEST['mode'] ) ) {
     128                        $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
     129                        set_user_setting( 'posts_list_mode', $mode );
     130                } else {
     131                        $mode = get_user_setting( 'posts_list_mode', 'list' );
     132                }
     133
    127134                $status_map = array(
    128135                        'mine'      => '',
    129136                        'moderated' => 'hold',
    class WP_Comments_List_Table extends WP_List_Table { 
    751758                /** This filter is documented in wp-admin/includes/dashboard.php */
    752759                $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
    753760
     761                $mode           = get_user_setting( 'posts_list_mode', 'list' );
     762                $always_visible = false;
     763                if ( 'extended' === $mode ) {
     764                        $always_visible = true;
     765                }
     766
    754767                $i    = 0;
    755                 $out .= '<div class="row-actions">';
     768                $out .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
    756769                foreach ( $actions as $action => $link ) {
    757770                        ++$i;
    758771                        ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  • src/wp-admin/includes/class-wp-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php
    index 7cf6f0725f..de16e89b32 100644
    a b class WP_List_Table { 
    166166
    167167                if ( empty( $this->modes ) ) {
    168168                        $this->modes = array(
    169                                 'list'    => __( 'List View' ),
    170                                 'excerpt' => __( 'Excerpt View' ),
     169                                'list'  => __( 'Compact view' ),
     170                                'extended' => __( 'Extended view' ),
    171171                        );
    172172                }
    173173        }
    class WP_List_Table { 
    523523                        return '';
    524524                }
    525525
     526                $mode = get_user_setting( 'posts_list_mode', 'list' );
     527                if ( 'extended' === $mode ) {
     528                        $always_visible = true;
     529                }
     530
    526531                $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
    527532                foreach ( $actions as $action => $link ) {
    528533                        ++$i;
    class WP_List_Table { 
    12471252         * @return string[] Array of CSS classes for the table tag.
    12481253         */
    12491254        protected function get_table_classes() {
    1250                 return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
     1255                $mode = get_user_setting( 'posts_list_mode', 'list' );
     1256                /**
     1257                 * Filters the current view mode.
     1258                 *
     1259                 * @since 5.5.0
     1260                 *
     1261                 * @param string $mode The current selected mode. Default value of
     1262                 *                     posts_list_mode user setting.
     1263                 */
     1264                $mode = apply_filters( 'table_view_mode', $mode );
     1265
     1266                $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
     1267
     1268                return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
    12511269        }
    12521270
    12531271        /**
  • src/wp-admin/includes/class-wp-posts-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php
    index 065e5d0382..889a22ae0d 100644
    a b class WP_Posts_List_Table extends WP_List_Table { 
    178178                }
    179179
    180180                if ( ! empty( $_REQUEST['mode'] ) ) {
    181                         $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
     181                        $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
    182182                        set_user_setting( 'posts_list_mode', $mode );
    183183                } else {
    184184                        $mode = get_user_setting( 'posts_list_mode', 'list' );
    class WP_Posts_List_Table extends WP_List_Table { 
    598598         * @return array
    599599         */
    600600        protected function get_table_classes() {
    601                 return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
     601                $mode = get_user_setting( 'posts_list_mode', 'list' );
     602                /**
     603                 * Filters the current view mode.
     604                 *
     605                 * @since 5.5.0
     606                 *
     607                 * @param string $mode The current selected mode. Default value of
     608                 *                     posts_list_mode user setting.
     609                 */
     610                $mode = apply_filters( 'table_view_mode', $mode );
     611
     612                $mode_class = 'extended' === $mode ? 'table-view-extended' : 'table-view-' . $mode;
     613
     614                return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
    602615        }
    603616
    604617        /**
    class WP_Posts_List_Table extends WP_List_Table { 
    10421055                }
    10431056                echo "</strong>\n";
    10441057
    1045                 if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
     1058                if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'extended' === $mode && current_user_can( 'read_post', $post->ID ) ) {
    10461059                        if ( post_password_required( $post ) ) {
    10471060                                echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
    10481061                        } else {
    class WP_Posts_List_Table extends WP_List_Table { 
    11021115                 * @param string  $status      The status text.
    11031116                 * @param WP_Post $post        Post object.
    11041117                 * @param string  $column_name The column name.
    1105                  * @param string  $mode        The list display mode ('excerpt' or 'list').
     1118                 * @param string  $mode        The list display mode ('extended' or 'list').
    11061119                 */
    11071120                $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
    11081121
    class WP_Posts_List_Table extends WP_List_Table { 
    11101123                        echo $status . '<br />';
    11111124                }
    11121125
    1113                 /**
    1114                  * Filters the published time of the post.
    1115                  *
    1116                  * @since 2.5.1
    1117                  * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes.
    1118                  *              The published time and date are both displayed now,
    1119                  *              which is equivalent to the previous 'excerpt' mode.
    1120                  *
    1121                  * @param string  $t_time      The published time.
    1122                  * @param WP_Post $post        Post object.
    1123                  * @param string  $column_name The column name.
    1124                  * @param string  $mode        The list display mode ('excerpt' or 'list').
    1125                  */
    1126                 echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
     1126                if ( 'extended' === $mode || 'excerpt' === $mode ) {
     1127                        /**
     1128                         * Filters the published time of the post.
     1129                         *
     1130                         * If `$mode` equals 'extended', the published time and date are both displayed.
     1131                         * If `$mode` equals 'list' (default), the publish date is displayed, with the
     1132                         * time and date together available as an abbreviation definition.
     1133                         *
     1134                         * @since 2.5.1
     1135                         *
     1136                         * @param string  $t_time      The published time.
     1137                         * @param WP_Post $post        Post object.
     1138                         * @param string  $column_name The column name.
     1139                         * @param string  $mode        The list display mode ('extended' or 'list').
     1140                         */
     1141                        echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
     1142                } else {
     1143                        /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
     1144                        echo '<span title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</span>';
     1145                }
    11271146        }
    11281147
    11291148        /**
    class WP_Posts_List_Table extends WP_List_Table { 
    14511470         *
    14521471         * @since 3.1.0
    14531472         *
    1454          * @global string $mode List table view mode.
     1473         * @global string $mode Compact table view mode.
    14551474         */
    14561475        public function inline_edit() {
    14571476                global $mode;
    class WP_Posts_List_Table extends WP_List_Table { 
    14911510                        }
    14921511                }
    14931512
    1494                 $m            = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
     1513                $m            = ( isset( $mode ) && 'extended' === $mode ) ? 'extended' : 'list';
    14951514                $can_publish  = current_user_can( $post_type_object->cap->publish_posts );
    14961515                $core_columns = array(
    14971516                        'cb'         => true,
  • src/wp-admin/includes/class-wp-screen.php

    diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php
    index e3a2fcd7a6..c06b19902f 100644
    a b final class WP_Screen { 
    12881288        public function render_view_mode() {
    12891289                $screen = get_current_screen();
    12901290
    1291                 // Currently only enabled for posts lists.
    1292                 if ( 'edit' !== $screen->base ) {
     1291                // Currently only enabled for posts and comments lists.
     1292                if ( 'edit' !== $screen->base && 'edit-comments' !== $screen->base && 'users' !== $screen->base ) {
    12931293                        return;
    12941294                }
    12951295
    1296                 $view_mode_post_types = get_post_types(
    1297                         array(
    1298                                 'hierarchical' => false,
    1299                                 'show_ui'      => true,
    1300                         )
    1301                 );
     1296                $view_mode_post_types = get_post_types( array( 'show_ui' => true ) );
    13021297
    13031298                /**
    13041299                 * Filters the post types that have different view mode options.
    final class WP_Screen { 
    13061301                 * @since 4.4.0
    13071302                 *
    13081303                 * @param string[] $view_mode_post_types Array of post types that can change view modes.
    1309                  *                                       Default non-hierarchical post types with show_ui on.
     1304                 *                                       Default post types with show_ui on.
    13101305                 */
    13111306                $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
    13121307
    1313                 if ( ! in_array( $this->post_type, $view_mode_post_types, true ) ) {
     1308                if ( 'edit' === $screen->base && ! in_array( $this->post_type, $view_mode_post_types, true ) ) {
    13141309                        return;
    13151310                }
    13161311
    1317                 global $mode;
     1312                $mode = get_user_setting( 'posts_list_mode', 'list' );
     1313
     1314                // Set 'list' as default value if $mode is not set.
     1315                $mode = ( isset( $mode ) && 'extended' === $mode ) ? 'extended' : 'list';
     1316
     1317                /**
     1318                 * Filters the current view mode.
     1319                 *
     1320                 * @since 5.5.0
     1321                 *
     1322                 * @param string $mode The current selected mode. Default value of
     1323                 *                     posts_list_mode user setting.
     1324                 */
     1325                $mode = apply_filters( 'table_view_mode', $mode );
    13181326
    13191327                // This needs a submit button.
    13201328                add_filter( 'screen_options_show_submit', '__return_true' );
    final class WP_Screen { 
    13231331                <legend><?php _e( 'View Mode' ); ?></legend>
    13241332                                <label for="list-view-mode">
    13251333                                        <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> />
    1326                                         <?php _e( 'List View' ); ?>
     1334                                        <?php _e( 'Compact view' ); ?>
    13271335                                </label>
    13281336                                <label for="excerpt-view-mode">
    1329                                         <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> />
    1330                                         <?php _e( 'Excerpt View' ); ?>
     1337                                        <input id="excerpt-view-mode" type="radio" name="mode" value="extended" <?php checked( 'extended', $mode ); ?> />
     1338                                        <?php _e( 'Extended View' ); ?>
    13311339                                </label>
     1340                                <?php
     1341                                /**
     1342                                 * Fires at the end of the table view modes screen option.
     1343                                 *
     1344                                 * @since 5.5.0
     1345                                 *
     1346                                 * @param string $mode The currently selected mode.
     1347                                 */
     1348                                do_action( 'wp_table_view_modes', $mode );
     1349                                ?>
    13321350                </fieldset>
    13331351                <?php
    13341352        }
  • src/wp-admin/includes/class-wp-users-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-users-list-table.php b/src/wp-admin/includes/class-wp-users-list-table.php
    index 018654bdd2..731e9304e5 100644
    a b class WP_Users_List_Table extends WP_List_Table { 
    127127                        $args['order'] = $_REQUEST['order'];
    128128                }
    129129
     130                if ( ! empty( $_REQUEST['mode'] ) ) {
     131                        $mode = 'extended' === $_REQUEST['mode'] ? 'extended' : 'list';
     132                        set_user_setting( 'posts_list_mode', $mode );
     133                } else {
     134                        $mode = get_user_setting( 'posts_list_mode', 'list' );
     135                }
     136
    130137                /**
    131138                 * Filters the query arguments used to retrieve users for the current users list table.
    132139                 *