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.

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


git-svn-id: http://core.svn.wordpress.org/trunk@32614 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2015-05-29 02:41:25 +00:00
parent 282e28ad81
commit 4c0c7fd7ba
12 changed files with 1006 additions and 655 deletions

View File

@ -357,6 +357,18 @@ class WP_Comments_List_Table extends WP_List_Table {
); );
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'comment';
}
public function display() { public function display() {
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
@ -415,62 +427,33 @@ class WP_Comments_List_Table extends WP_List_Table {
echo "</tr>\n"; echo "</tr>\n";
} }
public function column_cb( $comment ) { /**
if ( $this->user_can ) { ?> * Generate and display row actions links
<label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label> *
<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> * @since 4.3.0
<?php * @access protected
} *
* @param object $comment Comment being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
protected function handle_row_actions( $comment, $column_name, $primary ) {
global $comment_status;
if ( ! $this->user_can ) {
return;
} }
/**
*
* @global string $comment_status
* @param object $comment
*/
public function column_comment( $comment ) {
global $comment_status;
$post = get_post(); $post = get_post();
$comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
$the_comment_status = wp_get_comment_status( $comment->comment_ID ); $the_comment_status = wp_get_comment_status( $comment->comment_ID );
echo '<div class="comment-author">'; $out = '';
$this->column_author( $comment );
echo '</div>';
echo '<div class="submitted-on">'; if( $primary === $column_name ) {
/* translators: 2: comment date, 3: comment time */
printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
/* translators: comment date format. See http://php.net/date */
get_comment_date( __( 'Y/m/d' ) ),
get_comment_date( get_option( 'time_format' ) )
);
if ( $comment->comment_parent ) {
$parent = get_comment( $comment->comment_parent );
$parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
$name = get_comment_author( $parent->comment_ID );
printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
}
echo '</div>';
comment_text();
if ( $this->user_can ) { ?>
<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
<textarea class="comment" rows="1" cols="1"><?php
/** This filter is documented in wp-admin/includes/comment.php */
echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) );
?></textarea>
<div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
<div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
<div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
</div>
<?php
}
if ( $this->user_can ) {
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
@ -536,7 +519,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$i = 0; $i = 0;
echo '<div class="row-actions">'; $out .= '<div class="row-actions">';
foreach ( $actions as $action => $link ) { foreach ( $actions as $action => $link ) {
++$i; ++$i;
( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
@ -551,9 +534,67 @@ class WP_Comments_List_Table extends WP_List_Table {
$action .= ' unapprove'; $action .= ' unapprove';
} }
echo "<span class='$action'>$sep$link</span>"; $out .= "<span class='$action'>$sep$link</span>";
} }
$out .= '</div>';
}
return $out;
}
public function column_cb( $comment ) {
if ( $this->user_can ) { ?>
<label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
<?php
}
}
/**
*
* @global string $comment_status
* @param object $comment
*/
public function column_comment( $comment ) {
global $comment_status;
$post = get_post();
$comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
$the_comment_status = wp_get_comment_status( $comment->comment_ID );
echo '<div class="comment-author">';
$this->column_author( $comment );
echo '</div>'; echo '</div>';
echo '<div class="submitted-on">';
/* translators: 2: comment date, 3: comment time */
printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
/* translators: comment date format. See http://php.net/date */
get_comment_date( __( 'Y/m/d' ) ),
get_comment_date( get_option( 'time_format' ) )
);
if ( $comment->comment_parent ) {
$parent = get_comment( $comment->comment_parent );
$parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
$name = get_comment_author( $parent->comment_ID );
printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
}
echo '</div>';
comment_text();
if ( $this->user_can ) { ?>
<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
<textarea class="comment" rows="1" cols="1"><?php
/** This filter is documented in wp-admin/includes/comment.php */
echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) );
?></textarea>
<div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
<div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
<div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
</div>
<?php
} }
} }

View File

@ -120,6 +120,18 @@ class WP_Links_List_Table extends WP_List_Table {
); );
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'name';
}
/** /**
* *
* @global int $cat_id * @global int $cat_id
@ -142,41 +154,39 @@ class WP_Links_List_Table extends WP_List_Table {
<tr id="link-<?php echo $link->link_id; ?>"> <tr id="link-<?php echo $link->link_id; ?>">
<?php <?php
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$class = "class='column-$column_name'"; $classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
$attributes = $class . $style; $attributes = "class='$classes'$style";
switch ( $column_name ) { if ( 'cb' === $column_name ) {
case 'cb': ?> ?>
<th scope="row" class="check-column"> <th scope="row" class="check-column">
<label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label> <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
<input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
</th> </th>
<?php <?php
break; } else {
echo "<td $attributes>";
switch ( $column_name ) {
case 'name': case 'name':
echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />"; echo "<strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />";
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>";
echo $this->row_actions( $actions );
echo '</td>';
break; break;
case 'url': case 'url':
echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>"; echo "<a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a>";
break; break;
case 'categories': case 'categories':
?><td <?php echo $attributes ?>><?php
$cat_names = array(); $cat_names = array();
foreach ( $link->link_category as $category ) { foreach ( $link->link_category as $category ) {
$cat = get_term( $category, 'link_category', OBJECT, 'display' ); $cat = get_term( $category, 'link_category', OBJECT, 'display' );
@ -188,20 +198,17 @@ class WP_Links_List_Table extends WP_List_Table {
$cat_names[] = $cat_name; $cat_names[] = $cat_name;
} }
echo implode( ', ', $cat_names ); echo implode( ', ', $cat_names );
?></td><?php
break; break;
case 'rel': case 'rel':
?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
break; break;
case 'visible': case 'visible':
?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php echo $visible;
break; break;
case 'rating': case 'rating':
?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php echo $rating;
break; break;
default: default:
?>
<td <?php echo $attributes ?>><?php
/** /**
* Fires for each registered custom link column. * Fires for each registered custom link column.
* *
@ -211,14 +218,39 @@ class WP_Links_List_Table extends WP_List_Table {
* @param int $link_id Link ID. * @param int $link_id Link ID.
*/ */
do_action( 'manage_link_custom_column', $column_name, $link->link_id ); do_action( 'manage_link_custom_column', $column_name, $link->link_id );
?></td>
<?php
break; break;
} }
echo $this->handle_row_actions( $link, $column_name, $primary );
echo '</td>';
}
} }
?> ?>
</tr> </tr>
<?php <?php
} }
} }
/**
* Generate and display row actions links
*
* @since 4.3
* @access protected
*
* @param object $link Link being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
protected function handle_row_actions( $link, $column_name, $primary ) {
if( $primary === $column_name ) {
$edit_link = get_edit_bookmark_link( $link );
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm( '" . esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name)) . "' ) ) { return true;}return false;\">" . __('Delete') . "</a>";
return $this->row_actions($actions);
}
}
} }

View File

@ -794,6 +794,46 @@ class WP_List_Table {
return array(); return array();
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return '';
}
/**
* Get name of primary column.
*
* @since 4.3.0
* @access protected
*
* @return string Filtered name of primary column
*/
protected function get_primary_column_name() {
$columns = $this->get_columns();
$default = $this->get_default_primary_column_name();
/**
* Filter the name of the primary column for the current list table, with context as argument (eg: 'plugins').
*
* @since 4.3.0
*
* @param string $default Column name default for the specific list table (eg: 'name')
* @param string $context Screen ID for specific list table (eg: 'plugins')
*/
$column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
$column = $default;
}
return $column;
}
/** /**
* Get a list of all, hidden and sortable columns, with filter applied * Get a list of all, hidden and sortable columns, with filter applied
* *
@ -834,7 +874,8 @@ class WP_List_Table {
$sortable[$id] = $data; $sortable[$id] = $data;
} }
$this->_column_headers = array( $columns, $hidden, $sortable ); $primary = $this->get_primary_column_name();
$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
return $this->_column_headers; return $this->_column_headers;
} }
@ -1062,16 +1103,20 @@ class WP_List_Table {
* @param object $item The current item * @param object $item The current item
*/ */
protected function single_row_columns( $item ) { protected function single_row_columns( $item ) {
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$class = "class='$column_name column-$column_name'"; $classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
$attributes = "$class$style"; $attributes = "class='$classes'$style";
if ( 'cb' == $column_name ) { if ( 'cb' == $column_name ) {
echo '<th scope="row" class="check-column">'; echo '<th scope="row" class="check-column">';
@ -1081,16 +1126,34 @@ class WP_List_Table {
elseif ( method_exists( $this, 'column_' . $column_name ) ) { elseif ( method_exists( $this, 'column_' . $column_name ) ) {
echo "<td $attributes>"; echo "<td $attributes>";
echo call_user_func( array( $this, 'column_' . $column_name ), $item ); echo call_user_func( array( $this, 'column_' . $column_name ), $item );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>"; echo "</td>";
} }
else { else {
echo "<td $attributes>"; echo "<td $attributes>";
echo $this->column_default( $item, $column_name ); echo $this->column_default( $item, $column_name );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>"; echo "</td>";
} }
} }
} }
/**
* Generate and display row actions links
*
* @since 4.3.0
* @access protected
*
* @param object $item Item being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
protected function handle_row_actions( $item, $column_name, $primary ) {
return '';
}
/** /**
* Handle an incoming ajax request (called from admin-ajax.php) * Handle an incoming ajax request (called from admin-ajax.php)
* *

View File

@ -308,19 +308,22 @@ class WP_Media_List_Table extends WP_List_Table {
<tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>"> <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
<?php <?php
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$class = "class='$column_name column-$column_name'"; $classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
$attributes = $class . $style; $attributes = "class='$classes'$style";
switch ( $column_name ) { if ( 'cb' === $column_name ) {
case 'cb':
?> ?>
<th scope="row" class="check-column"> <th scope="row" class="check-column">
<?php if ( $user_can_edit ) { ?> <?php if ( $user_can_edit ) { ?>
@ -329,63 +332,50 @@ foreach ( $columns as $column_name => $column_display_name ) {
<?php } ?> <?php } ?>
</th> </th>
<?php <?php
break; } else {
echo "<td $attributes>";
switch ( $column_name ) {
case 'icon': case 'icon':
list( $mime ) = explode( '/', $post->post_mime_type ); list( $mime ) = explode( '/', $post->post_mime_type );
$attributes = 'class="column-icon media-icon ' . $mime . '-icon"' . $style; $attributes = 'class="column-icon media-icon ' . $mime . '-icon"' . $style;
?>
<td <?php echo $attributes ?>><?php
if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) { if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
if ( $this->is_trash || ! $user_can_edit ) { if ( $this->is_trash || ! $user_can_edit ) {
echo $thumb; echo $thumb;
} else { } else { ?>
?>
<a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"> <a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
<?php echo $thumb; ?> <?php echo $thumb; ?>
</a> </a><?php
}
<?php }
} }
?>
</td>
<?php
break; break;
case 'title': case 'title':
?> ?>
<td <?php echo $attributes ?>><strong> <strong>
<?php if ( $this->is_trash || ! $user_can_edit ) { <?php if ( $this->is_trash || ! $user_can_edit ) {
echo $att_title; echo $att_title;
} else { ?> } else { ?>
<a href="<?php echo get_edit_post_link( $post->ID ); ?>" <a href="<?php echo get_edit_post_link( $post->ID ); ?>"
title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"> title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
<?php echo $att_title; ?></a> <?php echo $att_title; ?></a>
<?php }; <?php }
_media_states( $post ); ?></strong> _media_states( $post ); ?></strong>
<p class="filename"><?php echo wp_basename( $post->guid ); ?></p> <p class="filename"><?php echo wp_basename( $post->guid ); ?></p>
<?php
echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
?>
</td>
<?php <?php
break; break;
case 'author': case 'author':
?>
<td <?php echo $attributes ?>><?php
printf( '<a href="%s">%s</a>', printf( '<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ), esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ),
get_the_author() get_the_author()
); );
?></td>
<?php
break; break;
case 'desc': case 'desc':
?> echo has_excerpt() ? $post->post_excerpt : '';
<td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
<?php
break; break;
case 'date': case 'date':
@ -403,9 +393,8 @@ foreach ( $columns as $column_name => $column_display_name ) {
$h_time = mysql2date( __( 'Y/m/d' ), $m_time ); $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
} }
} }
?>
<td <?php echo $attributes ?>><?php echo $h_time ?></td> echo $h_time;
<?php
break; break;
case 'parent': case 'parent':
@ -418,7 +407,7 @@ foreach ( $columns as $column_name => $column_display_name ) {
$title = _draft_or_post_title( $post->post_parent ); $title = _draft_or_post_title( $post->post_parent );
$parent_type = get_post_type_object( $parent->post_type ); $parent_type = get_post_type_object( $parent->post_type );
?> ?>
<td <?php echo $attributes ?>><strong> <strong>
<?php if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { ?> <?php if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { ?>
<a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"> <a href="<?php echo get_edit_post_link( $post->post_parent ); ?>">
<?php echo $title ?></a><?php <?php echo $title ?></a><?php
@ -434,35 +423,27 @@ foreach ( $columns as $column_name => $column_display_name ) {
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ) '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] )
), 'upload.php' ); ?> ), 'upload.php' ); ?>
<a class="hide-if-no-js detach-from-parent" href="<?php echo $detach_url ?>"><?php _e( 'Detach' ); ?></a> <a class="hide-if-no-js detach-from-parent" href="<?php echo $detach_url ?>"><?php _e( 'Detach' ); ?></a>
<?php endif; ?> <?php endif;
</td>
<?php
} else { } else {
?> _e( '(Unattached)' ); ?><br />
<td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br />
<?php if ( $user_can_edit ) { ?> <?php if ( $user_can_edit ) { ?>
<a class="hide-if-no-js" <a class="hide-if-no-js"
onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' ); return false;" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' ); return false;"
href="#the-list"> href="#the-list">
<?php _e( 'Attach' ); ?></a> <?php _e( 'Attach' ); ?></a>
<?php } ?></td> <?php }
<?php
} }
break; break;
case 'comments': case 'comments':
$attributes = 'class="comments column-comments num"' . $style; echo '<div class="post-com-count-wrapper">';
?>
<td <?php echo $attributes ?>>
<div class="post-com-count-wrapper">
<?php
$pending_comments = get_pending_comments_num( $post->ID );
$pending_comments = get_pending_comments_num( $post->ID );
$this->comments_bubble( $post->ID, $pending_comments ); $this->comments_bubble( $post->ID, $pending_comments );
?>
</div> echo '</div>';
</td>
<?php
break; break;
default: default:
@ -476,7 +457,6 @@ foreach ( $columns as $column_name => $column_display_name ) {
$taxonomy = false; $taxonomy = false;
if ( $taxonomy ) { if ( $taxonomy ) {
echo '<td ' . $attributes . '>';
if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) { if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
$out = array(); $out = array();
foreach ( $terms as $t ) { foreach ( $terms as $t ) {
@ -494,11 +474,10 @@ foreach ( $columns as $column_name => $column_display_name ) {
} else { } else {
echo '&#8212;'; echo '&#8212;';
} }
echo '</td>';
break; break;
} }
?>
<td <?php echo $attributes ?>><?php
/** /**
* Fires for each custom column in the Media list table. * Fires for each custom column in the Media list table.
* *
@ -510,16 +489,33 @@ foreach ( $columns as $column_name => $column_display_name ) {
* @param int $post_id Attachment ID. * @param int $post_id Attachment ID.
*/ */
do_action( 'manage_media_custom_column', $column_name, $post->ID ); do_action( 'manage_media_custom_column', $column_name, $post->ID );
?></td>
<?php
break; break;
} }
if( $primary === $column_name ) {
echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
}
echo '</td>';
}
} }
?> ?>
</tr> </tr>
<?php endwhile; <?php endwhile;
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'title';
}
/** /**
* @param WP_Post $post * @param WP_Post $post
* @param string $att_title * @param string $att_title

View File

@ -246,15 +246,23 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
$blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path']; $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path'];
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$style = ''; $classes = "$column_name column-$column_name";
if ( in_array( $column_name, $hidden ) ) if ( $primary === $column_name ) {
$style = ' style="display:none;"'; $classes .= ' has-row-actions column-primary';
}
switch ( $column_name ) { $style = '';
case 'cb': ?> if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"';
}
$attributes = "class='$classes'$style";
if ( 'cb' === $column_name ) {
?>
<th scope="row" class="check-column"> <th scope="row" class="check-column">
<?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?> <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?>
<label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label> <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label>
@ -262,17 +270,18 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
<?php endif; ?> <?php endif; ?>
</th> </th>
<?php <?php
break; } elseif ( 'id' === $column_name ) {
?>
case 'id':?>
<th scope="row"> <th scope="row">
<?php echo $blog['blog_id'] ?> <?php echo $blog['blog_id'] ?>
</th> </th>
<?php <?php
break; } else {
echo "<td $attributes>";
switch ( $column_name ) {
case 'blogname': case 'blogname':
echo "<td class='column-$column_name $column_name'$style>"; ?> ?>
<a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a> <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
<?php <?php
if ( 'list' != $mode ) { if ( 'list' != $mode ) {
@ -281,6 +290,106 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
echo '<p>' . sprintf( __( '%1$s &#8211; <em>%2$s</em>' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>'; echo '<p>' . sprintf( __( '%1$s &#8211; <em>%2$s</em>' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>';
restore_current_blog(); restore_current_blog();
} }
break;
case 'lastupdated':
echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] );
break;
case 'registered':
if ( $blog['registered'] == '0000-00-00 00:00:00' ) {
echo '&#x2014;';
} else {
echo mysql2date( $date, $blog['registered'] );
}
break;
case 'users':
$blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
if ( is_array( $blogusers ) ) {
$blogusers_warning = '';
if ( count( $blogusers ) > 5 ) {
$blogusers = array_slice( $blogusers, 0, 5 );
$blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
}
foreach ( $blogusers as $user_object ) {
echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
if ( 'list' != $mode )
echo '( ' . $user_object->user_email . ' )';
echo '<br />';
}
if ( $blogusers_warning != '' )
echo '<strong>' . $blogusers_warning . '</strong><br />';
}
break;
case 'plugins':
if ( has_filter( 'wpmublogsaction' ) ) {
/**
* Fires inside the auxiliary 'Actions' column of the Sites list table.
*
* By default this column is hidden unless something is hooked to the action.
*
* @since MU
*
* @param int $blog_id The site ID.
*/
do_action( 'wpmublogsaction', $blog['blog_id'] );
}
break;
default:
/**
* Fires for each registered custom column in the Sites list table.
*
* @since 3.1.0
*
* @param string $column_name The name of the column to display.
* @param int $blog_id The site ID.
*/
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
break;
}
echo $this->handle_row_actions( $blog, $column_name, $primary );
echo '</td>';
}
}
?>
</tr>
<?php
}
}
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'blogname';
}
/**
* Generate and display row actions links
*
* @since 4.3.0
* @access protected
*
* @param object $blog Blog being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
protected function handle_row_actions( $blog, $column_name, $primary ) {
global $current_site;
if ( $primary === $column_name ) {
$blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
// Preordered. // Preordered.
$actions = array( $actions = array(
@ -336,86 +445,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
* or subdirectory multisite install. * or subdirectory multisite install.
*/ */
$actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
echo $this->row_actions( $actions ); return $this->row_actions( $actions );
?>
</td>
<?php
break;
case 'lastupdated':
echo "<td class='$column_name column-$column_name'$style>";
echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
</td>
<?php
break;
case 'registered':
echo "<td class='$column_name column-$column_name'$style>";
if ( $blog['registered'] == '0000-00-00 00:00:00' )
echo '&#x2014;';
else
echo mysql2date( $date, $blog['registered'] );
?>
</td>
<?php
break;
case 'users':
echo "<td class='$column_name column-$column_name'$style>";
$blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
if ( is_array( $blogusers ) ) {
$blogusers_warning = '';
if ( count( $blogusers ) > 5 ) {
$blogusers = array_slice( $blogusers, 0, 5 );
$blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
}
foreach ( $blogusers as $user_object ) {
echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
if ( 'list' != $mode )
echo '( ' . $user_object->user_email . ' )';
echo '<br />';
}
if ( $blogusers_warning != '' )
echo '<strong>' . $blogusers_warning . '</strong><br />';
}
?>
</td>
<?php
break;
case 'plugins': ?>
<?php if ( has_filter( 'wpmublogsaction' ) ) {
echo "<td class='$column_name column-$column_name'$style>";
/**
* Fires inside the auxiliary 'Actions' column of the Sites list table.
*
* By default this column is hidden unless something is hooked to the action.
*
* @since MU
*
* @param int $blog_id The site ID.
*/
do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
</td>
<?php }
break;
default:
echo "<td class='$column_name column-$column_name'$style>";
/**
* Fires for each registered custom column in the Sites list table.
*
* @since 3.1.0
*
* @param string $column_name The name of the column to display.
* @param int $blog_id The site ID.
*/
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
echo "</td>";
break;
}
}
?>
</tr>
<?php
} }
} }
} }

View File

@ -229,6 +229,18 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
); );
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'name';
}
/** /**
* *
* @global array $totals * @global array $totals
@ -400,7 +412,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
echo "<tr id='$id' class='$class'>"; echo "<tr id='$id' class='$class'>";
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$style = ''; $style = '';
@ -413,7 +425,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
break; break;
case 'name': case 'name':
echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>"; echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
if ( $primary === $column_name ) {
echo $this->row_actions($actions, true); echo $this->row_actions($actions, true);
}
echo "</td>"; echo "</td>";
break; break;
case 'description': case 'description':
@ -451,7 +465,11 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
echo implode( ' | ', $theme_meta ); echo implode( ' | ', $theme_meta );
echo "</div></td>"; echo '</div>';
if ( $primary === $column_name ) {
echo $this->row_actions($actions, true);
}
echo '</td>';
break; break;
default: default:
@ -467,6 +485,10 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
* @param WP_Theme $theme Current WP_Theme object. * @param WP_Theme $theme Current WP_Theme object.
*/ */
do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
if ( $primary === $column_name ) {
echo $this->row_actions($actions, true);
}
echo "</td>"; echo "</td>";
} }
} }

View File

@ -180,67 +180,53 @@ class WP_MS_Users_List_Table extends WP_List_Table {
<tr class="<?php echo trim( $class ); ?>"> <tr class="<?php echo trim( $class ); ?>">
<?php <?php
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) : foreach ( $columns as $column_name => $column_display_name ) :
$class = "class='$column_name column-$column_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';
}
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
$attributes = "$class$style"; $attributes = "class='$classes'$style";
switch ( $column_name ) { if ( 'cb' === $column_name ){
case 'cb': ?> ?>
<th scope="row" class="check-column"> <th scope="row" class="check-column">
<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label> <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
<input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" /> <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
</th> </th>
<?php <?php
break; } else {
echo "<td $attributes>";
switch ( $column_name ) {
case 'username': case 'username':
$avatar = get_avatar( $user->user_email, 32 ); $avatar = get_avatar( $user->user_email, 32 );
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
echo "<td $attributes>"; ?> echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
<?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
if ( in_array( $user->user_login, $super_admins ) ) if ( in_array( $user->user_login, $super_admins ) )
echo ' - ' . __( 'Super Admin' ); echo ' - ' . __( 'Super Admin' );
?></strong> ?></strong>
<br/>
<?php
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
}
/**
* Filter the action links displayed under each user
* in the Network Admin Users list table.
*
* @since 3.2.0
*
* @param array $actions An array of action links to be displayed.
* Default 'Edit', 'Delete'.
* @param WP_User $user WP_User object.
*/
$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
echo $this->row_actions( $actions );
?>
</td>
<?php <?php
break; break;
case 'name': case 'name':
echo "<td $attributes>$user->first_name $user->last_name</td>"; echo "$user->first_name $user->last_name";
break; break;
case 'email': case 'email':
echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>"; echo "<a href='mailto:$user->user_email'>$user->user_email</a>";
break; break;
case 'registered': case 'registered':
@ -249,12 +235,11 @@ class WP_MS_Users_List_Table extends WP_List_Table {
else else
$date = __( 'Y/m/d g:i:s a' ); $date = __( 'Y/m/d g:i:s a' );
echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>"; echo mysql2date( $date, $user->user_registered );
break; break;
case 'blogs': case 'blogs':
$blogs = get_blogs_of_user( $user->ID, true ); $blogs = get_blogs_of_user( $user->ID, true );
echo "<td $attributes>";
if ( is_array( $blogs ) ) { if ( is_array( $blogs ) ) {
foreach ( (array) $blogs as $key => $val ) { foreach ( (array) $blogs as $key => $val ) {
if ( !can_edit_network( $val->site_id ) ) if ( !can_edit_network( $val->site_id ) )
@ -305,22 +290,72 @@ class WP_MS_Users_List_Table extends WP_List_Table {
echo '</small></span><br/>'; echo '</small></span><br/>';
} }
} }
?>
</td>
<?php
break; break;
default: default:
echo "<td $attributes>";
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
echo "</td>";
break; break;
} }
echo $this->handle_row_actions( $user, $column_name, $primary );
echo '</td>';
}
endforeach endforeach
?> ?>
</tr> </tr>
<?php <?php
} }
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'username';
}
/**
* Generate and display row actions links
*
* @since 4.3.0
* @access protected
*
* @param object $user User being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
protected function handle_row_actions( $user, $column_name, $primary ) {
$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>';
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
}
/**
* Filter the action links displayed under each user
* in the Network Admin Users list table.
*
* @since 3.2.0
*
* @param array $actions An array of action links to be displayed.
* Default 'Edit', 'Delete'.
* @param WP_User $user WP_User object.
*/
$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
return $this->row_actions( $actions );
}
}
} }

View File

@ -568,24 +568,36 @@ class WP_Plugins_List_Table extends WP_List_Table {
$plugin_slug $plugin_slug
); );
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
$extra_class = ' has-row-actions column-primary';
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
switch ( $column_name ) { switch ( $column_name ) {
case 'cb': case 'cb':
echo "<th scope='row' class='check-column'>$checkbox</th>"; echo "<th scope='row' class='check-column'>$checkbox</th>";
break; break;
case 'name': case 'name':
echo "<td class='plugin-title'$style><strong>$plugin_name</strong>"; if ( $primary === $column_name || ! isset( $columns[ $primary ] ) ) {
echo "<td class='plugin-title $extra_class'$style><strong>$plugin_name</strong>";
echo $this->row_actions( $actions, true ); echo $this->row_actions( $actions, true );
} else {
echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
}
echo "</td>"; echo "</td>";
break; break;
case 'description': case 'description':
echo "<td class='column-description desc'$style> $classes = 'column-description desc';
if ( $primary === $column_name ) {
$classes .= " $extra_class";
}
echo "<td class='$classes'$style>
<div class='plugin-description'>$description</div> <div class='plugin-description'>$description</div>
<div class='$class second plugin-version-author-uri'>"; <div class='$class second plugin-version-author-uri'>";
@ -632,10 +644,18 @@ class WP_Plugins_List_Table extends WP_List_Table {
$plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
echo implode( ' | ', $plugin_meta ); echo implode( ' | ', $plugin_meta );
if ( $primary === $column_name ) {
echo $this->row_actions( $actions, true );
}
echo "</div></td>"; echo "</div></td>";
break; break;
default: default:
echo "<td class='$column_name column-$column_name'$style>"; $classes = "$column_name column-$column_name$class";
if ( $primary === $column_name ) {
$classes .= " $extra_class";
}
echo "<td class='$classes'$style>";
/** /**
* Fires inside each custom column of the Plugins list table. * Fires inside each custom column of the Plugins list table.
@ -647,6 +667,10 @@ class WP_Plugins_List_Table extends WP_List_Table {
* @param array $plugin_data An array of plugin data. * @param array $plugin_data An array of plugin data.
*/ */
do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
if ( $primary === $column_name ) {
echo $this->row_actions( $actions, true );
}
echo "</td>"; echo "</td>";
} }
} }
@ -682,4 +706,16 @@ class WP_Plugins_List_Table extends WP_List_Table {
*/ */
do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
} }
/**
* Get name of default primary column for this specific list table.
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'plugin';
}
} }

View File

@ -684,16 +684,20 @@ class WP_Posts_List_Table extends WP_List_Table {
<tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>"> <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
<?php <?php
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$class = "class=\"$column_name column-$column_name\""; $classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
$attributes = "$class$style"; $attributes = "class='$classes'$style";
switch ( $column_name ) { switch ( $column_name ) {
@ -715,7 +719,8 @@ class WP_Posts_List_Table extends WP_List_Table {
break; break;
case 'title': case 'title':
$attributes = 'class="post-title page-title column-title"' . $style; $classes .= ' page-title'; // Special addition for title column
$attributes = "class='$classes'$style";
if ( $this->hierarchical_display ) { if ( $this->hierarchical_display ) {
if ( 0 == $level && (int) $post->post_parent > 0 ) { if ( 0 == $level && (int) $post->post_parent > 0 ) {
// Sent level 0 by accident, by default, or because we don't know the actual level. // Sent level 0 by accident, by default, or because we don't know the actual level.
@ -772,65 +777,7 @@ class WP_Posts_List_Table extends WP_List_Table {
if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) ) if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
the_excerpt(); the_excerpt();
$actions = array(); echo $this->handle_row_actions( $post, $column_name, $primary );
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&nbsp;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 . '&amp;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 &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
}
} elseif ( 'trash' != $post->post_status ) {
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $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 );
}
echo $this->row_actions( $actions );
get_inline_data( $post ); get_inline_data( $post );
echo '</td>'; echo '</td>';
@ -887,6 +834,7 @@ class WP_Posts_List_Table extends WP_List_Table {
} else { } else {
_e( 'Last Modified' ); _e( 'Last Modified' );
} }
echo $this->handle_row_actions( $post, $column_name, $primary );
echo '</td>'; echo '</td>';
break; break;
@ -898,7 +846,7 @@ class WP_Posts_List_Table extends WP_List_Table {
$this->comments_bubble( $post->ID, $pending_comments ); $this->comments_bubble( $post->ID, $pending_comments );
?> ?>
</div></td> </div><?php echo $this->handle_row_actions( $post, $column_name, $primary ); ?></td>
<?php <?php
break; break;
@ -909,6 +857,7 @@ class WP_Posts_List_Table extends WP_List_Table {
esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )), esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
get_the_author() get_the_author()
); );
echo $this->handle_row_actions( $post, $column_name, $primary );
?></td> ?></td>
<?php <?php
break; break;
@ -949,6 +898,7 @@ class WP_Posts_List_Table extends WP_List_Table {
} else { } else {
echo '&#8212;'; echo '&#8212;';
} }
echo $this->handle_row_actions( $post, $column_name, $primary );
echo '</td>'; echo '</td>';
break; break;
} }
@ -995,6 +945,7 @@ class WP_Posts_List_Table extends WP_List_Table {
* @param int $post_id The current post ID. * @param int $post_id The current post ID.
*/ */
do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID ); do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
echo $this->handle_row_actions( $post, $column_name, $primary );
?></td> ?></td>
<?php <?php
break; break;
@ -1006,6 +957,101 @@ class WP_Posts_List_Table extends WP_List_Table {
$GLOBALS['post'] = $global_post; $GLOBALS['post'] = $global_post;
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return( 'title' );
}
/**
* Generate and display row actions links
*
* @since 4.3.0
* @access protected
*
* @param object $post Post being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
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&nbsp;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 . '&amp;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 &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
}
} elseif ( 'trash' != $post->post_status ) {
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $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 );
}
}
/** /**
* Outputs the hidden row displayed when inline editing * Outputs the hidden row displayed when inline editing
* *

View File

@ -307,9 +307,6 @@ class WP_Terms_List_Table extends WP_List_Table {
*/ */
public function column_name( $tag ) { public function column_name( $tag ) {
$taxonomy = $this->screen->taxonomy; $taxonomy = $this->screen->taxonomy;
$tax = get_taxonomy( $taxonomy );
$default_term = get_option( 'default_' . $taxonomy );
$pad = str_repeat( '&#8212; ', max( 0, $this->level ) ); $pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
@ -333,6 +330,48 @@ class WP_Terms_List_Table extends WP_List_Table {
$out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />'; $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
$out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
$out .= '<div class="name">' . $qe_data->name . '</div>';
/** This filter is documented in wp-admin/edit-tag-form.php */
$out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
$out .= '<div class="parent">' . $qe_data->parent . '</div></div>';
return $out;
}
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'name';
}
/**
* Generate and display row actions links
*
* @since 4.3.0
* @access protected
*
* @param object $tag Tag being acted upon
* @param string $column_name Current column name
* @param string $primary Primary column name
*
* @return string
*/
protected function handle_row_actions( $tag, $column_name, $primary ) {
$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(); $actions = array();
if ( current_user_can( $tax->cap->edit_terms ) ) { if ( current_user_can( $tax->cap->edit_terms ) ) {
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
@ -368,15 +407,8 @@ class WP_Terms_List_Table extends WP_List_Table {
*/ */
$actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
$out .= $this->row_actions( $actions ); return $this->row_actions( $actions );
$out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; }
$out .= '<div class="name">' . $qe_data->name . '</div>';
/** This filter is documented in wp-admin/edit-tag-form.php */
$out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
$out .= '<div class="parent">' . $qe_data->parent . '</div></div>';
return $out;
} }
/** /**

View File

@ -389,7 +389,6 @@ class WP_Users_List_Table extends WP_List_Table {
* @param WP_User $user_object WP_User object for the currently-listed user. * @param WP_User $user_object WP_User object for the currently-listed user.
*/ */
$actions = apply_filters( 'user_row_actions', $actions, $user_object ); $actions = apply_filters( 'user_row_actions', $actions, $user_object );
$edit .= $this->row_actions( $actions );
// Set up the checkbox ( because the user is editable, otherwise it's empty ) // Set up the checkbox ( because the user is editable, otherwise it's empty )
$checkbox = '<label class="screen-reader-text" for="user_' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>' $checkbox = '<label class="screen-reader-text" for="user_' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>'
@ -403,36 +402,41 @@ class WP_Users_List_Table extends WP_List_Table {
$r = "<tr id='user-$user_object->ID'>"; $r = "<tr id='user-$user_object->ID'>";
list( $columns, $hidden ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) { foreach ( $columns as $column_name => $column_display_name ) {
$class = "class=\"$column_name column-$column_name\""; $classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
$style = ''; $style = '';
if ( in_array( $column_name, $hidden ) ) if ( in_array( $column_name, $hidden ) ) {
$style = ' style="display:none;"'; $style = ' style="display:none;"';
}
$attributes = "$class$style"; $attributes = "class='$classes'$style";
switch ( $column_name ) { if ( 'cb' === $column_name ) {
case 'cb':
$r .= "<th scope='row' class='check-column'>$checkbox</th>"; $r .= "<th scope='row' class='check-column'>$checkbox</th>";
break; } else {
$r .= "<td $attributes>";
switch ( $column_name ) {
case 'username': case 'username':
$r .= "<td $attributes>$avatar $edit</td>"; $r .= "$avatar $edit";
break; break;
case 'name': case 'name':
$r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>"; $r .= "$user_object->first_name $user_object->last_name";
break; break;
case 'email': case 'email':
$r .= "<td $attributes><a href='mailto:$email' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a></td>"; $r .= "<a href='mailto:$email' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a>";
break; break;
case 'role': case 'role':
$r .= "<td $attributes>$role_name</td>"; $r .= $role_name;
break; break;
case 'posts': case 'posts':
$attributes = 'class="posts column-posts num"' . $style; $attributes = 'class="posts column-posts num"' . $style;
$r .= "<td $attributes>"; $r .= "";
if ( $numposts > 0 ) { if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' title='" . esc_attr__( 'View posts by this author' ) . "' class='edit'>"; $r .= "<a href='edit.php?author=$user_object->ID' title='" . esc_attr__( 'View posts by this author' ) . "' class='edit'>";
$r .= $numposts; $r .= $numposts;
@ -440,11 +444,8 @@ class WP_Users_List_Table extends WP_List_Table {
} else { } else {
$r .= 0; $r .= 0;
} }
$r .= "</td>";
break; break;
default: default:
$r .= "<td $attributes>";
/** /**
* Filter the display output of custom columns in the Users list table. * Filter the display output of custom columns in the Users list table.
* *
@ -455,6 +456,11 @@ class WP_Users_List_Table extends WP_List_Table {
* @param int $user_id ID of the currently-listed user. * @param int $user_id ID of the currently-listed user.
*/ */
$r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID ); $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
}
if ( $primary === $column_name ) {
$r .= $this->row_actions( $actions );
}
$r .= "</td>"; $r .= "</td>";
} }
} }
@ -462,4 +468,16 @@ class WP_Users_List_Table extends WP_List_Table {
return $r; return $r;
} }
/**
* Get name of default primary column
*
* @since 4.3.0
* @access protected
*
* @return string
*/
protected function get_default_primary_column_name() {
return 'username';
}
} }

View File

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