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.

Built from https://develop.svn.wordpress.org/trunk@33270


git-svn-id: http://core.svn.wordpress.org/trunk@33242 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-07-14 17:47:24 +00:00
parent 4f94d3a969
commit 4d34e37311
9 changed files with 242 additions and 353 deletions

View File

@ -462,14 +462,14 @@ class WP_Comments_List_Table extends WP_List_Table {
protected function handle_row_actions( $comment, $column_name, $primary ) {
global $comment_status;
if ( ! $this->user_can ) {
return;
}
if ( $primary !== $column_name ) {
return '';
}
if ( ! $this->user_can ) {
return;
}
$post = get_post();
$the_comment_status = wp_get_comment_status( $comment->comment_ID );

View File

@ -310,7 +310,10 @@ class WP_Links_List_Table extends WP_List_Table {
* @return string Row action output for links.
*/
protected function handle_row_actions( $link, $column_name, $primary ) {
if ( $primary === $column_name ) {
if ( $primary !== $column_name ) {
return '';
}
$edit_link = get_edit_bookmark_link( $link );
$actions = array();
@ -319,4 +322,3 @@ class WP_Links_List_Table extends WP_List_Table {
return $this->row_actions( $actions );
}
}
}

View File

@ -1224,14 +1224,20 @@ class WP_List_Table {
echo '<th scope="row" class="check-column">';
echo $this->column_cb( $item );
echo '</th>';
}
elseif ( method_exists( $this, 'column_' . $column_name ) ) {
} elseif ( method_exists( $this, '_column_' . $column_name ) ) {
echo call_user_func(
array( $this, '_column_' . $column_name ),
$item,
$classes,
$data,
$primary
);
} elseif ( method_exists( $this, 'column_' . $column_name ) ) {
echo "<td $attributes>";
echo call_user_func( array( $this, 'column_' . $column_name ), $item );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
}
else {
} else {
echo "<td $attributes>";
echo $this->column_default( $item, $column_name );
echo $this->handle_row_actions( $item, $column_name, $primary );

View File

@ -647,9 +647,11 @@ class WP_Media_List_Table extends WP_List_Table {
* @return string Row actions output for media attachments.
*/
protected function handle_row_actions( $post, $column_name, $primary ) {
if ( $primary === $column_name ) {
if ( $primary !== $column_name ) {
return '';
}
$att_title = _draft_or_post_title();
return $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
}
}
}

View File

@ -408,61 +408,6 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
}
/**
* Handles columns output for a single row.
*
* @since 4.3.0
* @access public
*
* @param array $item Current site.
*/
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 ( in_array( $column_name, $hidden ) ) {
$classes .= ' hidden';
}
$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>';
} elseif ( 'id' === $column_name ) {
?>
<th scope="row">
<?php echo $item['blog_id'] ?>
</th>
<?php
} elseif ( method_exists( $this, 'column_' . $column_name ) ) {
echo "<td $attributes>";
echo call_user_func( array( $this, 'column_' . $column_name ), $item );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
} else {
echo "<td $attributes>";
echo $this->column_default( $item, $column_name );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
}
}
}
/**
*
* @global string $mode
@ -510,7 +455,10 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
* @return string Row actions output.
*/
protected function handle_row_actions( $blog, $column_name, $primary ) {
if ( $primary === $column_name ) {
if ( $primary !== $column_name ) {
return;
}
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
// Preordered.
@ -570,4 +518,3 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
return $this->row_actions( $actions );
}
}
}

View File

@ -256,6 +256,22 @@ class WP_MS_Users_List_Table extends WP_List_Table {
echo mysql2date( $date, $user->user_registered );
}
/**
* @since 4.3.0
* @access protected
*
* @param WP_User $user
* @param string $classes
* @param string $data
* @param string $primary
*/
protected function _column_blogs( $user, $classes, $data, $primary ) {
echo '<td class="', $classes, ' has-row-actions" ', $data, '>';
echo $this->column_blogs( $user );
echo $this->handle_row_actions( $user, 'blogs', $primary );
echo '</td>';
}
/**
* Handles the blogs/sites column output.
*
@ -335,59 +351,6 @@ class WP_MS_Users_List_Table extends WP_List_Table {
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
}
/**
* Handles columns output for a single row in the table.
*
* @since 4.3.0
* @access public
*
* @param WP_User $item The current WP_User 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 || 'blogs' === $column_name ) {
$classes .= ' has-row-actions';
}
if ( $primary === $column_name ) {
$classes .= ' column-primary';
}
if ( in_array( $column_name, $hidden ) ) {
$classes .= ' hidden';
}
$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>';
} elseif ( method_exists( $this, 'column_' . $column_name ) ) {
echo "<td $attributes>";
call_user_func( array( $this, 'column_' . $column_name ), $item );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
} else {
echo "<td $attributes>";
$this->column_default( $item, $column_name );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
}
}
}
public function display_rows() {
foreach ( $this->items as $user ) {
$class = '';
@ -432,10 +395,13 @@ class WP_MS_Users_List_Table extends WP_List_Table {
* @return string Row actions output for users in Multisite.
*/
protected function handle_row_actions( $user, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$super_admins = get_super_admins();
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
if ( $primary === $column_name ) {
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
@ -456,4 +422,3 @@ class WP_MS_Users_List_Table extends WP_List_Table {
return $this->row_actions( $actions );
}
}
}

View File

@ -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,9 +1048,10 @@ 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 ) {
return '';
}
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();
@ -1106,6 +1071,7 @@ class WP_Posts_List_Table extends WP_List_Table {
}
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 ) );
@ -1152,7 +1118,6 @@ class WP_Posts_List_Table extends WP_List_Table {
return $this->row_actions( $actions );
}
}
/**
* Outputs the hidden row displayed when inline editing

View File

@ -396,13 +396,16 @@ class WP_Terms_List_Table extends WP_List_Table {
* @return string Row actions output for terms.
*/
protected function handle_row_actions( $tag, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$taxonomy = $this->screen->taxonomy;
$tax = get_taxonomy( $taxonomy );
$default_term = get_option( 'default_' . $taxonomy );
$edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) );
if ( $primary === $column_name ) {
$actions = array();
if ( current_user_can( $tax->cap->edit_terms ) ) {
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
@ -440,7 +443,6 @@ class WP_Terms_List_Table extends WP_List_Table {
return $this->row_actions( $actions );
}
}
/**
* @param object $tag

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-beta2-33269';
$wp_version = '4.3-beta2-33270';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.