Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Options: Add 'label' argument to register_setting
  • Loading branch information
Mamaduka committed May 3, 2024
commit 3ef5d4489d557586e1e80100424edfb917405bb8
3 changes: 3 additions & 0 deletions src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,7 @@ function register_initial_settings() {
* @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`.
* Please consider writing more inclusive code.
* @since 6.6.0 Added the `label` argument.
*
* @global array $new_allowed_options
* @global array $wp_registered_settings
Expand All @@ -2782,6 +2783,7 @@ function register_initial_settings() {
*
* @type string $type The type of data associated with this setting.
* 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 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.
Expand All @@ -2802,6 +2804,7 @@ function register_setting( $option_group, $option_name, $args = array() ) {
$defaults = array(
'type' => 'string',
'group' => $option_group,
'label' => '',
'description' => '',
'sanitize_callback' => null,
'show_in_rest' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ protected function get_registered_options() {

$default_schema = array(
'type' => empty( $args['type'] ) ? null : $args['type'],
'label' => empty( $args['label'] ) ? '' : $args['label'],
Copy link
Member Author

@Mamaduka Mamaduka May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyBJacobs, in Gutenberg shim, we used the title key for the schema. Would it make sense to have a direct mapping to the argument here, or is the title key reserved for similar data in schemas?

Gutenberg PR: WordPress/gutenberg#59243

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it should be title as the prop name. That is how it's defined in the JSON Schema spec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification!

'description' => empty( $args['description'] ) ? '' : $args['description'],
'default' => isset( $args['default'] ) ? $args['default'] : null,
);
Expand Down