From cf8ceea86379f79345d7bd16eb18ffd088cf4043 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 9 Oct 2026 17:14:49 +0100 Subject: [PATCH 1/3] Twenty Eleven: Stop passing the sanitize callback as the `register_setting()` arguments. The theme passed its validation callback as the third argument of register_setting(), the signature from before WordPress 4.7, which the function still accepts for backward compatibility. PHPStan reports the call against the documented `$args` array, and the report was baselined. Register the setting without a callback and attach twentyeleven_theme_options_validate() to the option's sanitize filter, which is what register_setting() does with its `sanitize_callback` argument. The `$args` array only exists since 4.7 and the theme supports earlier versions, so this keeps the registration working on both. Remove the matching PHPStan baseline entry. --- .../themes/twentyeleven/inc/theme-options.php | 17 +++++++++++------ tests/phpstan/baselines/argument.type.neon | 5 ----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wp-content/themes/twentyeleven/inc/theme-options.php b/src/wp-content/themes/twentyeleven/inc/theme-options.php index 7b357b835843a..ebb068f39af34 100644 --- a/src/wp-content/themes/twentyeleven/inc/theme-options.php +++ b/src/wp-content/themes/twentyeleven/inc/theme-options.php @@ -28,20 +28,25 @@ function twentyeleven_admin_enqueue_scripts( $hook_suffix ) { * * This function is attached to the admin_init action hook. * - * This call to register_setting() registers a validation callback, twentyeleven_theme_options_validate(), - * which is used when the option is saved, to ensure that our option values are complete, properly - * formatted, and safe. + * The validation callback, twentyeleven_theme_options_validate(), is used when the option is saved, + * to ensure that our option values are complete, properly formatted, and safe. It is attached to the + * option's sanitize filter directly, which is what register_setting() does with the sanitize callback + * passed in its $args array. That array only exists since WordPress 4.7, and passing the callback + * as the third argument instead is the signature from before, so this keeps the theme working on + * both. * * @since Twenty Eleven 1.0 */ 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(). + 'twentyeleven_options', // Options group, see settings_fields() call in twentyeleven_theme_options_render_page(). + 'twentyeleven_theme_options' // Database option, see twentyeleven_get_theme_options(). ); + // The sanitization callback, see twentyeleven_theme_options_validate(). + add_filter( 'sanitize_option_twentyeleven_theme_options', 'twentyeleven_theme_options_validate' ); + // Register our settings field group. add_settings_section( 'general', // Unique identifier for the settings section. diff --git a/tests/phpstan/baselines/argument.type.neon b/tests/phpstan/baselines/argument.type.neon index 193d2aa64f6f3..89172440c47b0 100644 --- a/tests/phpstan/baselines/argument.type.neon +++ b/tests/phpstan/baselines/argument.type.neon @@ -428,11 +428,6 @@ parameters: identifier: argument.type count: 1 path: ../../../src/wp-content/themes/twentyeleven/inc/theme-options.php - - - 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, default\?\: mixed, \.\.\.\}, ''twentyeleven_theme…'' given\.$#' - identifier: argument.type - count: 1 - path: ../../../src/wp-content/themes/twentyeleven/inc/theme-options.php - message: '#^Parameter \#3 \$deps of function wp_enqueue_style expects array\, false given\.$#' identifier: argument.type From dc4056ecfaa34f1dcfae413d012ed3d77852d151 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 20 Oct 2026 16:21:42 -0700 Subject: [PATCH 2/3] Options, Meta APIs: Document `register_setting()` `$args` as `array|callable`. `register_setting()` still accepts a sanitize callback as its third argument for backward compatibility, converting it into the `sanitize_callback` arg. Documenting `$args` as only `array` made PHPStan flag callers that pass a callback, such as Twenty Eleven and the deprecated `add_option_update_handler()`, even though the call is supported. Co-Authored-By: Claude Opus 5.5 --- src/wp-includes/option.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 8bb89b7ceb5a4..1d6962a54690f 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -3047,12 +3047,13 @@ function _wp_register_initial_settings_for_abilities(): void { * @global array $new_allowed_options * @global array $wp_registered_settings * - * @param string $option_group A settings group name. Should correspond to an allowed option key name. - * Default allowed option key names include 'general', 'discussion', 'media', - * 'reading', 'writing', and 'options'. - * @param string $option_name The name of an option to sanitize and save. - * @param array $args { - * Data used to describe the setting when registered. + * @param string $option_group A settings group name. Should correspond to an allowed option key name. + * Default allowed option key names include 'general', 'discussion', 'media', + * 'reading', 'writing', and 'options'. + * @param string $option_name The name of an option to sanitize and save. + * @param array|callable $args { + * Data used to describe the setting when registered. For backward compatibility, a callable + * may be passed instead, which is used as the `$sanitize_callback`. * * @type string $type The type of data associated with this setting. * Valid values are 'string', 'boolean', 'integer', 'number', 'array', From 2cfd72bf07bf61ea4271f6b5068c5815a99388f8 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 20 Oct 2026 16:21:58 -0700 Subject: [PATCH 3/3] Twenty Eleven: Restore passing the sanitize callback to `register_setting()`. This reverts the theme change from cf8ceea863. Now that `register_setting()` documents a callable `$args`, the original call no longer trips PHPStan. Attaching the validator with `add_filter()` instead hid it from the Settings API: it no longer showed as the setting's `sanitize_callback` and `unregister_setting()` no longer removed it, a behavior change for child themes that replace the setting. Co-Authored-By: Claude Opus 5.5 --- .../themes/twentyeleven/inc/theme-options.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/wp-content/themes/twentyeleven/inc/theme-options.php b/src/wp-content/themes/twentyeleven/inc/theme-options.php index ebb068f39af34..7b357b835843a 100644 --- a/src/wp-content/themes/twentyeleven/inc/theme-options.php +++ b/src/wp-content/themes/twentyeleven/inc/theme-options.php @@ -28,25 +28,20 @@ function twentyeleven_admin_enqueue_scripts( $hook_suffix ) { * * This function is attached to the admin_init action hook. * - * The validation callback, twentyeleven_theme_options_validate(), is used when the option is saved, - * to ensure that our option values are complete, properly formatted, and safe. It is attached to the - * option's sanitize filter directly, which is what register_setting() does with the sanitize callback - * passed in its $args array. That array only exists since WordPress 4.7, and passing the callback - * as the third argument instead is the signature from before, so this keeps the theme working on - * both. + * This call to register_setting() registers a validation callback, twentyeleven_theme_options_validate(), + * which is used when the option is saved, to ensure that our option values are complete, properly + * formatted, and safe. * * @since Twenty Eleven 1.0 */ 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_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(). ); - // The sanitization callback, see twentyeleven_theme_options_validate(). - add_filter( 'sanitize_option_twentyeleven_theme_options', 'twentyeleven_theme_options_validate' ); - // Register our settings field group. add_settings_section( 'general', // Unique identifier for the settings section.