[wp-trac] [WordPress Trac] #58964: Introduce dedicated function to set autoload value of an option already in the database

WordPress Trac noreply at wordpress.org
Fri Sep 1 19:55:26 UTC 2023


#58964: Introduce dedicated function to set autoload value of an option already in
the database
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:  flixos90
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  6.4
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests needs-dev-  |     Focuses:
  note                                           |  performance
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"56508" 56508]:
 {{{
 #!CommitTicketReference repository="" revision="56508"
 Options, Meta APIs: Introduce `wp_set_option_autoload_values()`.

 This function accepts an associative array of option names and their
 autoload values to set, and it will update those values in the database in
 bulk, only for those options where the autoload field is not already set
 to the given value.

 Two wrapper functions for ease of use accompany the new main function:
 * `wp_set_options_autoload( $options, $autoload )` can be used to set
 multiple options to the same autoload value.
 * `wp_set_option_autoload( $option, $autoload )` can be used to set the
 autoload value for a single option.

 All of these functions allow changing the autoload value of an option,
 which previously has only been possible in combination with updating the
 value. This limitation prevented some relevant use-cases: For example, a
 plugin deactivation hook could set all of its options to not autoload, as
 a cleanup routine, while not actually deleting any data. The plugin's
 activation hook could then implement the reverse, resetting those options'
 autoload values to the originally intended ones for when using the plugin.

 Props boonebgorges, joemcgill, costdev, mukesh27, SergeyBiryukov,
 tabrisrp, flixos90.
 Fixes #58964.
 }}}

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


More information about the wp-trac mailing list