Make WordPress Core


Ignore:
Timestamp:
07/14/2015 05:46:13 PM (11 years ago)
Author:
wonderboymusic
Message:

List Tables:

  • In ->handle_row_actions(), bail immediately if $primary and $column_name do not match. Saves us a nesting level and avoids declaring code that is unusable.
  • In WP_List_Table::single_row_columns(), allow _column_{$name} to be called dynamically by core to avoid having to override the entirety of ->single_row_columns() in WP_MS_Users_List_Table and WP_Posts_List_Table
  • In WP_MS_Sites_List_Table, id is not a column.

Props wonderboymusic, paulwilde.
Fixes #29881.

File:
1 edited

Legend:

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

    r33266 r33270  
    696696                        <div class="locked-indicator"></div>
    697697                <?php endif;
     698        }
     699
     700        /**
     701         * @since 4.3.0
     702         * @access protected
     703         *
     704         * @param WP_Post $post
     705         * @param string  $classes
     706         * @param string  $data
     707         * @param string  $primary
     708         */
     709        protected function _column_title( $post, $classes, $data, $primary ) {
     710                echo '<td class="' . $classes . ' page-title" ', $data, '>';
     711                echo $this->column_title( $post );
     712                echo $this->handle_row_actions( $post, 'title', $primary );
     713                echo '</td>';
    698714        }
    699715
     
    974990
    975991        /**
    976          * Handles columns output for a single row in the table.
    977          *
    978          * @since 4.3.0
    979          * @access public
    980          *
    981          * @param WP_Post $item The current WP_Post object.
    982          */
    983         public function single_row_columns( $item ) {
    984                 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
    985 
    986                 foreach ( $columns as $column_name => $column_display_name ) {
    987                         $classes = "$column_name column-$column_name";
    988                         if ( $primary === $column_name ) {
    989                                 $classes .= ' has-row-actions column-primary';
    990                         }
    991 
    992                         if ( 'title' === $column_name ) {
    993                                 $classes .= ' page-title'; // Special addition for title column
    994                         }
    995 
    996                         if ( in_array( $column_name, $hidden ) ) {
    997                                 $classes .= ' hidden';
    998                         }
    999 
    1000                         // Comments column uses HTML in the display name with screen reader text.
    1001                         // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
    1002                         $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
    1003 
    1004                         $attributes = "class='$classes' $data";
    1005 
    1006                         if ( 'cb' === $column_name ) {
    1007                                 echo '<th scope="row" class="check-column">';
    1008 
    1009                                 $this->column_cb( $item );
    1010 
    1011                                 echo '</th>';
    1012                         } else {
    1013                                 echo "<td $attributes>";
    1014 
    1015                                 if ( method_exists( $this, 'column_' . $column_name ) ) {
    1016                                         call_user_func( array( $this, 'column_' . $column_name ), $item );
    1017                                 } else {
    1018                                         $this->column_default( $item, $column_name );
    1019                                 }
    1020 
    1021                                 echo $this->handle_row_actions( $item, $column_name, $primary );
    1022                                 echo '</td>';
    1023                         }
    1024                 }
    1025         }
    1026 
    1027         /**
    1028992         * @global WP_Post $post
    1029993         *
     
    10851049         */
    10861050        protected function handle_row_actions( $post, $column_name, $primary ) {
    1087                 $title = _draft_or_post_title();
    1088 
    1089                 if ( $primary === $column_name ) {
    1090                         $post_type_object = get_post_type_object( $post->post_type );
    1091                         $can_edit_post = current_user_can( 'edit_post', $post->ID );
    1092                         $actions = array();
    1093 
    1094                         if ( $can_edit_post && 'trash' != $post->post_status ) {
    1095                                 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
    1096                                 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
     1051                if ( $primary !== $column_name ) {
     1052                        return '';
     1053                }
     1054
     1055                $post_type_object = get_post_type_object( $post->post_type );
     1056                $can_edit_post = current_user_can( 'edit_post', $post->ID );
     1057                $actions = array();
     1058
     1059                if ( $can_edit_post && 'trash' != $post->post_status ) {
     1060                        $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
     1061                        $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
     1062                }
     1063
     1064                if ( current_user_can( 'delete_post', $post->ID ) ) {
     1065                        if ( 'trash' == $post->post_status )
     1066                                $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash' ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
     1067                        elseif ( EMPTY_TRASH_DAYS )
     1068                                $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
     1069                        if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
     1070                                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
     1071                }
     1072
     1073                if ( $post_type_object->public ) {
     1074                        $title = _draft_or_post_title();
     1075                        if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
     1076                                if ( $can_edit_post ) {
     1077                                        $preview_link = set_url_scheme( get_permalink( $post->ID ) );
     1078                                        /** This filter is documented in wp-admin/includes/meta-boxes.php */
     1079                                        $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
     1080                                        $actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
     1081                                }
     1082                        } elseif ( 'trash' != $post->post_status ) {
     1083                                $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
    10971084                        }
    1098 
    1099                         if ( current_user_can( 'delete_post', $post->ID ) ) {
    1100                                 if ( 'trash' == $post->post_status )
    1101                                         $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash' ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
    1102                                 elseif ( EMPTY_TRASH_DAYS )
    1103                                         $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
    1104                                 if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
    1105                                         $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
    1106                         }
    1107 
    1108                         if ( $post_type_object->public ) {
    1109                                 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
    1110                                         if ( $can_edit_post ) {
    1111                                                 $preview_link = set_url_scheme( get_permalink( $post->ID ) );
    1112                                                 /** This filter is documented in wp-admin/includes/meta-boxes.php */
    1113                                                 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
    1114                                                 $actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
    1115                                         }
    1116                                 } elseif ( 'trash' != $post->post_status ) {
    1117                                         $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
    1118                                 }
    1119                         }
    1120 
    1121                         if ( is_post_type_hierarchical( $post->post_type ) ) {
    1122 
    1123                                 /**
    1124                                  * Filter the array of row action links on the Pages list table.
    1125                                  *
    1126                                  * The filter is evaluated only for hierarchical post types.
    1127                                  *
    1128                                  * @since 2.8.0
    1129                                  *
    1130                                  * @param array $actions An array of row action links. Defaults are
    1131                                  *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
    1132                                  *                         'Delete Permanently', 'Preview', and 'View'.
    1133                                  * @param WP_Post $post The post object.
    1134                                  */
    1135                                 $actions = apply_filters( 'page_row_actions', $actions, $post );
    1136                         } else {
    1137 
    1138                                 /**
    1139                                  * Filter the array of row action links on the Posts list table.
    1140                                  *
    1141                                  * The filter is evaluated only for non-hierarchical post types.
    1142                                  *
    1143                                  * @since 2.8.0
    1144                                  *
    1145                                  * @param array $actions An array of row action links. Defaults are
    1146                                  *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
    1147                                  *                         'Delete Permanently', 'Preview', and 'View'.
    1148                                  * @param WP_Post $post The post object.
    1149                                  */
    1150                                 $actions = apply_filters( 'post_row_actions', $actions, $post );
    1151                         }
    1152 
    1153                         return $this->row_actions( $actions );
    1154                 }
     1085                }
     1086
     1087                if ( is_post_type_hierarchical( $post->post_type ) ) {
     1088
     1089                        /**
     1090                         * Filter the array of row action links on the Pages list table.
     1091                         *
     1092                         * The filter is evaluated only for hierarchical post types.
     1093                         *
     1094                         * @since 2.8.0
     1095                         *
     1096                         * @param array $actions An array of row action links. Defaults are
     1097                         *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
     1098                         *                         'Delete Permanently', 'Preview', and 'View'.
     1099                         * @param WP_Post $post The post object.
     1100                         */
     1101                        $actions = apply_filters( 'page_row_actions', $actions, $post );
     1102                } else {
     1103
     1104                        /**
     1105                         * Filter the array of row action links on the Posts list table.
     1106                         *
     1107                         * The filter is evaluated only for non-hierarchical post types.
     1108                         *
     1109                         * @since 2.8.0
     1110                         *
     1111                         * @param array $actions An array of row action links. Defaults are
     1112                         *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
     1113                         *                         'Delete Permanently', 'Preview', and 'View'.
     1114                         * @param WP_Post $post The post object.
     1115                         */
     1116                        $actions = apply_filters( 'post_row_actions', $actions, $post );
     1117                }
     1118
     1119                return $this->row_actions( $actions );
    11551120        }
    11561121
Note: See TracChangeset for help on using the changeset viewer.