Skip to content

Commit fd7d178

Browse files
swissspidyclaude
andcommitted
Report an error when the autoload value cannot be stored
set_autoload() ignored the result of $wpdb->update(), so a failed query still printed success. It is now also reached from `wp option update` when only the autoload value changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent e9fcc2b commit fd7d178

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎features/option.feature‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,45 @@ Feature: Manage WordPress options
286286
on
287287
"""
288288
289+
Scenario: Report an error when the autoload value cannot be stored
290+
Given a WP install
291+
And a wp-content/mu-plugins/fail-autoload-update.php file:
292+
"""
293+
<?php
294+
add_filter(
295+
'query',
296+
static function ( $query ) {
297+
if ( false !== strpos( $query, 'SET `autoload` =' ) && false !== strpos( $query, "`option_name` = 'hello'" ) ) {
298+
return 'UPDATE wp_cli_missing_table SET autoload = 1';
299+
}
300+
return $query;
301+
}
302+
);
303+
"""
304+
And I run `wp option add hello world --autoload=on`
305+
306+
When I try `wp option update hello world --autoload=off`
307+
Then STDERR should contain:
308+
"""
309+
Error: Could not update autoload value for 'hello' option.
310+
"""
311+
And STDOUT should not contain:
312+
"""
313+
Success:
314+
"""
315+
And the return code should be 1
316+
317+
When I try `wp option set-autoload hello off`
318+
Then STDERR should contain:
319+
"""
320+
Error: Could not update autoload value for 'hello' option.
321+
"""
322+
And STDOUT should not contain:
323+
"""
324+
Success:
325+
"""
326+
And the return code should be 1
327+
289328
@require-wp-4.2
290329
@less-than-wp-6.6
291330
Scenario: Managed autoloaded options

‎src/Option_Command.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,16 @@ public function set_autoload( $args ) {
564564
return;
565565
}
566566

567-
$wpdb->update(
567+
$updated = $wpdb->update(
568568
$wpdb->options,
569569
array( 'autoload' => $autoload ),
570570
array( 'option_name' => $option )
571571
);
572572

573+
if ( false === $updated ) {
574+
WP_CLI::error( "Could not update autoload value for '{$option}' option." );
575+
}
576+
573577
// Recreate cache refreshing from update_option().
574578
$notoptions = wp_cache_get( 'notoptions', 'options' );
575579

0 commit comments

Comments
 (0)