Skip to content

Commit 0b89da4

Browse files
committed
Add Notes column to posts list table
1 parent 3a265ea commit 0b89da4

File tree

4 files changed

+158
-44
lines changed

4 files changed

+158
-44
lines changed

src/wp-admin/css/list-tables.css

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
}
2626

2727
.column-response .post-com-count-wrapper,
28-
.column-comments .post-com-count-wrapper {
28+
.column-comments .post-com-count-wrapper,
29+
.column-notes .post-com-count-wrapper {
2930
white-space: nowrap;
3031
word-wrap: normal;
3132
}
3233

3334
/* comments bubble common */
3435
.column-response .post-com-count,
35-
.column-comments .post-com-count {
36+
.column-comments .post-com-count,
37+
.column-notes .post-com-count {
3638
display: inline-block;
3739
vertical-align: top;
3840
}
@@ -41,14 +43,16 @@
4143
.column-response .post-com-count-no-comments,
4244
.column-response .post-com-count-approved,
4345
.column-comments .post-com-count-no-comments,
44-
.column-comments .post-com-count-approved {
46+
.column-comments .post-com-count-approved,
47+
.column-notes .post-com-count {
4548
margin-top: 5px;
4649
}
4750

4851
.column-response .comment-count-no-comments,
4952
.column-response .comment-count-approved,
5053
.column-comments .comment-count-no-comments,
51-
.column-comments .comment-count-approved {
54+
.column-comments .comment-count-approved,
55+
.column-notes .comment-count {
5256
box-sizing: border-box;
5357
display: block;
5458
padding: 0 8px;
@@ -65,7 +69,8 @@
6569
.column-response .post-com-count-no-comments:after,
6670
.column-response .post-com-count-approved:after,
6771
.column-comments .post-com-count-no-comments:after,
68-
.column-comments .post-com-count-approved:after {
72+
.column-comments .post-com-count-approved:after,
73+
.notes .post-com-count:after {
6974
content: "";
7075
display: block;
7176
margin-left: 8px;
@@ -78,14 +83,17 @@
7883
.column-response a.post-com-count-approved:hover .comment-count-approved,
7984
.column-response a.post-com-count-approved:focus .comment-count-approved,
8085
.column-comments a.post-com-count-approved:hover .comment-count-approved,
81-
.column-comments a.post-com-count-approved:focus .comment-count-approved {
86+
.column-comments a.post-com-count-approved:focus .comment-count-approved,
87+
.column-notes a.post-com-count:hover .comment-count,
88+
.column-notes a.post-com-count:focus .comment-count {
8289
background: #2271b1;
8390
}
8491

8592
.column-response a.post-com-count-approved:hover:after,
8693
.column-response a.post-com-count-approved:focus:after,
8794
.column-comments a.post-com-count-approved:hover:after,
88-
.column-comments a.post-com-count-approved:focus:after {
95+
.column-comments a.post-com-count-approved:focus:after,
96+
.column-notes a.post-com-count:focus:after {
8997
border-top-color: #2271b1;
9098
}
9199

@@ -299,7 +307,9 @@ table.fixed {
299307
.fixed .column-parent,
300308
.fixed .column-links,
301309
.fixed .column-author,
302-
.fixed .column-format {
310+
.fixed .column-format,
311+
.fixed .column-comments,
312+
.fixed .column-notes {
303313
width: 10%;
304314
}
305315

@@ -342,7 +352,6 @@ table.fixed {
342352
}
343353

344354
.fixed .column-comments {
345-
width: 5.5em;
346355
text-align: left;
347356
}
348357

@@ -2006,29 +2015,34 @@ div.action-links,
20062015
.column-response .post-com-count-no-comments:after,
20072016
.column-response .post-com-count-approved:after,
20082017
.column-comments .post-com-count-no-comments:after,
2009-
.column-comments .post-com-count-approved:after {
2018+
.column-comments .post-com-count-approved:after,
2019+
.column-notes .post-com-count:after {
20102020
content: none;
20112021
}
20122022

20132023
.column-response .post-com-count [aria-hidden="true"],
2014-
.column-comments .post-com-count [aria-hidden="true"] {
2024+
.column-comments .post-com-count [aria-hidden="true"],
2025+
.column-notes .post-com-count [aria-hidden="true"] {
20152026
display: none;
20162027
}
20172028

20182029
.column-response .post-com-count-wrapper,
2019-
.column-comments .post-com-count-wrapper {
2030+
.column-comments .post-com-count-wrapper,
2031+
.column-notes .post-com-count-wrapper {
20202032
white-space: normal;
20212033
}
20222034

20232035
.column-response .post-com-count-wrapper > a,
2024-
.column-comments .post-com-count-wrapper > a {
2036+
.column-comments .post-com-count-wrapper > a,
2037+
.column-notes .post-com-count-wrapper > a {
20252038
display: block;
20262039
}
20272040

20282041
.column-response .post-com-count-no-comments,
20292042
.column-response .post-com-count-approved,
20302043
.column-comments .post-com-count-no-comments,
2031-
.column-comments .post-com-count-approved {
2044+
.column-comments .post-com-count-approved,
2045+
.column-notes .post-com-count {
20322046
margin-top: 0;
20332047
margin-right: 0.5em;
20342048
}

src/wp-admin/includes/class-wp-list-table.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,73 @@ protected function comments_bubble( $post_id, $pending_comments ) {
954954
}
955955
}
956956

957+
/**
958+
* Displays a note count bubble.
959+
*
960+
* @since 3.1.0
961+
*
962+
* @param int $post_id The post ID.
963+
*/
964+
protected function notes_bubble( $post_id ) {
965+
$post_object = get_post( $post_id );
966+
$edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
967+
968+
if ( ! current_user_can( $edit_post_cap, $post_id )
969+
&& ( post_password_required( $post_id )
970+
|| ! current_user_can( 'read_post', $post_id ) )
971+
) {
972+
// The user has no access to the post and thus cannot see the notes.
973+
return false;
974+
}
975+
976+
$args = array(
977+
'type' => 'note',
978+
'count' => true,
979+
'status' => 'any',
980+
'post_id' => $post_id,
981+
);
982+
$args = apply_filters( 'post_column_notes_query_args', $args );
983+
984+
$note_count = get_comments( $args );
985+
$note_count_number = number_format_i18n( $note_count );
986+
987+
$notes_phrase = sprintf(
988+
/* translators: %s: Number of notes. */
989+
_n( '%s note', '%s notes', $note_count ),
990+
$note_count_number
991+
);
992+
993+
if ( ! $note_count ) {
994+
// No notes at all.
995+
printf(
996+
'<span aria-hidden="true">&#8212;</span>' .
997+
'<span class="screen-reader-text">%s</span>',
998+
__( 'No notes' )
999+
);
1000+
} elseif ( $note_count && 'trash' === get_post_status( $post_id ) ) {
1001+
// Don't link the notes bubble for a trashed post.
1002+
printf(
1003+
'<span class="post-com-count">' .
1004+
'<span class="comment-count" aria-hidden="true">%s</span>' .
1005+
'<span class="screen-reader-text">%s</span>' .
1006+
'</span>',
1007+
$note_count_number,
1008+
$notes_phrase
1009+
);
1010+
} else {
1011+
// Link the note bubble to the edit post screen.
1012+
printf(
1013+
'<a href="%s" class="post-com-count">' .
1014+
'<span class="comment-count" aria-hidden="true">%s</span>' .
1015+
'<span class="screen-reader-text">%s</span>' .
1016+
'</a>',
1017+
get_edit_post_link( $post_id ),
1018+
$note_count_number,
1019+
$notes_phrase
1020+
);
1021+
}
1022+
}
1023+
9571024
/**
9581025
* Gets the current page number.
9591026
*

src/wp-admin/includes/class-wp-posts-list-table.php

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,11 @@ public function get_columns() {
705705
if ( post_type_supports( $post_type, 'comments' )
706706
&& ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true )
707707
) {
708-
$posts_columns['comments'] = sprintf(
709-
'<span class="vers comment-grey-bubble" title="%1$s" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span>',
710-
esc_attr__( 'Comments' ),
711-
/* translators: Hidden accessibility text. */
712-
__( 'Comments' )
713-
);
708+
$posts_columns['comments'] = __( 'Comments' );
709+
}
710+
711+
if ( post_type_supports( $post_type, 'editor', 'notes' ) ) {
712+
$posts_columns['notes'] = __( 'Notes' );
714713
}
715714

716715
$posts_columns['date'] = __( 'Date' );
@@ -762,27 +761,19 @@ protected function get_sortable_columns() {
762761

763762
$post_type = $this->screen->post_type;
764763

765-
if ( 'page' === $post_type ) {
766-
if ( isset( $_GET['orderby'] ) ) {
767-
$title_orderby_text = __( 'Table ordered by Title.' );
768-
} else {
769-
$title_orderby_text = __( 'Table ordered by Hierarchical Menu Order and Title.' );
770-
}
764+
$title_orderby_text = __( 'Table ordered by Title.' );
771765

772-
$sortables = array(
773-
'title' => array( 'title', false, __( 'Title' ), $title_orderby_text, 'asc' ),
774-
'parent' => array( 'parent', false ),
775-
'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
776-
'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ) ),
777-
);
778-
} else {
779-
$sortables = array(
780-
'title' => array( 'title', false, __( 'Title' ), __( 'Table ordered by Title.' ) ),
781-
'parent' => array( 'parent', false ),
782-
'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
783-
'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ),
784-
);
766+
if ( 'page' === $post_type && ! isset( $_GET['orderby'] ) ) {
767+
$title_orderby_text = __( 'Table ordered by Hierarchical Menu Order and Title.' );
785768
}
769+
770+
$sortables = array(
771+
'title' => array( 'title', false, __( 'Title' ), $title_orderby_text ),
772+
'parent' => array( 'parent', false ),
773+
'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
774+
'notes' => array( 'note_count', false, __( 'Notes' ), __( 'Table ordered by Notes.' ) ),
775+
'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ),
776+
);
786777
// Custom Post Types: there's a filter for that, see get_column_info().
787778

788779
return $sortables;
@@ -1263,11 +1254,29 @@ public function column_date( $post ) {
12631254
public function column_comments( $post ) {
12641255
?>
12651256
<div class="post-com-count-wrapper">
1266-
<?php
1257+
<?php
12671258
$pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
12681259

12691260
$this->comments_bubble( $post->ID, $pending_comments );
1261+
?>
1262+
</div>
1263+
<?php
1264+
}
1265+
1266+
/**
1267+
* Handles the notes column output.
1268+
*
1269+
* @since 7.0
1270+
*
1271+
* @param WP_Post $post The current WP_Post object.
1272+
*/
1273+
public function column_notes( $post ) {
1274+
global $_wp_post_type_features;
12701275
?>
1276+
<div class="post-com-count-wrapper">
1277+
<?php
1278+
$this->notes_bubble( $post->ID );
1279+
?>
12711280
</div>
12721281
<?php
12731282
}

src/wp-includes/post.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,15 +2340,39 @@ function get_all_post_type_supports( $post_type ) {
23402340
*
23412341
* @global array $_wp_post_type_features
23422342
*
2343-
* @param string $post_type The post type being checked.
2344-
* @param string $feature The feature being checked.
2343+
* @param string $post_type The post type being checked.
2344+
* @param string $feature The feature being checked.
2345+
* @param string|null $sub_feature The sub-feature being checked.
23452346
* @return bool Whether the post type supports the given feature.
23462347
*/
2347-
function post_type_supports( $post_type, $feature ) {
2348+
function post_type_supports( $post_type, $feature, $sub_feature = null ) {
23482349
global $_wp_post_type_features;
23492350

2350-
return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) );
2351+
if ( ! isset( $_wp_post_type_features[ $post_type ] ) ) {
2352+
return false;
2353+
}
2354+
2355+
if ( ! isset( $_wp_post_type_features[ $post_type ][ $feature ] ) ) {
2356+
return false;
2357+
}
2358+
2359+
if ( null === $sub_feature ) {
2360+
return ! empty( $_wp_post_type_features[ $post_type ][ $feature ] );
2361+
}
2362+
2363+
if ( ! is_array( $_wp_post_type_features[ $post_type ][ $feature ] ) ) {
2364+
return false;
2365+
}
2366+
2367+
if ( array_key_exists( $sub_feature, $_wp_post_type_features[ $post_type ][ $feature ] ) ) {
2368+
return true;
2369+
}
2370+
2371+
$sub_features = array_merge( ...$_wp_post_type_features[ $post_type ][ $feature ] );
2372+
2373+
return isset( $sub_features[ $sub_feature ] );
23512374
}
2375+
23522376
/**
23532377
* Retrieves a list of post type names that support a specific feature.
23542378
*

0 commit comments

Comments
 (0)