#57894 closed defect (bug) (duplicate)
update_option() still tries to update integers, floats and booleans that have not changed
| Reported by: | domainsupport | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Options, Meta APIs | Version: | 4.2 |
| Severity: | major | Keywords: | |
| Cc: | Focuses: | performance |
Description
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 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 57271.
Oliver
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi there, thanks for the ticket!
We're already tracking this issue in #22192.