Skip to content

Add wp menu item get command#570

Open
Copilot wants to merge 7 commits intomainfrom
copilot/add-wp-cli-menu-item-get-command
Open

Add wp menu item get command#570
Copilot wants to merge 7 commits intomainfrom
copilot/add-wp-cli-menu-item-get-command

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Plan for implementing wp menu item get command

  • Analyze existing code structure and patterns
    • Review Menu_Item_Command.php
    • Review Term_Command.php for get method pattern
    • Review existing test files (menu-item.feature, term.feature)
  • Implement get method in Menu_Item_Command.php
    • Add get method following WP-CLI patterns
    • Support getting menu item by db_id
    • Support all available fields
    • Add proper error handling
  • Add command to composer.json
  • Write comprehensive tests
    • Add test scenario for basic menu item get
    • Test with different output formats (table, json, csv, yaml)
    • Test field filtering
    • Test error handling for non-existent menu items
  • Run tests and validate
    • Run composer lint - ✅ Passed
    • Run composer phpcs - ✅ Passed
    • Run composer phpstan - ✅ Passed (no new errors)
    • Run behat tests for menu-item - ✅ All 6 scenarios passed (113/113 steps)
  • Address test failure
    • Fixed position calculation to handle menu_order 0 correctly
    • Restored correct logic: position = (menu_order === 0) ? 1 : menu_order
    • All tests passing
  • Update default fields behavior
    • Changed to use curated default fields (db_id, type, title, link, position)
    • Updated documentation to reflect actual behavior
    • Consistent with list command behavior
  • Code review and security scan - ✅ Completed

Changes Applied

Default Fields Update

  • Documentation: Updated --fields parameter description to specify it defaults to db_id, type, title, link, position
  • Implementation: Removed explicit field list assignment, allowing formatter to use $obj_fields class property
  • Consistency: Now matches the behavior of wp menu item list command
  • Benefits: Cleaner output by default, better UX, users can still request all fields with --fields=all
Original prompt

This section details on the original issue you should resolve

<issue_title>WP CLI - Menu Item Get Command</issue_title>
<issue_description>Hi guys,

Could you consider to improve wp menu item commands with get method?

I have the problem to get some information of existing menu items for example ID. I try dynamically to add new items as child elements but I can't get parent menu item ID. At this moment we have options to list all menu items and here I can see menu item ID

wp menu item list main-menu

but if I want to create a simple program to collect menu items information and to add new items in predefined places, then I can't do that. Thanks for your time

Best regards,
Nenad</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera @NenadObradovic If you want to retrieve the parent menu item ID, you can do this by adding the field `menu_item_parent` to the displayed fields: ``` wp menu item list main-menu --fields=db_id,title,menu_parent_item ``` With the above, for example, you can `grep` for a specific menu item title, and then use something like `awk` to retrieve the parent menu item ID.

Does that provide what you need, or are you thinking of something else specifically?</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add get method for WP CLI menu item commands Add wp menu item get command Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 18:44
@github-actions github-actions bot added command:menu-item Related to 'menu item' command command:menu-item-add-custom Related to 'menu item add-custom' command command:menu-item-list Related to 'menu item list' command command:menu-item-update Related to 'menu item update' command labels Feb 2, 2026
@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!

This comment was marked as resolved.

swissspidy and others added 2 commits February 3, 2026 09:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy swissspidy marked this pull request as ready for review February 3, 2026 14:45
@swissspidy swissspidy requested a review from a team as a code owner February 3, 2026 14:45
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy
Copy link
Member

/gemini review

Copy link
Contributor

@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 the wp menu item get command, a valuable addition for retrieving details of a specific menu item. The implementation is solid and includes comprehensive test coverage. However, there's an inconsistency in the default fields displayed by the command. The code defaults to showing all available fields, while the documentation example and tests expect a more concise, curated list. My feedback focuses on aligning the implementation with the documentation and tests to improve user experience and maintain consistency with the list command.

Comment on lines 211 to 229
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current implementation sets the default fields to all available fields. This contradicts the command's own documentation example and the accompanying tests, which expect a smaller default set of fields (db_id, type, title, link, position). While the tests may pass if they only check for the presence of rows, this behavior is inconsistent and not ideal for the user. To fix this, the default fields should be sourced from $this->obj_fields for consistency with the list command.

			$assoc_args['fields'] = $this->obj_fields;

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

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

Labels

command:menu-item Related to 'menu item' command command:menu-item-add-custom Related to 'menu item add-custom' command command:menu-item-list Related to 'menu item list' command command:menu-item-update Related to 'menu item update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP CLI - Menu Item Get Command

2 participants

Comments