diff --git a/features/taxonomy.feature b/features/taxonomy.feature index d107ea57d..58469156f 100644 --- a/features/taxonomy.feature +++ b/features/taxonomy.feature @@ -46,3 +46,83 @@ Feature: Manage WordPress taxonomies | Field | Value | | name | category | | count | 1 | + + @require-wp-5.1 + Scenario: Listing taxonomies with strict/no-strict mode + Given a WP installation + And a wp-content/mu-plugins/test-taxonomy-list.php file: + """ + true, + 'show_ui' => true, + 'show_admin_column' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'labels' => array( + 'name' => _x( 'Genres', 'taxonomy general name', 'textdomain' ), + ), + + ); + + register_taxonomy( 'genres', array( 'post','page' ), $args ); + } ); + """ + + When I run `wp taxonomy list --object_type=post --strict` + Then STDOUT should be a table containing rows: + | name | label | description | object_type | show_tagcloud | hierarchical | public | + | category | Categories | | post | 1 | 1 | 1 | + | post_tag | Tags | | post | 1 | | 1 | + | post_format | Formats | | post | | | 1 | + + When I run `wp taxonomy list --object_type=post --no-strict` + Then STDOUT should be a table containing rows: + | name | label | description | object_type | show_tagcloud | hierarchical | public | + | category | Categories | | post | 1 | 1 | 1 | + | post_tag | Tags | | post | 1 | | 1 | + | post_format | Formats | | post | | | 1 | + | genres | Genres | | post, page | 1 | 1 | 1 | + + @less-than-wp-5.1 + Scenario: Listing taxonomies with strict/no-strict mode (for WP < 5.1) + Given a WP installation + And a wp-content/mu-plugins/test-taxonomy-list.php file: + """ + true, + 'show_ui' => true, + 'show_admin_column' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'labels' => array( + 'name' => _x( 'Genres', 'taxonomy general name', 'textdomain' ), + ), + + ); + + register_taxonomy( 'genres', array( 'post','page' ), $args ); + } ); + """ + + When I run `wp taxonomy list --object_type=post --strict` + Then STDOUT should be a table containing rows: + | name | label | description | object_type | show_tagcloud | hierarchical | public | + | category | Categories | | post | 1 | 1 | 1 | + | post_tag | Tags | | post | 1 | | 1 | + | post_format | Format | | post | | | 1 | + + When I run `wp taxonomy list --object_type=post --no-strict` + Then STDOUT should be a table containing rows: + | name | label | description | object_type | show_tagcloud | hierarchical | public | + | category | Categories | | post | 1 | 1 | 1 | + | post_tag | Tags | | post | 1 | | 1 | + | post_format | Format | | post | | | 1 | + | genres | Genres | | post, page | 1 | 1 | 1 | diff --git a/src/Taxonomy_Command.php b/src/Taxonomy_Command.php index 91d1cf52e..21d33c9ad 100644 --- a/src/Taxonomy_Command.php +++ b/src/Taxonomy_Command.php @@ -148,13 +148,24 @@ protected function get_counts( $taxonomies ) { public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); + // Check if it's strict mode or not. + $strict = Utils\get_flag_value( $assoc_args, 'strict', false ); + + unset( $assoc_args['strict'] ); + if ( isset( $assoc_args['object_type'] ) ) { $assoc_args['object_type'] = array( $assoc_args['object_type'] ); + $taxonomy_object = $assoc_args['object_type']; + } else { + $taxonomy_object = get_post_types(); } $fields = $formatter->fields; - $taxonomies = get_taxonomies( $assoc_args, 'objects' ); - $counts = []; + $taxonomies = ( isset( $taxonomy_object ) && ! $strict ) + ? get_object_taxonomies( $taxonomy_object, 'objects' ) + : get_taxonomies( $assoc_args, 'objects' ); + + $counts = []; if ( count( $taxonomies ) > 0 && in_array( 'count', $fields, true ) ) { $counts = $this->get_counts( wp_list_pluck( $taxonomies, 'name' ) );