607
614
* @param int $pending_comments Number of pending comments.
609
616
protected function comments_bubble( $post_id, $pending_comments ) {
610
$pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
612
if ( $pending_comments )
615
echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>";
617
if ( $pending_comments )
617
$approved_comments = get_comments_number();
619
$approved_comments_number = number_format_i18n( $approved_comments );
620
$pending_comments_number = number_format_i18n( $pending_comments );
622
$approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number );
623
$approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
624
$pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
626
// No comments at all.
627
if ( ! $approved_comments && ! $pending_comments ) {
628
printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
631
// Approved comments have different display depending on some conditions.
632
} elseif ( $approved_comments ) {
633
printf( '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
634
esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) ),
635
$approved_comments_number,
636
$pending_comments ? $approved_phrase : $approved_only_phrase
639
printf( '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
640
$approved_comments_number,
641
$pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
645
if ( $pending_comments ) {
646
printf( '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
647
esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'moderated' ), admin_url( 'edit-comments.php' ) ) ),
648
$pending_comments_number,
697
730
$page_links = array();
699
$disable_first = $disable_last = '';
700
if ( $current == 1 ) {
701
$disable_first = ' disabled';
703
if ( $current == $total_pages ) {
704
$disable_last = ' disabled';
706
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
707
'first-page' . $disable_first,
708
esc_attr__( 'Go to the first page' ),
709
esc_url( remove_query_arg( 'paged', $current_url ) ),
713
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
714
'prev-page' . $disable_first,
715
esc_attr__( 'Go to the previous page' ),
716
esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
732
$total_pages_before = '<span class="paging-input">';
733
$total_pages_after = '</span>';
735
$disable_first = $disable_last = $disable_prev = $disable_next = false;
737
if ( $current == 1 ) {
738
$disable_first = true;
739
$disable_prev = true;
741
if ( $current == 2 ) {
742
$disable_first = true;
744
if ( $current == $total_pages ) {
745
$disable_last = true;
746
$disable_next = true;
748
if ( $current == $total_pages - 1 ) {
749
$disable_last = true;
752
if ( $disable_first ) {
753
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">«</span>';
755
$page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
756
esc_url( remove_query_arg( 'paged', $current_url ) ),
762
if ( $disable_prev ) {
763
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">‹</span>';
765
$page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
766
esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
767
__( 'Previous page' ),
720
772
if ( 'bottom' == $which ) {
721
$html_current_page = $current;
773
$html_current_page = $current;
774
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
723
$html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' title='%s' type='text' name='paged' value='%s' size='%d' />",
724
'<label for="current-page-selector" class="screen-reader-text">' . __( 'Select Page' ) . '</label>',
725
esc_attr__( 'Current page' ),
776
$html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
777
'<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
727
779
strlen( $total_pages )
730
782
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
731
$page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
733
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
734
'next-page' . $disable_last,
735
esc_attr__( 'Go to the next page' ),
736
esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
740
$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
741
'last-page' . $disable_last,
742
esc_attr__( 'Go to the last page' ),
743
esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
783
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
785
if ( $disable_next ) {
786
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">›</span>';
788
$page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
789
esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
795
if ( $disable_last ) {
796
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">»</span>';
798
$page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
799
esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
747
805
$pagination_links_class = 'pagination-links';
748
806
if ( ! empty( $infinite_scroll ) ) {
853
* Gets the name of the default primary column.
858
* @return string Name of the default primary column, in this case, an empty string.
860
protected function get_default_primary_column_name() {
861
$columns = $this->get_columns();
864
// We need a primary defined so responsive views show something,
865
// so let's fall back to the first non-checkbox column.
866
foreach( $columns as $col => $column_name ) {
867
if ( 'cb' === $col ) {
879
* Gets the name of the primary column.
884
* @return string The name of the primary column.
886
protected function get_primary_column_name() {
887
$columns = $this->get_columns();
888
$default = $this->get_default_primary_column_name();
890
// If the primary column doesn't exist fall back to the
891
// first non-checkbox column.
892
if ( ! isset( $columns[ $default ] ) ) {
893
$default = WP_List_Table::get_default_primary_column_name();
897
* Filter the name of the primary column for the current list table.
901
* @param string $default Column name default for the specific list table, e.g. 'name'.
902
* @param string $context Screen ID for specific list table, e.g. 'plugins'.
904
$column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
906
if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
795
914
* Get a list of all, hidden and sortable columns, with filter applied
802
921
protected function get_column_info() {
803
if ( isset( $this->_column_headers ) )
804
return $this->_column_headers;
922
// $_column_headers is already set / cached
923
if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
924
// Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
925
// In 4.3, we added a fourth argument for primary column.
926
$column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
927
foreach ( $this->_column_headers as $key => $value ) {
928
$column_headers[ $key ] = $value;
931
return $column_headers;
806
934
$columns = get_column_headers( $this->screen );
807
935
$hidden = get_hidden_columns( $this->screen );
884
1015
foreach ( $columns as $column_key => $column_display_name ) {
885
1016
$class = array( 'manage-column', "column-$column_key" );
888
if ( in_array( $column_key, $hidden ) )
889
$style = 'display:none;';
891
$style = ' style="' . $style . '"';
1018
if ( in_array( $column_key, $hidden ) ) {
1019
$class[] = 'hidden';
893
1022
if ( 'cb' == $column_key )
894
1023
$class[] = 'check-column';
895
1024
elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
896
1025
$class[] = 'num';
1027
if ( $column_key === $primary ) {
1028
$class[] = 'column-primary';
898
1031
if ( isset( $sortable[$column_key] ) ) {
899
1032
list( $orderby, $desc_first ) = $sortable[$column_key];
1059
1202
* @param object $item The current item
1061
1204
protected function single_row_columns( $item ) {
1062
list( $columns, $hidden ) = $this->get_column_info();
1205
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1064
1207
foreach ( $columns as $column_name => $column_display_name ) {
1065
$class = "class='$column_name column-$column_name'";
1068
if ( in_array( $column_name, $hidden ) )
1069
$style = ' style="display:none;"';
1071
$attributes = "$class$style";
1208
$classes = "$column_name column-$column_name";
1209
if ( $primary === $column_name ) {
1210
$classes .= ' has-row-actions column-primary';
1213
if ( in_array( $column_name, $hidden ) ) {
1214
$classes .= ' hidden';
1217
// Comments column uses HTML in the display name with screen reader text.
1218
// Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1219
$data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
1221
$attributes = "class='$classes' $data";
1073
1223
if ( 'cb' == $column_name ) {
1074
1224
echo '<th scope="row" class="check-column">';
1075
1225
echo $this->column_cb( $item );
1078
elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1227
} elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1228
echo call_user_func(
1229
array( $this, '_column_' . $column_name ),
1235
} elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1079
1236
echo "<td $attributes>";
1080
1237
echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1238
echo $this->handle_row_actions( $item, $column_name, $primary );
1084
1241
echo "<td $attributes>";
1085
1242
echo $this->column_default( $item, $column_name );
1243
echo $this->handle_row_actions( $item, $column_name, $primary );
1250
* Generates and display row actions links for the list table.
1255
* @param object $item The item being acted upon.
1256
* @param string $column_name Current column name.
1257
* @param string $primary Primary column name.
1258
* @return string The row actions output. In this case, an empty string.
1260
protected function handle_row_actions( $item, $column_name, $primary ) {
1261
return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1092
1265
* Handle an incoming ajax request (called from admin-ajax.php)