Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#55629 closed enhancement (duplicate)

WordPress Settings API should be able to store option as autoload=false

Reported by: apermo's profile apermo 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)

#1 @SergeyBiryukov
2 years ago

  • Component changed from General to Options, Meta APIs

#2 @SergeyBiryukov
2 years ago

  • Focuses performance added

#3 @SergeyBiryukov
2 years ago

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

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.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.