List Tables: Do not show filter button when there are no filter options available.
Props juhise, dipesh.kakadiya, swissspidy. Fixes #37407. git-svn-id: https://develop.svn.wordpress.org/trunk@38854 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5fb3d3f279
commit
f508d80a1b
@ -459,6 +459,7 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||||||
<div class="alignleft actions">
|
<div class="alignleft actions">
|
||||||
<?php
|
<?php
|
||||||
if ( 'top' === $which && !is_singular() ) {
|
if ( 'top' === $which && !is_singular() ) {
|
||||||
|
ob_start();
|
||||||
|
|
||||||
$this->months_dropdown( $this->screen->post_type );
|
$this->months_dropdown( $this->screen->post_type );
|
||||||
$this->categories_dropdown( $this->screen->post_type );
|
$this->categories_dropdown( $this->screen->post_type );
|
||||||
@ -479,8 +480,13 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||||||
*/
|
*/
|
||||||
do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
|
do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
|
||||||
|
|
||||||
|
$output = ob_get_clean();
|
||||||
|
|
||||||
|
if ( ! empty( $output ) ) {
|
||||||
|
echo $output;
|
||||||
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
|
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
|
if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
|
||||||
submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
|
submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
|
||||||
|
@ -9,6 +9,11 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase {
|
|||||||
protected static $grandchildren = array();
|
protected static $grandchildren = array();
|
||||||
protected static $post_ids = array();
|
protected static $post_ids = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var WP_Posts_List_Table
|
||||||
|
*/
|
||||||
|
protected $table;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
set_current_screen( 'edit-page' );
|
set_current_screen( 'edit-page' );
|
||||||
@ -191,4 +196,45 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 37407
|
||||||
|
*/
|
||||||
|
function test_filter_button_should_not_be_shown_if_there_are_no_posts() {
|
||||||
|
// Set post type to a non-existent one.
|
||||||
|
$this->table->screen->post_type = 'foo';
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$this->table->extra_tablenav( 'top' );
|
||||||
|
$output = ob_get_clean();
|
||||||
|
|
||||||
|
$this->assertNotContains( 'id="post-query-submit"', $output );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 37407
|
||||||
|
*/
|
||||||
|
function test_months_dropdown_should_not_be_shown_if_there_are_no_posts() {
|
||||||
|
// Set post type to a non-existent one.
|
||||||
|
$this->table->screen->post_type = 'foo';
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$this->table->extra_tablenav( 'top' );
|
||||||
|
$output = ob_get_clean();
|
||||||
|
|
||||||
|
$this->assertNotContains( 'id="filter-by-date"', $output );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 37407
|
||||||
|
*/
|
||||||
|
function test_category_dropdown_should_not_be_shown_if_there_are_no_posts() {
|
||||||
|
// Set post type to a non-existent one.
|
||||||
|
$this->table->screen->post_type = 'foo';
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$this->table->extra_tablenav( 'top' );
|
||||||
|
$output = ob_get_clean();
|
||||||
|
|
||||||
|
$this->assertNotContains( 'id="cat"', $output );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user