Posts list table: Add a filter to disable the categories dropdown.
This allows one to short-circuit its output before any queries are run, similar to how it was done for the months dropdown in [31438]. Props davidmosterd for initial patch. Fixes #36152. git-svn-id: https://develop.svn.wordpress.org/trunk@37856 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d0555f9544
commit
70693b520f
@ -412,19 +412,31 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @global int $cat
|
* Displays a categories drop-down for filtering on the Posts list table.
|
||||||
* @param string $which
|
*
|
||||||
|
* @since 4.6.0
|
||||||
|
* @access protected
|
||||||
|
*
|
||||||
|
* @global int $cat Currently selected category.
|
||||||
|
*
|
||||||
|
* @param string $post_type The Post Type.
|
||||||
*/
|
*/
|
||||||
protected function extra_tablenav( $which ) {
|
protected function categories_dropdown( $post_type ) {
|
||||||
global $cat;
|
global $cat;
|
||||||
?>
|
|
||||||
<div class="alignleft actions">
|
|
||||||
<?php
|
|
||||||
if ( 'top' === $which && !is_singular() ) {
|
|
||||||
|
|
||||||
$this->months_dropdown( $this->screen->post_type );
|
/**
|
||||||
|
* Filters whether to remove the 'Categories' drop-down from the post list table.
|
||||||
|
*
|
||||||
|
* @since 4.6.0
|
||||||
|
*
|
||||||
|
* @param bool $disable Whether to disable the categories drop-down. Default false.
|
||||||
|
* @param string $post_type The post type.
|
||||||
|
*/
|
||||||
|
if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
|
if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
|
||||||
$dropdown_options = array(
|
$dropdown_options = array(
|
||||||
'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
|
'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
|
||||||
'hide_empty' => 0,
|
'hide_empty' => 0,
|
||||||
@ -437,6 +449,19 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||||||
echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
|
echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
|
||||||
wp_dropdown_categories( $dropdown_options );
|
wp_dropdown_categories( $dropdown_options );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $which
|
||||||
|
*/
|
||||||
|
protected function extra_tablenav( $which ) {
|
||||||
|
?>
|
||||||
|
<div class="alignleft actions">
|
||||||
|
<?php
|
||||||
|
if ( 'top' === $which && !is_singular() ) {
|
||||||
|
|
||||||
|
$this->months_dropdown( $this->screen->post_type );
|
||||||
|
$this->categories_dropdown( $this->screen->post_type );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires before the Filter button on the Posts and Pages list tables.
|
* Fires before the Filter button on the Posts and Pages list tables.
|
||||||
|
Loading…
Reference in New Issue
Block a user