Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions features/theme-mod.feature
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ Feature: Manage WordPress theme mods
Success: Theme mod background_color set to 123456.
"""

Scenario: Setting a theme mod that does not get saved
Given a WP install
And a wp-content/mu-plugins/override-theme-mod.php file:
"""
<?php
add_filter( 'pre_set_theme_mod_background_color', function () {
return 'ffffff';
} );
"""

When I try `wp theme mod set background_color 123456`
Then STDERR should be:
"""
Error: Could not update theme mod background_color.
"""
And STDOUT should be empty
And the return code should be 1

Scenario: Setting a theme mod whose value is changed when it is read
Given a WP install
And a wp-content/mu-plugins/filter-theme-mod.php file:
"""
<?php
add_filter( 'theme_mod_background_color', function () {
return 'ffffff';
} );
"""

When I run `wp theme mod set background_color 123456`
Then STDOUT should be:
"""
Success: Theme mod background_color set to 123456.
"""

Scenario: Removing theme mods
Given a WP install

Expand Down
6 changes: 4 additions & 2 deletions src/Theme_Mod_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,12 @@ public function set( $args, $assoc_args ) {

set_theme_mod( $mod, $value );

if ( get_theme_mod( $mod ) === $value ) {
// Read the stored mods, as a theme_mod_{$mod} filter can change get_theme_mod() without changing what was saved.
$mods = get_theme_mods();
if ( isset( $mods[ $mod ] ) && $mods[ $mod ] === $value ) {
WP_CLI::success( "Theme mod {$mod} set to {$value}." );
} else {
WP_CLI::success( "Could not update theme mod {$mod}." );
WP_CLI::error( "Could not update theme mod {$mod}." );
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
}
Loading