Options: Add 'label' argument to register_setting.

The 'label' will displayed to users when editing core or custom settings via block editors. It avoids hardcoding Settings labels and improves extensibility.

Backports https://github.com/WordPress/gutenberg/pull/59243.

Props mamaduka, timothyblynjacobs, ellatrix.

Fixes #61023.


Built from https://develop.svn.wordpress.org/trunk@58230


git-svn-id: http://core.svn.wordpress.org/trunk@57693 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ellatrix 2024-05-29 08:53:09 +00:00
parent d2eed678ab
commit 396851e0ae
3 changed files with 11 additions and 1 deletions

View File

@ -2659,6 +2659,7 @@ function register_initial_settings() {
'name' => 'title', 'name' => 'title',
), ),
'type' => 'string', 'type' => 'string',
'label' => __( 'Title' ),
'description' => __( 'Site title.' ), 'description' => __( 'Site title.' ),
) )
); );
@ -2671,6 +2672,7 @@ function register_initial_settings() {
'name' => 'description', 'name' => 'description',
), ),
'type' => 'string', 'type' => 'string',
'label' => __( 'Tagline' ),
'description' => __( 'Site tagline.' ), 'description' => __( 'Site tagline.' ),
) )
); );
@ -2801,6 +2803,7 @@ function register_initial_settings() {
array( array(
'show_in_rest' => true, 'show_in_rest' => true,
'type' => 'integer', 'type' => 'integer',
'label' => __( 'Maximum posts per page' ),
'description' => __( 'Blog pages show at most.' ), 'description' => __( 'Blog pages show at most.' ),
'default' => 10, 'default' => 10,
) )
@ -2812,6 +2815,7 @@ function register_initial_settings() {
array( array(
'show_in_rest' => true, 'show_in_rest' => true,
'type' => 'string', 'type' => 'string',
'label' => __( 'Show on front' ),
'description' => __( 'What to show on the front page' ), 'description' => __( 'What to show on the front page' ),
) )
); );
@ -2822,6 +2826,7 @@ function register_initial_settings() {
array( array(
'show_in_rest' => true, 'show_in_rest' => true,
'type' => 'integer', 'type' => 'integer',
'label' => __( 'Page on front' ),
'description' => __( 'The ID of the page that should be displayed on the front page' ), 'description' => __( 'The ID of the page that should be displayed on the front page' ),
) )
); );
@ -2860,6 +2865,7 @@ function register_initial_settings() {
), ),
), ),
'type' => 'string', 'type' => 'string',
'label' => __( 'Allow comments on new posts' ),
'description' => __( 'Allow people to submit comments on new posts.' ), 'description' => __( 'Allow people to submit comments on new posts.' ),
) )
); );
@ -2874,6 +2880,7 @@ function register_initial_settings() {
* @since 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`. * @since 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`.
* @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`. * @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`.
* Please consider writing more inclusive code. * Please consider writing more inclusive code.
* @since 6.6.0 Added the `label` argument.
* *
* @global array $new_allowed_options * @global array $new_allowed_options
* @global array $wp_registered_settings * @global array $wp_registered_settings
@ -2887,6 +2894,7 @@ function register_initial_settings() {
* *
* @type string $type The type of data associated with this setting. * @type string $type The type of data associated with this setting.
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'. * Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
* @type string $label A label of the data attached to this setting.
* @type string $description A description of the data attached to this setting. * @type string $description A description of the data attached to this setting.
* @type callable $sanitize_callback A callback function that sanitizes the option's value. * @type callable $sanitize_callback A callback function that sanitizes the option's value.
* @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API. * @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API.
@ -2907,6 +2915,7 @@ function register_setting( $option_group, $option_name, $args = array() ) {
$defaults = array( $defaults = array(
'type' => 'string', 'type' => 'string',
'group' => $option_group, 'group' => $option_group,
'label' => '',
'description' => '', 'description' => '',
'sanitize_callback' => null, 'sanitize_callback' => null,
'show_in_rest' => false, 'show_in_rest' => false,

View File

@ -237,6 +237,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
$default_schema = array( $default_schema = array(
'type' => empty( $args['type'] ) ? null : $args['type'], 'type' => empty( $args['type'] ) ? null : $args['type'],
'title' => empty( $args['label'] ) ? '' : $args['label'],
'description' => empty( $args['description'] ) ? '' : $args['description'], 'description' => empty( $args['description'] ) ? '' : $args['description'],
'default' => isset( $args['default'] ) ? $args['default'] : null, 'default' => isset( $args['default'] ) ? $args['default'] : null,
); );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-alpha-58229'; $wp_version = '6.6-alpha-58230';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.