diff -r 34716fd837a4 -r be944660c56a wp/wp-admin/includes/class-wp-posts-list-table.php --- a/wp/wp-admin/includes/class-wp-posts-list-table.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-admin/includes/class-wp-posts-list-table.php Wed Sep 21 18:19:35 2022 +0200 @@ -84,35 +84,47 @@ $post_type = $this->screen->post_type; $post_type_object = get_post_type_object( $post_type ); - $exclude_states = get_post_stati( + $exclude_states = get_post_stati( array( 'show_in_admin_all_list' => false, ) ); - $this->user_posts_count = intval( - $wpdb->get_var( - $wpdb->prepare( - " - SELECT COUNT( 1 ) - FROM $wpdb->posts - WHERE post_type = %s - AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) - AND post_author = %d - ", - $post_type, - get_current_user_id() - ) + + $this->user_posts_count = (int) $wpdb->get_var( + $wpdb->prepare( + "SELECT COUNT( 1 ) + FROM $wpdb->posts + WHERE post_type = %s + AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) + AND post_author = %d", + $post_type, + get_current_user_id() ) ); - if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) { + if ( $this->user_posts_count + && ! current_user_can( $post_type_object->cap->edit_others_posts ) + && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) + && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) + ) { $_GET['author'] = get_current_user_id(); } $sticky_posts = get_option( 'sticky_posts' ); + if ( 'post' === $post_type && $sticky_posts ) { - $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) ); - $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) ); + $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) ); + + $this->sticky_posts_count = (int) $wpdb->get_var( + $wpdb->prepare( + "SELECT COUNT( 1 ) + FROM $wpdb->posts + WHERE post_type = %s + AND post_status NOT IN ('trash', 'auto-draft') + AND ID IN ($sticky_posts)", + $post_type + ) + ); } } @@ -153,7 +165,10 @@ // Is going to call wp(). $avail_post_stati = wp_edit_posts_query(); - $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] ); + $this->set_hierarchical_display( + is_post_type_hierarchical( $this->screen->post_type ) + && 'menu_order title' === $wp_query->query['orderby'] + ); $post_type = $this->screen->post_type; $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' ); @@ -172,7 +187,7 @@ $total_items = $post_counts[ $_REQUEST['post_status'] ]; } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) { $total_items = $this->sticky_posts_count; - } elseif ( isset( $_GET['author'] ) && get_current_user_id() == $_GET['author'] ) { + } elseif ( isset( $_GET['author'] ) && get_current_user_id() === (int) $_GET['author'] ) { $total_items = $this->user_posts_count; } else { $total_items = array_sum( $post_counts ); @@ -246,6 +261,7 @@ $class_html = ''; $aria_current = ''; + if ( ! empty( $class ) ) { $class_html = sprintf( ' class="%s"', @@ -295,7 +311,7 @@ } if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) { - if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) { + if ( isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ) ) { $class = 'current'; } @@ -337,6 +353,7 @@ ); $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class ); + if ( $mine ) { $status_links['mine'] = $mine; } @@ -458,7 +475,8 @@ 'selected' => $cat, ); - echo ''; + echo ''; + wp_dropdown_categories( $dropdown_options ); } } @@ -514,6 +532,7 @@ $slug = str_replace( 'post-format-', '', $used_post_format->slug ); // Pretty, translated version of the post format slug. $pretty_name = get_post_format_string( $slug ); + // Skip the standard post format. if ( 'standard' === $slug ) { continue; @@ -566,7 +585,9 @@ } } - if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) { + if ( $this->is_trash && $this->has_items() + && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) + ) { submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); } ?> @@ -604,7 +625,13 @@ $mode_class = esc_attr( 'table-view-' . $mode ); - return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); + return array( + 'widefat', + 'fixed', + 'striped', + $mode_class, + is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts', + ); } /** @@ -633,6 +660,11 @@ * The dynamic portion of the hook name, `$post_type`, refers to the post * type slug. * + * Possible hook names include: + * + * - `manage_taxonomies_for_post_columns` + * - `manage_taxonomies_for_page_columns` + * * @since 3.5.0 * * @param string[] $taxonomies Array of taxonomy names to show columns for. @@ -654,8 +686,15 @@ } $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; - if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) ) { - $posts_columns['comments'] = '' . __( 'Comments' ) . ''; + + if ( post_type_supports( $post_type, 'comments' ) + && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) + ) { + $posts_columns['comments'] = sprintf( + '%2$s', + esc_attr__( 'Comments' ), + __( 'Comments' ) + ); } $posts_columns['date'] = __( 'Date' ); @@ -688,6 +727,11 @@ * * The dynamic portion of the hook name, `$post_type`, refers to the post type slug. * + * Possible hook names include: + * + * - `manage_post_posts_columns` + * - `manage_page_posts_columns` + * * @since 3.0.0 * * @param string[] $post_columns An associative array of column headings. @@ -780,23 +824,21 @@ * If searching, ignore hierarchy and treat everything as top level */ if ( empty( $_REQUEST['s'] ) ) { - $top_level_pages = array(); $children_pages = array(); foreach ( $pages as $page ) { - // Catch and repair bad pages. - if ( $page->post_parent == $page->ID ) { + if ( $page->post_parent === $page->ID ) { $page->post_parent = 0; $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) ); clean_post_cache( $page ); } - if ( 0 == $page->post_parent ) { + if ( $page->post_parent > 0 ) { + $children_pages[ $page->post_parent ][] = $page; + } else { $top_level_pages[] = $page; - } else { - $children_pages[ $page->post_parent ][] = $page; } } @@ -883,24 +925,30 @@ } // If the page starts in a subtree, print the parents. - if ( $count == $start && $page->post_parent > 0 ) { + if ( $count === $start && $page->post_parent > 0 ) { $my_parents = array(); $my_parent = $page->post_parent; + while ( $my_parent ) { // Get the ID from the list or the attribute if my_parent is an object. $parent_id = $my_parent; + if ( is_object( $my_parent ) ) { $parent_id = $my_parent->ID; } $my_parent = get_post( $parent_id ); $my_parents[] = $my_parent; + if ( ! $my_parent->post_parent ) { break; } + $my_parent = $my_parent->post_parent; } + $num_parents = count( $my_parents ); + while ( $my_parent = array_pop( $my_parents ) ) { $to_display[ $my_parent->ID ] = $level - $num_parents; $num_parents--; @@ -927,7 +975,19 @@ * @param WP_Post $post The current WP_Post object. */ public function column_cb( $post ) { - if ( current_user_can( 'edit_post', $post->ID ) ) : + $show = current_user_can( 'edit_post', $post->ID ); + + /** + * Filters whether to show the bulk edit checkbox for a post in its list table. + * + * By default the checkbox is only shown if the current user can edit the post. + * + * @since 5.7.0 + * + * @param bool $show Whether to show the checkbox. + * @param WP_Post $post The current WP_Post object. + */ + if ( apply_filters( 'wp_list_table_show_post_checkbox', $show, $post ) ) : ?>