#55629 closed enhancement (duplicate)
WordPress Settings API should be able to store option as autoload=false
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Options, Meta APIs | Keywords: | |
| Focuses: | performance | Cc: |
Description
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';
}
Change History (3)
Note: See
TracTickets for help on using
tickets.
Hi there, welcome back to WordPress Trac! Thanks for the ticket.
It looks like a similar ticket was submitted a few days earlier: #55584, let's continue the discussion there.