From bd0363694184a8d9d1baf32d8fc8e636febdeef5 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 28 Jun 2020 14:28:23 +0000 Subject: [PATCH] Posts, Post Types: Return early from `WP_Posts_List_Table::formats_dropdown()` if the post type does not support post formats. This avoids an unnecessary database query for the `post_format` taxonomy. Props Chouby. Fixes #50496. git-svn-id: https://develop.svn.wordpress.org/trunk@48203 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-posts-list-table.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index 69493c3200..de0d70c6ca 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -485,6 +485,11 @@ class WP_Posts_List_Table extends WP_List_Table { return; } + // Return if the post type doesn't have post formats or if we're in the Trash. + if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) { + return; + } + // Make sure the dropdown shows only formats with a post count greater than 0. $used_post_formats = get_terms( array( @@ -493,11 +498,8 @@ class WP_Posts_List_Table extends WP_List_Table { ) ); - /* - * Return if the post type doesn't have post formats, or there are no posts using formats, - * or if we're in the Trash. - */ - if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || ! $used_post_formats || $this->is_trash ) { + // Return if there are no posts using formats. + if ( ! $used_post_formats ) { return; }