mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 12:44:31 +00:00
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@33270 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -697,6 +697,22 @@ class WP_Posts_List_Table extends WP_List_Table {
|
||||
<?php endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.3.0
|
||||
* @access protected
|
||||
*
|
||||
* @param WP_Post $post
|
||||
* @param string $classes
|
||||
* @param string $data
|
||||
* @param string $primary
|
||||
*/
|
||||
protected function _column_title( $post, $classes, $data, $primary ) {
|
||||
echo '<td class="' . $classes . ' page-title" ', $data, '>';
|
||||
echo $this->column_title( $post );
|
||||
echo $this->handle_row_actions( $post, 'title', $primary );
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the title column output.
|
||||
*
|
||||
@@ -972,58 +988,6 @@ class WP_Posts_List_Table extends WP_List_Table {
|
||||
do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles columns output for a single row in the table.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access public
|
||||
*
|
||||
* @param WP_Post $item The current WP_Post object.
|
||||
*/
|
||||
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 ) {
|
||||
$classes .= ' has-row-actions column-primary';
|
||||
}
|
||||
|
||||
if ( 'title' === $column_name ) {
|
||||
$classes .= ' page-title'; // Special addition for title column
|
||||
}
|
||||
|
||||
if ( in_array( $column_name, $hidden ) ) {
|
||||
$classes .= ' hidden';
|
||||
}
|
||||
|
||||
// Comments column uses HTML in the display name with screen reader text.
|
||||
// Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
|
||||
$data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
|
||||
|
||||
$attributes = "class='$classes' $data";
|
||||
|
||||
if ( 'cb' === $column_name ) {
|
||||
echo '<th scope="row" class="check-column">';
|
||||
|
||||
$this->column_cb( $item );
|
||||
|
||||
echo '</th>';
|
||||
} else {
|
||||
echo "<td $attributes>";
|
||||
|
||||
if ( method_exists( $this, 'column_' . $column_name ) ) {
|
||||
call_user_func( array( $this, 'column_' . $column_name ), $item );
|
||||
} else {
|
||||
$this->column_default( $item, $column_name );
|
||||
}
|
||||
|
||||
echo $this->handle_row_actions( $item, $column_name, $primary );
|
||||
echo '</td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @global WP_Post $post
|
||||
*
|
||||
@@ -1084,74 +1048,75 @@ class WP_Posts_List_Table extends WP_List_Table {
|
||||
* @return string Row actions output for posts.
|
||||
*/
|
||||
protected function handle_row_actions( $post, $column_name, $primary ) {
|
||||
$title = _draft_or_post_title();
|
||||
|
||||
if ( $primary === $column_name ) {
|
||||
$post_type_object = get_post_type_object( $post->post_type );
|
||||
$can_edit_post = current_user_can( 'edit_post', $post->ID );
|
||||
$actions = array();
|
||||
|
||||
if ( $can_edit_post && 'trash' != $post->post_status ) {
|
||||
$actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
|
||||
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick Edit' ) . '</a>';
|
||||
}
|
||||
|
||||
if ( current_user_can( 'delete_post', $post->ID ) ) {
|
||||
if ( 'trash' == $post->post_status )
|
||||
$actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash' ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
|
||||
elseif ( EMPTY_TRASH_DAYS )
|
||||
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
|
||||
if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
|
||||
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
|
||||
}
|
||||
|
||||
if ( $post_type_object->public ) {
|
||||
if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
|
||||
if ( $can_edit_post ) {
|
||||
$preview_link = set_url_scheme( get_permalink( $post->ID ) );
|
||||
/** This filter is documented in wp-admin/includes/meta-boxes.php */
|
||||
$preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
|
||||
$actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
|
||||
}
|
||||
} elseif ( 'trash' != $post->post_status ) {
|
||||
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_post_type_hierarchical( $post->post_type ) ) {
|
||||
|
||||
/**
|
||||
* Filter the array of row action links on the Pages list table.
|
||||
*
|
||||
* The filter is evaluated only for hierarchical post types.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param array $actions An array of row action links. Defaults are
|
||||
* 'Edit', 'Quick Edit', 'Restore, 'Trash',
|
||||
* 'Delete Permanently', 'Preview', and 'View'.
|
||||
* @param WP_Post $post The post object.
|
||||
*/
|
||||
$actions = apply_filters( 'page_row_actions', $actions, $post );
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Filter the array of row action links on the Posts list table.
|
||||
*
|
||||
* The filter is evaluated only for non-hierarchical post types.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param array $actions An array of row action links. Defaults are
|
||||
* 'Edit', 'Quick Edit', 'Restore, 'Trash',
|
||||
* 'Delete Permanently', 'Preview', and 'View'.
|
||||
* @param WP_Post $post The post object.
|
||||
*/
|
||||
$actions = apply_filters( 'post_row_actions', $actions, $post );
|
||||
}
|
||||
|
||||
return $this->row_actions( $actions );
|
||||
if ( $primary !== $column_name ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$post_type_object = get_post_type_object( $post->post_type );
|
||||
$can_edit_post = current_user_can( 'edit_post', $post->ID );
|
||||
$actions = array();
|
||||
|
||||
if ( $can_edit_post && 'trash' != $post->post_status ) {
|
||||
$actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
|
||||
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick Edit' ) . '</a>';
|
||||
}
|
||||
|
||||
if ( current_user_can( 'delete_post', $post->ID ) ) {
|
||||
if ( 'trash' == $post->post_status )
|
||||
$actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash' ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
|
||||
elseif ( EMPTY_TRASH_DAYS )
|
||||
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
|
||||
if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
|
||||
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
|
||||
}
|
||||
|
||||
if ( $post_type_object->public ) {
|
||||
$title = _draft_or_post_title();
|
||||
if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
|
||||
if ( $can_edit_post ) {
|
||||
$preview_link = set_url_scheme( get_permalink( $post->ID ) );
|
||||
/** This filter is documented in wp-admin/includes/meta-boxes.php */
|
||||
$preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
|
||||
$actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
|
||||
}
|
||||
} elseif ( 'trash' != $post->post_status ) {
|
||||
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_post_type_hierarchical( $post->post_type ) ) {
|
||||
|
||||
/**
|
||||
* Filter the array of row action links on the Pages list table.
|
||||
*
|
||||
* The filter is evaluated only for hierarchical post types.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param array $actions An array of row action links. Defaults are
|
||||
* 'Edit', 'Quick Edit', 'Restore, 'Trash',
|
||||
* 'Delete Permanently', 'Preview', and 'View'.
|
||||
* @param WP_Post $post The post object.
|
||||
*/
|
||||
$actions = apply_filters( 'page_row_actions', $actions, $post );
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Filter the array of row action links on the Posts list table.
|
||||
*
|
||||
* The filter is evaluated only for non-hierarchical post types.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param array $actions An array of row action links. Defaults are
|
||||
* 'Edit', 'Quick Edit', 'Restore, 'Trash',
|
||||
* 'Delete Permanently', 'Preview', and 'View'.
|
||||
* @param WP_Post $post The post object.
|
||||
*/
|
||||
$actions = apply_filters( 'post_row_actions', $actions, $post );
|
||||
}
|
||||
|
||||
return $this->row_actions( $actions );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user