From 653790b83c335998cea5083cc3b07faa4e207d0b Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 9 Sep 2021 14:31:13 +0000 Subject: [PATCH] Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Customize_Setting::sanitize()`. In each child class: renames the parameter to match the parent's method signature. Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match. Changes for readability: - `@since` clearly specifies the original parameter name and its new name as well as why the change happened. - In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made. Follow-up to [19995], [32806]. Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion. See #51553. git-svn-id: https://develop.svn.wordpress.org/trunk@51783 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-setting.php | 2 +- .../class-wp-customize-nav-menu-item-setting.php | 8 ++++++-- .../customize/class-wp-customize-nav-menu-setting.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-customize-setting.php b/src/wp-includes/class-wp-customize-setting.php index 752593fa61..c10285e1c3 100644 --- a/src/wp-includes/class-wp-customize-setting.php +++ b/src/wp-includes/class-wp-customize-setting.php @@ -559,7 +559,7 @@ class WP_Customize_Setting { * * @since 3.4.0 * - * @param string|array $value The value to sanitize. + * @param string|array $value The value to sanitize. * @return string|array|null|WP_Error Sanitized value, or `null`/`WP_Error` if invalid. */ public function sanitize( $value ) { diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php index 18cf83dfda..8e35e32238 100644 --- a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php +++ b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php @@ -653,12 +653,16 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { * we remove that in this override. * * @since 4.3.0 + * @since 5.9.0 Renamed `$menu_item_value` to `$value` for PHP 8 named parameter support. * - * @param array $menu_item_value The value to sanitize. + * @param array $value The menu item value to sanitize. * @return array|false|null|WP_Error Null or WP_Error if an input isn't valid. False if it is marked for deletion. * Otherwise the sanitized value. */ - public function sanitize( $menu_item_value ) { + public function sanitize( $value ) { + // Restores the more descriptive, specific name for use within this method. + $menu_item_value = $value; + // Menu is marked for deletion. if ( false === $menu_item_value ) { return $menu_item_value; diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php index 8962606e5c..c3dc1e9eb5 100644 --- a/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php +++ b/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php @@ -407,7 +407,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting { * * @since 4.3.0 * - * @param array $value The value to sanitize. + * @param array $value The menu value to sanitize. * @return array|false|null Null if an input isn't valid. False if it is marked for deletion. * Otherwise the sanitized value. */