-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add Notes column to posts list table #10611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -954,6 +954,73 @@ protected function comments_bubble( $post_id, $pending_comments ) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Displays a note count bubble. | ||||||
| * | ||||||
| * @since 3.1.0 | ||||||
| * | ||||||
| * @param int $post_id The post ID. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| */ | ||||||
| protected function notes_bubble( $post_id ) { | ||||||
| $post_object = get_post( $post_id ); | ||||||
| $edit_post_cap = $post_object ? 'edit_post' : 'edit_posts'; | ||||||
|
|
||||||
| if ( ! current_user_can( $edit_post_cap, $post_id ) | ||||||
| && ( post_password_required( $post_id ) | ||||||
| || ! current_user_can( 'read_post', $post_id ) ) | ||||||
| ) { | ||||||
| // The user has no access to the post and thus cannot see the notes. | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| $args = array( | ||||||
| 'type' => 'note', | ||||||
| 'count' => true, | ||||||
| 'status' => 'any', | ||||||
| 'post_id' => $post_id, | ||||||
| ); | ||||||
| $args = apply_filters( 'post_column_notes_query_args', $args ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add filter docs |
||||||
|
|
||||||
| $note_count = get_comments( $args ); | ||||||
| $note_count_number = number_format_i18n( $note_count ); | ||||||
|
|
||||||
| $notes_phrase = sprintf( | ||||||
| /* translators: %s: Number of notes. */ | ||||||
| _n( '%s note', '%s notes', $note_count ), | ||||||
| $note_count_number | ||||||
| ); | ||||||
|
|
||||||
| if ( ! $note_count ) { | ||||||
| // No notes at all. | ||||||
| printf( | ||||||
| '<span aria-hidden="true">—</span>' . | ||||||
| '<span class="screen-reader-text">%s</span>', | ||||||
| __( 'No notes' ) | ||||||
| ); | ||||||
| } elseif ( $note_count && 'trash' === get_post_status( $post_id ) ) { | ||||||
| // Don't link the notes bubble for a trashed post. | ||||||
| printf( | ||||||
| '<span class="post-com-count">' . | ||||||
| '<span class="comment-count" aria-hidden="true">%s</span>' . | ||||||
| '<span class="screen-reader-text">%s</span>' . | ||||||
| '</span>', | ||||||
| $note_count_number, | ||||||
| $notes_phrase | ||||||
| ); | ||||||
| } else { | ||||||
| // Link the note bubble to the edit post screen. | ||||||
| printf( | ||||||
| '<a href="%s" class="post-com-count">' . | ||||||
| '<span class="comment-count" aria-hidden="true">%s</span>' . | ||||||
| '<span class="screen-reader-text">%s</span>' . | ||||||
| '</a>', | ||||||
| get_edit_post_link( $post_id ), | ||||||
| $note_count_number, | ||||||
| $notes_phrase | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Gets the current page number. | ||||||
| * | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -705,12 +705,11 @@ public function get_columns() { | |||||
| if ( post_type_supports( $post_type, 'comments' ) | ||||||
| && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) | ||||||
| ) { | ||||||
| $posts_columns['comments'] = sprintf( | ||||||
| '<span class="vers comment-grey-bubble" title="%1$s" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span>', | ||||||
| esc_attr__( 'Comments' ), | ||||||
| /* translators: Hidden accessibility text. */ | ||||||
| __( 'Comments' ) | ||||||
| ); | ||||||
| $posts_columns['comments'] = __( 'Comments' ); | ||||||
| } | ||||||
|
|
||||||
| if ( post_type_supports( $post_type, 'editor', 'notes' ) ) { | ||||||
| $posts_columns['notes'] = __( 'Notes' ); | ||||||
| } | ||||||
|
|
||||||
| $posts_columns['date'] = __( 'Date' ); | ||||||
|
|
@@ -762,27 +761,19 @@ protected function get_sortable_columns() { | |||||
|
|
||||||
| $post_type = $this->screen->post_type; | ||||||
|
|
||||||
| if ( 'page' === $post_type ) { | ||||||
| if ( isset( $_GET['orderby'] ) ) { | ||||||
| $title_orderby_text = __( 'Table ordered by Title.' ); | ||||||
| } else { | ||||||
| $title_orderby_text = __( 'Table ordered by Hierarchical Menu Order and Title.' ); | ||||||
| } | ||||||
| $title_orderby_text = __( 'Table ordered by Title.' ); | ||||||
|
|
||||||
| $sortables = array( | ||||||
| 'title' => array( 'title', false, __( 'Title' ), $title_orderby_text, 'asc' ), | ||||||
| 'parent' => array( 'parent', false ), | ||||||
| 'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), | ||||||
| 'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ) ), | ||||||
| ); | ||||||
| } else { | ||||||
| $sortables = array( | ||||||
| 'title' => array( 'title', false, __( 'Title' ), __( 'Table ordered by Title.' ) ), | ||||||
| 'parent' => array( 'parent', false ), | ||||||
| 'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), | ||||||
| 'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ), | ||||||
| ); | ||||||
| if ( 'page' === $post_type && ! isset( $_GET['orderby'] ) ) { | ||||||
| $title_orderby_text = __( 'Table ordered by Hierarchical Menu Order and Title.' ); | ||||||
| } | ||||||
|
|
||||||
| $sortables = array( | ||||||
| 'title' => array( 'title', false, __( 'Title' ), $title_orderby_text ), | ||||||
| 'parent' => array( 'parent', false ), | ||||||
| 'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), | ||||||
| 'notes' => array( 'note_count', false, __( 'Notes' ), __( 'Table ordered by Notes.' ) ), | ||||||
| 'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ), | ||||||
| ); | ||||||
| // Custom Post Types: there's a filter for that, see get_column_info(). | ||||||
|
|
||||||
| return $sortables; | ||||||
|
|
@@ -1263,11 +1254,29 @@ public function column_date( $post ) { | |||||
| public function column_comments( $post ) { | ||||||
| ?> | ||||||
| <div class="post-com-count-wrapper"> | ||||||
| <?php | ||||||
| <?php | ||||||
| $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0; | ||||||
|
|
||||||
| $this->comments_bubble( $post->ID, $pending_comments ); | ||||||
| ?> | ||||||
| </div> | ||||||
| <?php | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Handles the notes column output. | ||||||
| * | ||||||
| * @since 7.0 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * | ||||||
| * @param WP_Post $post The current WP_Post object. | ||||||
| */ | ||||||
| public function column_notes( $post ) { | ||||||
| global $_wp_post_type_features; | ||||||
| ?> | ||||||
| <div class="post-com-count-wrapper"> | ||||||
| <?php | ||||||
| $this->notes_bubble( $post->ID ); | ||||||
| ?> | ||||||
| </div> | ||||||
| <?php | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2340,15 +2340,39 @@ function get_all_post_type_supports( $post_type ) { | |
| * | ||
| * @global array $_wp_post_type_features | ||
| * | ||
| * @param string $post_type The post type being checked. | ||
| * @param string $feature The feature being checked. | ||
| * @param string $post_type The post type being checked. | ||
| * @param string $feature The feature being checked. | ||
| * @param string|null $sub_feature The sub-feature being checked. | ||
| * @return bool Whether the post type supports the given feature. | ||
| */ | ||
| function post_type_supports( $post_type, $feature ) { | ||
| function post_type_supports( $post_type, $feature, $sub_feature = null ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is best done in a separate ticket. See https://core.trac.wordpress.org/ticket/64156 and #10426 (comment) It will require extensive unit tests as well. |
||
| global $_wp_post_type_features; | ||
|
|
||
| return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) ); | ||
| if ( ! isset( $_wp_post_type_features[ $post_type ] ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( ! isset( $_wp_post_type_features[ $post_type ][ $feature ] ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( null === $sub_feature ) { | ||
| return ! empty( $_wp_post_type_features[ $post_type ][ $feature ] ); | ||
| } | ||
|
|
||
| if ( ! is_array( $_wp_post_type_features[ $post_type ][ $feature ] ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( array_key_exists( $sub_feature, $_wp_post_type_features[ $post_type ][ $feature ] ) ) { | ||
| return true; | ||
| } | ||
|
|
||
| $sub_features = array_merge( ...$_wp_post_type_features[ $post_type ][ $feature ] ); | ||
|
|
||
| return isset( $sub_features[ $sub_feature ] ); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a list of post type names that support a specific feature. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.