Skip to content

Commit d1c9ce9

Browse files
authored
Respect --position when moving a widget to another sidebar (#95)
1 parent 4838d3c commit d1c9ce9

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎features/widget.feature‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ Feature: Manage widgets in WordPress sidebar
110110
| name | position | options |
111111
| archives | 2 | {"title":"New Archives","count":0,"dropdown":0} |
112112

113+
Scenario: Move a widget to a position in another sidebar
114+
When I run `wp widget move archives-1 --sidebar-id=sidebar-2 --position=2`
115+
Then STDOUT should be:
116+
"""
117+
Success: Widget moved.
118+
"""
119+
120+
When I run `wp widget list sidebar-2 --fields=id,position`
121+
Then STDOUT should be a table containing rows:
122+
| id | position |
123+
| search-2 | 1 |
124+
| archives-1 | 2 |
125+
113126
Scenario: Patch widget options
114127
When I run `wp widget patch update archives-1 title "Patched Archives"`
115128
Then STDOUT should be:

‎src/Widget_Command.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public function move( $args, $assoc_args ) {
361361

362362
$new_sidebar_index = ! empty( $assoc_args['position'] ) ? $assoc_args['position'] - 1 : $current_sidebar_index;
363363
// Moving between sidebars adds to the top.
364-
if ( $new_sidebar_id !== $current_sidebar_id && $new_sidebar_index === $current_sidebar_index ) {
364+
if ( $new_sidebar_id !== $current_sidebar_id && empty( $assoc_args['position'] ) ) {
365365
// Human-readable positions are different than numerically indexed array.
366366
$new_sidebar_index = 0;
367367
}

0 commit comments

Comments
 (0)