Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/wp-content/themes/twentyeleven/inc/theme-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,14 @@
* @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,

Check failure on line 373 in src/wp-content/themes/twentyfourteen/inc/featured-content.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array item not aligned correctly; expected 16 spaces but found 17
)
);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/blocks/site-logo.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function register_block_core_site_logo_setting() {
'type' => 'integer',
'label' => __( 'Logo' ),
'description' => __( 'Site logo.' ),
'autoload' => true,
)
);
}
Expand All @@ -96,6 +97,7 @@ function register_block_core_site_icon_setting() {
'type' => 'integer',
'label' => __( 'Icon' ),
'description' => __( 'Site icon.' ),
'autoload' => true,
)
);
}
Expand Down
29 changes: 28 additions & 1 deletion src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,13 @@
return 'off';
}

$wp_registered_settings = get_registered_settings();
if ( isset( $wp_registered_settings[ $option ]['autoload'] ) ) {
$default_autoload_value = ( bool ) $wp_registered_settings[ $option ]['autoload'];

Check failure on line 1322 in src/wp-includes/option.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Cast statements must not contain whitespace; expected "(bool)" but found "( bool )"
} else {
$default_autoload_value = null;
}

/**
* Allows to determine the default autoload value for an option where no explicit value is passed.
*
Expand All @@ -1328,7 +1335,7 @@
* @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 );

Check failure on line 1338 in src/wp-includes/option.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Space found before comma in argument list

Check failure on line 1338 in src/wp-includes/option.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

No space found after comma in argument list
if ( is_bool( $autoload ) ) {
return $autoload ? 'auto-on' : 'auto-off';
}
Expand Down Expand Up @@ -2749,6 +2756,7 @@
'type' => 'string',
'label' => __( 'Title' ),
'description' => __( 'Site title.' ),
'autoload' => true,
)
);

Expand All @@ -2762,6 +2770,7 @@
'type' => 'string',
'label' => __( 'Tagline' ),
'description' => __( 'Site tagline.' ),
'autoload' => false,
)
);

Expand All @@ -2778,6 +2787,7 @@
),
'type' => 'string',
'description' => __( 'Site URL.' ),
'autoload' => false,
)
);
}
Expand All @@ -2795,6 +2805,7 @@
),
'type' => 'string',
'description' => __( 'This address is used for admin purposes, like new user notification.' ),
'autoload' => false,
)
);
}
Expand All @@ -2808,6 +2819,7 @@
),
'type' => 'string',
'description' => __( 'A city in the same timezone as you.' ),
'autoload' => true,
)
);

Expand All @@ -2818,6 +2830,7 @@
'show_in_rest' => true,
'type' => 'string',
'description' => __( 'A date format for all date strings.' ),
'autoload' => true,
)
);

Expand All @@ -2828,6 +2841,7 @@
'show_in_rest' => true,
'type' => 'string',
'description' => __( 'A time format for all time strings.' ),
'autoload' => false,
)
);

Expand All @@ -2838,6 +2852,7 @@
'show_in_rest' => true,
'type' => 'integer',
'description' => __( 'A day number of the week that the week should start on.' ),
'autoload' => false,
)
);

Expand All @@ -2851,6 +2866,7 @@
'type' => 'string',
'description' => __( 'WordPress locale code.' ),
'default' => 'en_US',
'autoload' => true,
)
);

Expand All @@ -2862,6 +2878,7 @@
'type' => 'boolean',
'description' => __( 'Convert emoticons like :-) and :-P to graphics on display.' ),
'default' => true,
'autoload' => true,
)
);

Expand All @@ -2872,6 +2889,7 @@
'show_in_rest' => true,
'type' => 'integer',
'description' => __( 'Default post category.' ),
'autoload' => false,
)
);

Expand All @@ -2882,6 +2900,7 @@
'show_in_rest' => true,
'type' => 'string',
'description' => __( 'Default post format.' ),
'autoload' => false,
)
);

Expand All @@ -2894,6 +2913,7 @@
'label' => __( 'Maximum posts per page' ),
'description' => __( 'Blog pages show at most.' ),
'default' => 10,
'autoload' => true,
)
);

Expand All @@ -2905,6 +2925,7 @@
'type' => 'string',
'label' => __( 'Show on front' ),
'description' => __( 'What to show on the front page' ),
'autoload' => true,
)
);

Expand All @@ -2916,6 +2937,7 @@
'type' => 'integer',
'label' => __( 'Page on front' ),
'description' => __( 'The ID of the page that should be displayed on the front page' ),
'autoload' => true,
)
);

Expand All @@ -2926,6 +2948,7 @@
'show_in_rest' => true,
'type' => 'integer',
'description' => __( 'The ID of the page that should display the latest posts' ),
'autoload' => true,
)
);

Expand All @@ -2940,6 +2963,7 @@
),
'type' => 'string',
'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ),
'autoload' => true,
)
);

Expand All @@ -2955,6 +2979,7 @@
'type' => 'string',
'label' => __( 'Allow comments on new posts' ),
'description' => __( 'Allow people to submit comments on new posts.' ),
'autoload' => true,
)
);
}
Expand Down Expand Up @@ -2989,6 +3014,7 @@
* 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() ) {
Expand All @@ -3007,6 +3033,7 @@
'description' => '',
'sanitize_callback' => null,
'show_in_rest' => false,
'autoload' => false,
);

// Back-compat: old sanitize callback is added.
Expand Down
43 changes: 43 additions & 0 deletions tests/phpunit/tests/option/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
);
}
}
Loading