File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,6 +159,40 @@ Feature: Manage WordPress theme mods
159159 Success: Theme mod background_color set to 123456.
160160 """
161161
162+ Scenario : Setting a theme mod that does not get saved
163+ Given a WP install
164+ And a wp-content/mu-plugins/override-theme-mod.php file:
165+ """
166+ <?php
167+ add_filter( 'pre_set_theme_mod_background_color', function () {
168+ return 'ffffff';
169+ } );
170+ """
171+
172+ When I try `wp theme mod set background_color 123456`
173+ Then STDERR should be:
174+ """
175+ Error: Could not update theme mod background_color.
176+ """
177+ And STDOUT should be empty
178+ And the return code should be 1
179+
180+ Scenario : Setting a theme mod whose value is changed when it is read
181+ Given a WP install
182+ And a wp-content/mu-plugins/filter-theme-mod.php file:
183+ """
184+ <?php
185+ add_filter( 'theme_mod_background_color', function () {
186+ return 'ffffff';
187+ } );
188+ """
189+
190+ When I run `wp theme mod set background_color 123456`
191+ Then STDOUT should be:
192+ """
193+ Success: Theme mod background_color set to 123456.
194+ """
195+
162196 Scenario : Removing theme mods
163197 Given a WP install
164198
Original file line number Diff line number Diff line change @@ -338,10 +338,12 @@ public function set( $args, $assoc_args ) {
338338
339339 set_theme_mod ( $ mod , $ value );
340340
341- if ( get_theme_mod ( $ mod ) === $ value ) {
341+ // Read the stored mods, as a theme_mod_{$mod} filter can change get_theme_mod() without changing what was saved.
342+ $ mods = get_theme_mods ();
343+ if ( isset ( $ mods [ $ mod ] ) && $ mods [ $ mod ] === $ value ) {
342344 WP_CLI ::success ( "Theme mod {$ mod } set to {$ value }. " );
343345 } else {
344- WP_CLI ::success ( "Could not update theme mod {$ mod }. " );
346+ WP_CLI ::error ( "Could not update theme mod {$ mod }. " );
345347 }
346348 }
347349}
You can’t perform that action at this time.
0 commit comments