diff --git a/src/wp-content/themes/twentyeleven/inc/theme-options.php b/src/wp-content/themes/twentyeleven/inc/theme-options.php index 7b357b835843a..74be1c75ae15d 100644 --- a/src/wp-content/themes/twentyeleven/inc/theme-options.php +++ b/src/wp-content/themes/twentyeleven/inc/theme-options.php @@ -39,7 +39,10 @@ function twentyeleven_theme_options_init() { register_setting( 'twentyeleven_options', // Options group, see settings_fields() call in twentyeleven_theme_options_render_page(). 'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options(). - 'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate(). + array( + 'callable' => 'twentyeleven_theme_options_validate', // The sanitization callback, see twentyeleven_theme_options_validate(). + 'autoload' => true, + ) ); // Register our settings field group. diff --git a/src/wp-content/themes/twentyfourteen/inc/featured-content.php b/src/wp-content/themes/twentyfourteen/inc/featured-content.php index 3193aa8b93549..a467d35191be1 100644 --- a/src/wp-content/themes/twentyfourteen/inc/featured-content.php +++ b/src/wp-content/themes/twentyfourteen/inc/featured-content.php @@ -365,7 +365,14 @@ public static function hide_the_featured_term( $terms, $id, $taxonomy ) { * @since Twenty Fourteen 1.0 */ public static function register_setting() { - register_setting( 'featured-content', 'featured-content', array( __CLASS__, 'validate_settings' ) ); + register_setting( + 'featured-content', + 'featured-content', + array( + 'callable' => array( __CLASS__, 'validate_settings' ), + 'autoload' => true, + ) + ); } /** diff --git a/src/wp-includes/blocks/site-logo.php b/src/wp-includes/blocks/site-logo.php index 915563461e30c..680ebcb318d4b 100644 --- a/src/wp-includes/blocks/site-logo.php +++ b/src/wp-includes/blocks/site-logo.php @@ -76,6 +76,7 @@ function register_block_core_site_logo_setting() { 'type' => 'integer', 'label' => __( 'Logo' ), 'description' => __( 'Site logo.' ), + 'autoload' => true, ) ); } @@ -96,6 +97,7 @@ function register_block_core_site_icon_setting() { 'type' => 'integer', 'label' => __( 'Icon' ), 'description' => __( 'Site icon.' ), + 'autoload' => true, ) ); } diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 7979c119a986f..5bfac286d1603 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -1317,6 +1317,13 @@ function wp_determine_option_autoload_value( $option, $value, $serialized_value, return 'off'; } + $wp_registered_settings = get_registered_settings(); + if ( isset( $wp_registered_settings[ $option ]['autoload'] ) ) { + $default_autoload_value = ( bool ) $wp_registered_settings[ $option ]['autoload']; + } else { + $default_autoload_value = null; + } + /** * Allows to determine the default autoload value for an option where no explicit value is passed. * @@ -1328,7 +1335,7 @@ function wp_determine_option_autoload_value( $option, $value, $serialized_value, * @param mixed $value The passed option value to be saved. * @param mixed $serialized_value The passed option value to be saved, in serialized form. */ - $autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value ); + $autoload = apply_filters( 'wp_default_autoload_value',$default_autoload_value , $option, $value, $serialized_value ); if ( is_bool( $autoload ) ) { return $autoload ? 'auto-on' : 'auto-off'; } @@ -2749,6 +2756,7 @@ function register_initial_settings() { 'type' => 'string', 'label' => __( 'Title' ), 'description' => __( 'Site title.' ), + 'autoload' => true, ) ); @@ -2762,6 +2770,7 @@ function register_initial_settings() { 'type' => 'string', 'label' => __( 'Tagline' ), 'description' => __( 'Site tagline.' ), + 'autoload' => false, ) ); @@ -2778,6 +2787,7 @@ function register_initial_settings() { ), 'type' => 'string', 'description' => __( 'Site URL.' ), + 'autoload' => false, ) ); } @@ -2795,6 +2805,7 @@ function register_initial_settings() { ), 'type' => 'string', 'description' => __( 'This address is used for admin purposes, like new user notification.' ), + 'autoload' => false, ) ); } @@ -2808,6 +2819,7 @@ function register_initial_settings() { ), 'type' => 'string', 'description' => __( 'A city in the same timezone as you.' ), + 'autoload' => true, ) ); @@ -2818,6 +2830,7 @@ function register_initial_settings() { 'show_in_rest' => true, 'type' => 'string', 'description' => __( 'A date format for all date strings.' ), + 'autoload' => true, ) ); @@ -2828,6 +2841,7 @@ function register_initial_settings() { 'show_in_rest' => true, 'type' => 'string', 'description' => __( 'A time format for all time strings.' ), + 'autoload' => false, ) ); @@ -2838,6 +2852,7 @@ function register_initial_settings() { 'show_in_rest' => true, 'type' => 'integer', 'description' => __( 'A day number of the week that the week should start on.' ), + 'autoload' => false, ) ); @@ -2851,6 +2866,7 @@ function register_initial_settings() { 'type' => 'string', 'description' => __( 'WordPress locale code.' ), 'default' => 'en_US', + 'autoload' => true, ) ); @@ -2862,6 +2878,7 @@ function register_initial_settings() { 'type' => 'boolean', 'description' => __( 'Convert emoticons like :-) and :-P to graphics on display.' ), 'default' => true, + 'autoload' => true, ) ); @@ -2872,6 +2889,7 @@ function register_initial_settings() { 'show_in_rest' => true, 'type' => 'integer', 'description' => __( 'Default post category.' ), + 'autoload' => false, ) ); @@ -2882,6 +2900,7 @@ function register_initial_settings() { 'show_in_rest' => true, 'type' => 'string', 'description' => __( 'Default post format.' ), + 'autoload' => false, ) ); @@ -2894,6 +2913,7 @@ function register_initial_settings() { 'label' => __( 'Maximum posts per page' ), 'description' => __( 'Blog pages show at most.' ), 'default' => 10, + 'autoload' => true, ) ); @@ -2905,6 +2925,7 @@ function register_initial_settings() { 'type' => 'string', 'label' => __( 'Show on front' ), 'description' => __( 'What to show on the front page' ), + 'autoload' => true, ) ); @@ -2916,6 +2937,7 @@ function register_initial_settings() { 'type' => 'integer', 'label' => __( 'Page on front' ), 'description' => __( 'The ID of the page that should be displayed on the front page' ), + 'autoload' => true, ) ); @@ -2926,6 +2948,7 @@ function register_initial_settings() { 'show_in_rest' => true, 'type' => 'integer', 'description' => __( 'The ID of the page that should display the latest posts' ), + 'autoload' => true, ) ); @@ -2940,6 +2963,7 @@ function register_initial_settings() { ), 'type' => 'string', 'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ), + 'autoload' => true, ) ); @@ -2955,6 +2979,7 @@ function register_initial_settings() { 'type' => 'string', 'label' => __( 'Allow comments on new posts' ), 'description' => __( 'Allow people to submit comments on new posts.' ), + 'autoload' => true, ) ); } @@ -2989,6 +3014,7 @@ function register_initial_settings() { * When registering complex settings, this argument may optionally be an * array with a 'schema' key. * @type mixed $default Default value when calling `get_option()`. + * @type bool $autoload Should this setting be set to autoload for all pages, default is false * } */ function register_setting( $option_group, $option_name, $args = array() ) { @@ -3007,6 +3033,7 @@ function register_setting( $option_group, $option_name, $args = array() ) { 'description' => '', 'sanitize_callback' => null, 'show_in_rest' => false, + 'autoload' => false, ); // Back-compat: old sanitize callback is added. diff --git a/tests/phpunit/tests/option/registration.php b/tests/phpunit/tests/option/registration.php index 850376498e91a..cac089f522a13 100644 --- a/tests/phpunit/tests/option/registration.php +++ b/tests/phpunit/tests/option/registration.php @@ -162,4 +162,47 @@ public function test_unregister_invalid_setting_does_not_throw_notice_or_warning unregister_setting( $setting, $setting ); $this->assertFalse( has_filter( 'default_option_' . $setting, 'filter_default_option' ) ); } + + /** + * @ticket 61522 + * + * @covers ::register_setting + * + * @dataProvider data_provider_register_setting_sets_autoload + */ + public function test_register_setting_sets_autoload( $autoload, $expected ) { + global $wpdb; + + register_setting( + 'test_group', + 'test_default', + array( + 'autoload' => $autoload, + ) + ); + $added = add_option( 'test_default', 'Autoload test' ); + $this->assertTrue( $added ); + + $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'test_default' ) ); + $this->assertSame( $expected, $actual->autoload ); + + $added = update_option( 'test_default', 'Autoload tested' ); + $this->assertTrue( $added ); + + $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'test_default' ) ); + $this->assertSame( $expected, $actual->autoload ); + } + + public function data_provider_register_setting_sets_autoload() { + return array( + 'autoloaded' => array( + 'autoload' => true, + 'expected' => 'auto-on', + ), + 'not_autoloaded' => array( + 'autoload' => false, + 'expected' => 'auto-off', + ), + ); + } }