[wp-trac] [WordPress Trac] #55629: WordPress Settings API should be able to store option as autoload=false

WordPress Trac noreply at wordpress.org
Wed Apr 27 14:02:04 UTC 2022


#55629: WordPress Settings API should be able to store option as autoload=false
-------------------------+-----------------------------
 Reporter:  apermo       |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 As of now, using the WordPress Settings API, any option saved is stored as
 autoload=true.

 The only "solution" you find on stackoverflow is "do an update_option in
 the sanitize function", which actually does not work, since calling
 update_option will fire the sanitize callback and result in a recursion.

 Any other idea would be a hacky solution.

 Suggestion:

 Can we a filter within the {{{ update_options() }}} in {{{ options.php }}}
 to allow to alter it on saving, from checking the code, this is likely the
 quickest solution without completely altering the settings api.


 I would propose the following change to allow filtering of {{{$autoload}}}

 {{{
 Index: public/wp-includes/option.php
 IDEA additional info:
 Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
 <+>UTF-8
 ===================================================================
 diff --git a/public/wp-includes/option.php b/public/wp-includes/option.php
 --- a/public/wp-includes/option.php
 +++ b/public/wp-includes/option.php     (date 1651054674847)
 @@ -461,7 +461,16 @@

         /** This filter is documented in wp-includes/option.php */
         if ( apply_filters( "default_option_{$option}", false, $option,
 false ) === $old_value ) {
 -               // Default setting for new options is 'yes'.
 +               /**
 +                * Filter autoload for an option.
 +                *
 +                * @since tbd
 +                *
 +                * @param string|null $autoload Current value of autoload,
 can be "yes", "no" or null.
 +                */
 +               $autoload = apply_filters( "autoload_option_{$option}",
 $autoload );
 +
 +               // Default setting for options is 'yes'.
                 if ( null === $autoload ) {
                         $autoload = 'yes';
                 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55629>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list