Skip to content

Commit ff2a71f

Browse files
committed
Docs: Allow a callable $args in register_setting().
For backward compatibility, `register_setting()` still accepts a sanitize callback as its third argument, converting it into the `sanitize_callback` argument without a deprecation notice. Its docblock documented `$args` only as an array, so once PHPStan began reading the hash notation in r63420, callers passing a callback were reported, such as Twenty Eleven and the deprecated `add_option_update_handler()`. This form remains in wide use across thousands of plugins and themes in the theme & plugin directories. Developed in #14137. Follow-up to r38635, r63420. Props jorgefilipecosta, westonruter. See #65817, #65860. git-svn-id: https://develop.svn.wordpress.org/trunk@64670 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 48d627a commit ff2a71f

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

‎src/wp-includes/option.php‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,12 +3047,13 @@ function _wp_register_initial_settings_for_abilities(): void {
30473047
* @global array $new_allowed_options
30483048
* @global array $wp_registered_settings
30493049
*
3050-
* @param string $option_group A settings group name. Should correspond to an allowed option key name.
3051-
* Default allowed option key names include 'general', 'discussion', 'media',
3052-
* 'reading', 'writing', and 'options'.
3053-
* @param string $option_name The name of an option to sanitize and save.
3054-
* @param array $args {
3055-
* Data used to describe the setting when registered.
3050+
* @param string $option_group A settings group name. Should correspond to an allowed option key name.
3051+
* Default allowed option key names include 'general', 'discussion', 'media',
3052+
* 'reading', 'writing', and 'options'.
3053+
* @param string $option_name The name of an option to sanitize and save.
3054+
* @param array|callable $args {
3055+
* Data used to describe the setting when registered. For backward compatibility, a callable
3056+
* may be passed instead, which is used as the `$sanitize_callback`.
30563057
*
30573058
* @type string $type The type of data associated with this setting.
30583059
* Valid values are 'string', 'boolean', 'integer', 'number', 'array',

‎tests/phpstan/baselines/argument.type.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,6 @@ parameters:
418418
identifier: argument.type
419419
count: 1
420420
path: ../../../src/wp-content/themes/twentyeleven/inc/theme-options.php
421-
-
422-
message: '#^Parameter \#3 \$args of function register_setting expects array\{type\?\: string, label\?\: string, description\?\: string, sanitize_callback\?\: \(callable\(\)\: mixed\)\|null, show_in_rest\?\: array\|bool, show_in_abilities\?\: array\|bool, default\?\: mixed, \.\.\.\}, ''twentyeleven_theme…'' given\.$#'
423-
identifier: argument.type
424-
count: 1
425-
path: ../../../src/wp-content/themes/twentyeleven/inc/theme-options.php
426421
-
427422
message: '#^Parameter \#3 \$deps of function wp_enqueue_style expects array\<string\>, false given\.$#'
428423
identifier: argument.type

0 commit comments

Comments
 (0)