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
11 changes: 11 additions & 0 deletions features/profile-stage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ Feature: Profile the template render stage
Error: Invalid stage. Must be one of bootstrap, main_query, template, or use --all.
"""

@require-wp-4.0
Scenario: Invalid field name supplied to --fields
Given a WP install

When I try `wp profile stage template --fields=test`
Then STDERR should contain:
"""
Invalid field(s): test
"""
And the return code should be 1

@require-wp-4.0
Scenario: Identify callback_count for each hook
Given a WP install
Expand Down
17 changes: 14 additions & 3 deletions src/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ public function __construct( &$assoc_args, $fields = null, $prefix = false ) {
$format_args['fields'] = explode( ',', $format_args['fields'] );
}

if ( 'time' !== $fields[0] ) {
$this->total_cell_index = array_search( $fields[0], $format_args['fields'], true );
$format_args['fields'] = array_filter( array_map( 'trim', $format_args['fields'] ) );

if ( isset( $assoc_args['fields'] ) ) {
if ( empty( $format_args['fields'] ) ) {
$format_args['fields'] = $fields;
}
$invalid_fields = array_diff( $format_args['fields'], $fields );
if ( ! empty( $invalid_fields ) ) {
\WP_CLI::error( 'Invalid field(s): ' . implode( ', ', $invalid_fields ) );
}
}

$format_args['fields'] = array_map( 'trim', $format_args['fields'] );
if ( 'time' !== $fields[0] ) {
$index = array_search( $fields[0], $format_args['fields'], true );
$this->total_cell_index = ( false !== $index ) ? $index : null;
}

$this->args = $format_args;
$this->formatter = new \WP_CLI\Formatter( $assoc_args, $fields, $prefix );
Expand Down