[wp-trac] [WordPress Trac] #57894: update_option() still tries to update integers, floats and booleans that have not changed
WordPress Trac
noreply at wordpress.org
Thu Mar 9 09:18:21 UTC 2023
#57894: update_option() still tries to update integers, floats and booleans that
have not changed
--------------------------------+-----------------------------
Reporter: domainsupport | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: 4.2
Severity: major | Keywords:
Focuses: performance |
--------------------------------+-----------------------------
On line 485 of `/wp-includes/option.php` the `update_option()` function
will return `false` if the new and old value are the same to prevent un-
necessary call to `$wpdb->update()`. Which is great.
However, the condition uses the identical `===` operator so this check
fails because `get_option()` always returns a string (unless called from
memory on the same page load).
This means that the condition fails when `$value` is an integer, float or
boolean and an un-necessary call is then made to `$wpdb->update()` which
then fails and returns `false` anyway.
The following needs to be inserted before this to make sure that the
condition works correctly ...
{{{#!php
<?php
if ( in_array( gettype($value), array( 'boolean', 'integer', 'double' ),
true ) ) {
$value = (string) $value;
}
if ( in_array( gettype($old_value), array( 'boolean', 'integer', 'double'
), true ) ) {
$old_value = (string) $old_value;
}
}}}
The second check is in case `update_option()` is called on the same page
load.
I discovered this whilst trying to get to the bottom of an issue with wp-
cron [ticket:57271].
Oliver
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57894>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list