Introduce 'show_in_quick_edit' parameter for register_taxonomy()
.
Setting 'show_in_quick_edit' to false when registering a custom taxonomy will hide the taxonomy when editing posts using Quick Edit. The new 'quick_edit_show_taxonomy' filter allows this behavior to be filtered on a finer scale, as when you want a given taxonomy to be hidden for one post type but not for others. Props hlashbrooke. Fixes #26948. git-svn-id: https://develop.svn.wordpress.org/trunk@31307 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2fb8562a97
commit
057c428346
@ -944,10 +944,26 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||||||
$hierarchical_taxonomies = array();
|
$hierarchical_taxonomies = array();
|
||||||
$flat_taxonomies = array();
|
$flat_taxonomies = array();
|
||||||
foreach ( $taxonomy_names as $taxonomy_name ) {
|
foreach ( $taxonomy_names as $taxonomy_name ) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters whether the current taxonomy should be shown in the Quick Edit panel.
|
||||||
|
*
|
||||||
|
* @since 4.2.0
|
||||||
|
*
|
||||||
|
* @param bool $show Whether to show the current taxonomy in Quick Edit.
|
||||||
|
* Default: true.
|
||||||
|
* @param string $taxonomy_name Taxonomy name.
|
||||||
|
* @param string $post_type Post type of current Quick Edit post.
|
||||||
|
*/
|
||||||
|
if ( ! apply_filters( 'quick_edit_show_taxonomy', true, $taxonomy_name, $screen->post_type ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$taxonomy = get_taxonomy( $taxonomy_name );
|
$taxonomy = get_taxonomy( $taxonomy_name );
|
||||||
|
|
||||||
if ( !$taxonomy->show_ui )
|
if ( ! $taxonomy->show_in_quick_edit ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $taxonomy->hierarchical )
|
if ( $taxonomy->hierarchical )
|
||||||
$hierarchical_taxonomies[] = $taxonomy;
|
$hierarchical_taxonomies[] = $taxonomy;
|
||||||
|
@ -282,6 +282,8 @@ function is_taxonomy_hierarchical($taxonomy) {
|
|||||||
* * If not set, the default is inherited from public.
|
* * If not set, the default is inherited from public.
|
||||||
* - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
|
* - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
|
||||||
* * If not set, the default is inherited from show_ui.
|
* * If not set, the default is inherited from show_ui.
|
||||||
|
* - show_in_quick_edit - Whether to show the taxonomy in the quick/bulk edit panel.
|
||||||
|
* * It not set, the default is inherited from show_ui.
|
||||||
* - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
|
* - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
|
||||||
* * Defaults to false.
|
* * Defaults to false.
|
||||||
* - meta_box_cb - Provide a callback function for the meta box display.
|
* - meta_box_cb - Provide a callback function for the meta box display.
|
||||||
@ -308,6 +310,7 @@ function is_taxonomy_hierarchical($taxonomy) {
|
|||||||
* - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
|
* - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
|
||||||
*
|
*
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
|
* @since 4.2.0 Introduced 'show_in_quick_edit' parameter.
|
||||||
* @uses $wp_taxonomies Inserts new taxonomy object into the list
|
* @uses $wp_taxonomies Inserts new taxonomy object into the list
|
||||||
* @uses $wp Adds query vars
|
* @uses $wp Adds query vars
|
||||||
*
|
*
|
||||||
@ -331,6 +334,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
|||||||
'show_in_menu' => null,
|
'show_in_menu' => null,
|
||||||
'show_in_nav_menus' => null,
|
'show_in_nav_menus' => null,
|
||||||
'show_tagcloud' => null,
|
'show_tagcloud' => null,
|
||||||
|
'show_in_quick_edit' => null,
|
||||||
'show_admin_column' => false,
|
'show_admin_column' => false,
|
||||||
'meta_box_cb' => null,
|
'meta_box_cb' => null,
|
||||||
'capabilities' => array(),
|
'capabilities' => array(),
|
||||||
@ -389,6 +393,11 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
|||||||
if ( null === $args['show_tagcloud'] )
|
if ( null === $args['show_tagcloud'] )
|
||||||
$args['show_tagcloud'] = $args['show_ui'];
|
$args['show_tagcloud'] = $args['show_ui'];
|
||||||
|
|
||||||
|
// If not set, default to the setting for show_ui.
|
||||||
|
if ( null === $args['show_in_quick_edit'] ) {
|
||||||
|
$args['show_in_quick_edit'] = $args['show_ui'];
|
||||||
|
}
|
||||||
|
|
||||||
$default_caps = array(
|
$default_caps = array(
|
||||||
'manage_terms' => 'manage_categories',
|
'manage_terms' => 'manage_categories',
|
||||||
'edit_terms' => 'manage_categories',
|
'edit_terms' => 'manage_categories',
|
||||||
|
@ -162,6 +162,25 @@ class Tests_Taxonomy extends WP_UnitTestCase {
|
|||||||
$this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) );
|
$this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 26948
|
||||||
|
*/
|
||||||
|
public function test_register_taxonomy_show_in_quick_edit_should_default_to_value_of_show_ui() {
|
||||||
|
register_taxonomy( 'wptests_tax_1', 'post', array(
|
||||||
|
'show_ui' => true,
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_taxonomy( 'wptests_tax_2', 'post', array(
|
||||||
|
'show_ui' => false,
|
||||||
|
) );
|
||||||
|
|
||||||
|
$tax_1 = get_taxonomy( 'wptests_tax_1' );
|
||||||
|
$this->assertTrue( $tax_1->show_in_quick_edit );
|
||||||
|
|
||||||
|
$tax_2 = get_taxonomy( 'wptests_tax_2' );
|
||||||
|
$this->assertFalse( $tax_2->show_in_quick_edit );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ticket 11058
|
* @ticket 11058
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user