File tree 2 files changed +26
-6
lines changed 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,23 @@ Feature: Manage WordPress menu locations
29
29
Then STDOUT should be a table containing rows:
30
30
| slug | locations |
31
31
| primary -menu | |
32
+
33
+ When I try `wp menu location assign secondary-menu secondary`
34
+ Then STDERR should be:
35
+ """
36
+ Error: Invalid menu secondary-menu.
37
+ """
38
+
39
+ When I run `wp menu create "Secondary Menu" `
40
+ And I try `wp menu location assign secondary-menu secondary`
41
+ Then STDERR should be:
42
+ """
43
+ Error: Invalid location secondary.
44
+ """
45
+
46
+ When I run `wp menu location assign secondary-menu primary`
47
+ And I run `wp menu list --fields=slug,locations`
48
+ Then STDOUT should be a table containing rows:
49
+ | slug | locations |
50
+ | primary -menu | |
51
+ | secondary -menu | primary |
Original file line number Diff line number Diff line change @@ -108,22 +108,22 @@ public function assign( $args, $_ ) {
108
108
109
109
list ( $ menu , $ location ) = $ args ;
110
110
111
- $ menu = wp_get_nav_menu_object ( $ menu );
112
- if ( ! $ menu || is_wp_error ( $ menu ) ) {
113
- WP_CLI ::error ( "Invalid menu. " );
111
+ $ menu_obj = wp_get_nav_menu_object ( $ menu );
112
+ if ( ! $ menu_obj ) {
113
+ WP_CLI ::error ( "Invalid menu $ menu . " );
114
114
}
115
115
116
116
$ locations = get_registered_nav_menus ();
117
117
if ( ! array_key_exists ( $ location , $ locations ) ) {
118
- WP_CLI ::error ( "Invalid location. " );
118
+ WP_CLI ::error ( "Invalid location $ location . " );
119
119
}
120
120
121
121
$ locations = get_nav_menu_locations ();
122
- $ locations [ $ location ] = $ menu ->term_id ;
122
+ $ locations [ $ location ] = $ menu_obj ->term_id ;
123
123
124
124
set_theme_mod ( 'nav_menu_locations ' , $ locations );
125
125
126
- WP_CLI ::success ( "Assigned location to menu. " );
126
+ WP_CLI ::success ( "Assigned location $ location to menu $ menu. " );
127
127
}
128
128
129
129
/**
You can’t perform that action at this time.
0 commit comments