Skip to content

Conversation

@iamsohilvahora
Copy link

This pull request adds new get and exists subcommands to the sidebar command.

It includes Behat tests to ensure proper coverage and correct exit codes, and aligns behavior with existing wp-cli command patterns.

@iamsohilvahora iamsohilvahora requested a review from a team as a code owner February 2, 2026 14:54
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@gemini-code-assist
Copy link

Summary of Changes

Hello @iamsohilvahora, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request expands the wp sidebar command's capabilities by introducing get and exists subcommands. These additions allow users to programmatically retrieve detailed information about specific sidebars and verify their existence, enhancing the command-line management of WordPress sidebars.

Highlights

  • New get subcommand: Implemented wp sidebar get <id> to retrieve and display details of a specific WordPress sidebar, supporting various output formats like table, JSON, and YAML.
  • New exists subcommand: Added wp sidebar exists <id> to check for the presence of a sidebar, returning an exit code of 0 for existence and 1 for non-existence, aligning with standard command-line practices.
  • Behat Test Coverage: Introduced new Behat scenarios to validate the functionality and correct exit codes of both the get and exists subcommands, ensuring robust behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces get and exists subcommands for the sidebar command, along with corresponding Behat tests. The implementation is straightforward and follows existing patterns. I've identified a couple of opportunities for improvement: one to enhance the robustness of the new tests, and another to reduce code duplication by introducing a helper method. These changes will improve the maintainability and quality of the code.

Comment on lines 33 to 37
And I run `wp sidebar get sidebar-1`
Then STDOUT should contain:
"""
sidebar-1
"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current test for the get subcommand only verifies that the output contains the sidebar ID. This is a weak assertion. To make the test more robust and less prone to breaking from unrelated output changes, I suggest using the --format=json option and asserting the structure and content of the JSON output. This ensures the command returns the expected data fields and values correctly.

    And I run `wp sidebar get sidebar-1 --format=json`
    Then STDOUT should be JSON containing:
      """
      {"name":"Main Sidebar","id":"sidebar-1"}
      """

Comment on lines +87 to +156

/**
* 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 ) {
global $wp_registered_sidebars;

Utils\wp_register_unused_sidebar();

$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 ) {
global $wp_registered_sidebars;

Utils\wp_register_unused_sidebar();

if ( isset( $wp_registered_sidebars[ $args[0] ] ) ) {
WP_CLI::halt( 0 );
}

WP_CLI::halt( 1 );
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for loading registered sidebars (global $wp_registered_sidebars; and Utils\wp_register_unused_sidebar();) is duplicated across the list_, get, and exists methods. To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, I recommend extracting this logic into a private helper method. This way, if the sidebar loading mechanism changes in the future, you'll only need to update it in one place.

	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 );
	}

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
Copy link
Member

Why the new PR? Does this replace #69?

@iamsohilvahora
Copy link
Author

Yes @swissspidy and actually, I got error where I confuse how to edit and push this file?

image

@swissspidy
Copy link
Member

The Behat steps you used don't exist. You can find a list of all available Behat steps in our handbook.

I recommend checking out the repository locslly to make edits & pushing changes.

Then STDOUT should not be empty

When I run `wp theme install twentytwelve`
And I run `wp theme activate twentytwelve`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
And I run `wp theme activate twentytwelve`
And I run `wp theme activate twentytwelve --force`

There would be warning if theme already exists. Try "--force" argument.

@iamsohilvahora
Copy link
Author

iamsohilvahora commented Feb 3, 2026

Please check @ernilambar and there is also file called - src/Sidebar_Command.php

530c09a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants