File tree 2 files changed +32
-7
lines changed
2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,28 @@ 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
+ Then STDOUT should be:
48
+ """
49
+ Success: Assigned location primary to menu secondary-menu.
50
+ """
51
+
52
+ When I run `wp menu list --fields=slug,locations`
53
+ Then STDOUT should be a table containing rows:
54
+ | slug | locations |
55
+ | primary -menu | |
56
+ | secondary -menu | primary |
Original file line number Diff line number Diff line change @@ -100,30 +100,30 @@ function($o) {
100
100
* ## EXAMPLES
101
101
*
102
102
* $ wp menu location assign primary-menu primary
103
- * Success: Assigned location to menu.
103
+ * Success: Assigned location primary to menu primary- menu.
104
104
*
105
105
* @subcommand assign
106
106
*/
107
107
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