-
Notifications
You must be signed in to change notification settings - Fork 11
Adds new get and exists subcommands to the sidebar command
#70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
805bba3
825c171
41975cd
2d5adcb
0181329
770b58e
530c09a
06bd4b1
46cdb3d
0364e0b
8c3a208
4e8ec50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,48 @@ | ||
| Feature: Manage WordPress sidebars | ||
|
|
||
| Scenario: List available sidebars | ||
| Background: | ||
| Given a WP install | ||
|
|
||
| When I try `wp theme delete twentytwelve --force` | ||
| And I try `wp theme delete twentytwelve --force` | ||
| And I run `wp theme install twentytwelve --activate` | ||
| Then STDOUT should not be empty | ||
|
|
||
| Scenario: List available sidebars | ||
| When I run `wp sidebar list --fields=name,id` | ||
| Then STDOUT should be a table containing rows: | ||
| | name | id | | ||
| | Main Sidebar | sidebar-1 | | ||
| | First Front Page Widget Area | sidebar-2 | | ||
| | Second Front Page Widget Area | sidebar-3 | | ||
| | Inactive Widgets | wp_inactive_widgets | | ||
|
|
||
| When I run `wp sidebar list --format=ids` | ||
| Then STDOUT should be: | ||
| """ | ||
| sidebar-1 sidebar-2 sidebar-3 wp_inactive_widgets | ||
| """ | ||
|
|
||
| When I run `wp sidebar list --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 4 | ||
| """ | ||
|
|
||
| Scenario: Get sidebar details | ||
| When I run `wp sidebar get sidebar-1` | ||
| Then STDOUT should contain: | ||
| """ | ||
| sidebar-1 | ||
| """ | ||
|
|
||
| Scenario: Sidebar exists command returns success | ||
| When I run `wp sidebar exists sidebar-1` | ||
| Then the return code should be 0 | ||
|
|
||
| Scenario: Sidebar exists command returns failure | ||
| When I try `wp sidebar exists does-not-exist` | ||
| Then the return code should be 1 | ||
|
|
||
| Scenario: Get non-existing sidebar returns error | ||
| When I try `wp sidebar get does-not-exist` | ||
| Then STDERR should contain: | ||
| """ | ||
| does not exist | ||
| """ | ||
| And the return code should be 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,4 +84,77 @@ public function list_( $args, $assoc_args ) { | |
| $formatter = new Formatter( $assoc_args, $this->fields ); | ||
| $formatter->display_items( $sidebars ); | ||
| } | ||
|
|
||
| /** | ||
| * Get details about a specific sidebar. | ||
| * | ||
| * ## OPTIONS | ||
| * | ||
| * <id> | ||
| * : The sidebar ID. | ||
| * | ||
| * [--fields=<fields>] | ||
| * : Limit the output to specific object fields. | ||
| * | ||
| * [--format=<format>] | ||
| * : Render output in a particular format. | ||
| * --- | ||
| * default: table | ||
| * options: | ||
| * - table | ||
| * - csv | ||
| * - json | ||
|
iamsohilvahora marked this conversation as resolved.
|
||
| * - ids | ||
| * - count | ||
| * - yaml | ||
| * --- | ||
| * | ||
| * ## EXAMPLES | ||
| * | ||
| * $ wp sidebar get sidebar-1 | ||
| * $ wp sidebar get wp_inactive_widgets --format=json | ||
| * | ||
| * @when after_wp_load | ||
| */ | ||
| public function get( $args, $assoc_args ) { | ||
| global $wp_registered_sidebars; | ||
|
|
||
| Utils\wp_register_unused_sidebar(); | ||
|
|
||
| $id = $args[0]; | ||
|
|
||
| if ( ! array_key_exists( $id, $wp_registered_sidebars ) ) { | ||
| WP_CLI::error( "Sidebar '{$id}' does not exist." ); | ||
| } | ||
|
|
||
| $formatter = new Formatter( $assoc_args, $this->fields ); | ||
| $formatter->display_item( $wp_registered_sidebars[ $id ] ); | ||
| } | ||
|
|
||
| /** | ||
| * Check if a sidebar exists. | ||
| * | ||
| * ## OPTIONS | ||
| * | ||
| * <id> | ||
| * : The sidebar ID. | ||
| * | ||
| * ## EXAMPLES | ||
| * | ||
| * $ wp sidebar exists sidebar-1 | ||
| * $ wp sidebar exists wp_inactive_widgets && echo "exists" | ||
| * | ||
| * @when after_wp_load | ||
| */ | ||
| public function exists( $args ) { | ||
| global $wp_registered_sidebars; | ||
|
|
||
| Utils\wp_register_unused_sidebar(); | ||
|
|
||
| if ( array_key_exists( $args[0], $wp_registered_sidebars ) ) { | ||
| WP_CLI::halt( 0 ); | ||
| } | ||
|
|
||
| WP_CLI::halt( 1 ); | ||
| } | ||
|
Comment on lines
+87
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for loading registered sidebars ( private function get_registered_sidebars() {
global $wp_registered_sidebars;
Utils\wp_register_unused_sidebar();
return $wp_registered_sidebars;
}
/**
* Get details about a specific sidebar.
*
* ## OPTIONS
*
* <id>
* : The sidebar ID.
*
* [--fields=<fields>]
* : Limit the output to specific object fields.
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - json
* - yaml
* ---
*
* ## EXAMPLES
*
* $ wp sidebar get sidebar-1
* $ wp sidebar get wp_inactive_widgets --format=json
*
* @when after_wp_load
*/
public function get( $args, $assoc_args ) {
$wp_registered_sidebars = $this->get_registered_sidebars();
$id = $args[0];
if ( ! isset( $wp_registered_sidebars[ $id ] ) ) {
WP_CLI::error( "Sidebar '{$id}' does not exist." );
}
$formatter = new Formatter( $assoc_args, $this->fields );
$formatter->display_item( $wp_registered_sidebars[ $id ] );
}
/**
* Check if a sidebar exists.
*
* ## OPTIONS
*
* <id>
* : The sidebar ID.
*
* ## EXAMPLES
*
* $ wp sidebar exists sidebar-1
* $ wp sidebar exists wp_inactive_widgets && echo "exists"
*
* @when after_wp_load
*/
public function exists( $args ) {
$wp_registered_sidebars = $this->get_registered_sidebars();
if ( isset( $wp_registered_sidebars[ $args[0] ] ) ) {
WP_CLI::halt( 0 );
}
WP_CLI::halt( 1 );
} |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.