From 1603a0b324f1e3e8a5056df7c2430747bd9f33bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 07:45:10 +0000 Subject: [PATCH 1/4] Initial plan From f26bdbd5efdf6026beeaf4a8165ab451e7e456dd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 07:48:13 +0000 Subject: [PATCH 2/4] Add wp menu item add-post-type-archive command Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/menu-item.feature | 21 ++++++++++++++ src/Menu_Item_Command.php | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/features/menu-item.feature b/features/menu-item.feature index 494e0dfd0..cbaceae3c 100644 --- a/features/menu-item.feature +++ b/features/menu-item.feature @@ -252,3 +252,24 @@ Feature: Manage WordPress menu items """ And the return code should be 1 + Scenario: Add a post type archive as a menu item + + When I run `wp menu create "Archive Menu"` + Then STDOUT should not be empty + + When I run `wp menu item add-post-type-archive archive-menu post --porcelain` + Then STDOUT should be a number + And save STDOUT as {ITEM_ID} + + When I run `wp menu item list archive-menu --fields=db_id,type,object` + Then STDOUT should be a table containing rows: + | db_id | type | object | + | {ITEM_ID} | post_type_archive | post | + + When I try `wp menu item add-post-type-archive archive-menu invalidposttype` + Then STDERR should be: + """ + Error: Invalid post type. + """ + And the return code should be 1 + diff --git a/src/Menu_Item_Command.php b/src/Menu_Item_Command.php index 40bf6610b..8f3e44781 100644 --- a/src/Menu_Item_Command.php +++ b/src/Menu_Item_Command.php @@ -329,6 +329,63 @@ public function add_term( $args, $assoc_args ) { $this->add_or_update_item( 'add', 'taxonomy', $args, $assoc_args ); } + /** + * Adds a post type archive as a menu item. + * + * ## OPTIONS + * + * + * : The name, slug, or term ID for the menu. + * + * + * : Post type slug. + * + * [--title=] + * : Set a custom title for the menu item. + * + * [--link=<link>] + * : Set a custom url for the menu item. + * + * [--description=<description>] + * : Set a custom description for the menu item. + * + * [--attr-title=<attr-title>] + * : Set a custom title attribute for the menu item. + * + * [--target=<target>] + * : Set a custom link target for the menu item. + * + * [--classes=<classes>] + * : Set a custom link classes for the menu item. + * + * [--position=<position>] + * : Specify the position of this menu item. + * + * [--parent-id=<parent-id>] + * : Make this menu item a child of another menu item. + * + * [--porcelain] + * : Output just the new menu item id. + * + * ## EXAMPLES + * + * $ wp menu item add-post-type-archive sidebar-menu post + * Success: Menu item added. + * + * @subcommand add-post-type-archive + */ + public function add_post_type_archive( $args, $assoc_args ) { + + $assoc_args['object'] = $args[1]; + unset( $args[1] ); + + if ( ! get_post_type_object( $assoc_args['object'] ) ) { + WP_CLI::error( 'Invalid post type.' ); + } + + $this->add_or_update_item( 'add', 'post_type_archive', $args, $assoc_args ); + } + /** * Adds a custom menu item. * From a3dc7054d5ecdede55de9e466657410a33feff15 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Sun, 15 Mar 2026 09:38:54 +0100 Subject: [PATCH 3/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Menu_Item_Command.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Menu_Item_Command.php b/src/Menu_Item_Command.php index 8f3e44781..94a1ea3f3 100644 --- a/src/Menu_Item_Command.php +++ b/src/Menu_Item_Command.php @@ -379,10 +379,16 @@ public function add_post_type_archive( $args, $assoc_args ) { $assoc_args['object'] = $args[1]; unset( $args[1] ); - if ( ! get_post_type_object( $assoc_args['object'] ) ) { + $post_type = $assoc_args['object']; + + if ( ! get_post_type_object( $post_type ) ) { WP_CLI::error( 'Invalid post type.' ); } + if ( false === get_post_type_archive_link( $post_type ) ) { + WP_CLI::error( 'Post type does not have an archive.' ); + } + $this->add_or_update_item( 'add', 'post_type_archive', $args, $assoc_args ); } From c4daab2abc3860229e14119028097f3b8958904b Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Sun, 15 Mar 2026 09:39:19 +0100 Subject: [PATCH 4/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- features/menu-item.feature | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/menu-item.feature b/features/menu-item.feature index cbaceae3c..c5a040568 100644 --- a/features/menu-item.feature +++ b/features/menu-item.feature @@ -266,6 +266,9 @@ Feature: Manage WordPress menu items | db_id | type | object | | {ITEM_ID} | post_type_archive | post | + When I run `wp menu item get {ITEM_ID} --field=link` + Then STDOUT should not be empty + When I try `wp menu item add-post-type-archive archive-menu invalidposttype` Then STDERR should be: """