[wp-trac] [WordPress Trac] #59246: update_option returns true, even when the value didn't change, potentially adding back old data

WordPress Trac noreply at wordpress.org
Wed Feb 7 10:24:15 UTC 2024


#59246: update_option returns true, even when the value didn't change, potentially
adding back old data
--------------------------------------+------------------------------
 Reporter:  malthert                  |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Options, Meta APIs        |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------

Comment (by kkmuffme):

 We encountered this issue also within the same request in cases where an
 apply filters/do action callback modified an option value, which it turned
 out is an extremely common issue and requires manual mitigation at the
 moment.

 Simple reproduction case:

 {{{#!php
 <?php

 $foo = get_option( 'foo' );

 do_action( 'hello' ); // any callback may update the option value of
 'foo', but any changes would be overwritten by the call to update_option
 below

 $foo = apply_filters( 'filter_foo', $foo ); // any callback may update the
 option value of 'foo', but any changes would be overwritten by the call to
 update_option below

 update_option( 'foo', $foo );

 }}}


 I created a PR that adds a 4th optional argument as well as a specific
 function for update_option to require the old value for atomic updates.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59246#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list