Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions features/taxonomy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
<?php
// Plugin Name: Test Taxonomy Strict/No-Strict Mode

add_action( 'init', function() {
$args = array(
'hierarchical' => 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:
"""
<?php
// Plugin Name: Test Taxonomy Strict/No-Strict Mode

add_action( 'init', function() {
$args = array(
'hierarchical' => 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 |
15 changes: 13 additions & 2 deletions src/Taxonomy_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down