Make WordPress Core

Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#57894 closed defect (bug) (duplicate)

update_option() still tries to update integers, floats and booleans that have not changed

Reported by: domainsupport's profile domainsupport Owned by:
Milestone: Priority: normal
Severity: major Version: 4.2
Component: Options, Meta APIs Keywords:
Focuses: performance Cc:

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

Change History (2)

#1 @SergeyBiryukov
18 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, thanks for the ticket!

We're already tracking this issue in #22192.

#2 @domainsupport
18 months ago

Thank you. I did try to look to see if it had already been reported but didn't look back far enough (10 years!).

Oliver

Note: See TracTickets for help on using tickets.