From cc1632c046b815d377374097798485c5a9d520b9 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 9 Sep 2021 20:12:58 +0000 Subject: [PATCH] Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Widget::update()`. 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. Adds @since to clearly specify why the change happened. Replaces the original with the variable name with within each method. Why? The new name is more specific and descriptive, which improves readability. Follow-up to [10782], [25090], [26556], [40640]. Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion. See #51553. git-svn-id: https://develop.svn.wordpress.org/trunk@51789 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentyfourteen/inc/widgets.php | 14 ++++++++------ src/wp-includes/widgets/class-wp-widget-media.php | 10 ++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/wp-content/themes/twentyfourteen/inc/widgets.php b/src/wp-content/themes/twentyfourteen/inc/widgets.php index d8d15c2ba4..397b2fc0d8 100644 --- a/src/wp-content/themes/twentyfourteen/inc/widgets.php +++ b/src/wp-content/themes/twentyfourteen/inc/widgets.php @@ -262,20 +262,22 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget { * Here is where any validation should happen. * * @since Twenty Fourteen 1.0 + * @since Twenty Fourteen 3.3 Renamed `$instance` to `$old_instance` to match + * parent class for PHP 8 named parameter support. * * @param array $new_instance New widget instance. - * @param array $instance Original widget instance. + * @param array $old_instance Original widget instance. * @return array Updated widget instance. */ - function update( $new_instance, $instance ) { - $instance['title'] = strip_tags( $new_instance['title'] ); - $instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] ); + function update( $new_instance, $old_instance ) { + $old_instance['title'] = strip_tags( $new_instance['title'] ); + $old_instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] ); if ( in_array( $new_instance['format'], $this->formats, true ) ) { - $instance['format'] = $new_instance['format']; + $old_instance['format'] = $new_instance['format']; } - return $instance; + return $old_instance; } /** diff --git a/src/wp-includes/widgets/class-wp-widget-media.php b/src/wp-includes/widgets/class-wp-widget-media.php index 25016fd268..b6eaff793e 100644 --- a/src/wp-includes/widgets/class-wp-widget-media.php +++ b/src/wp-includes/widgets/class-wp-widget-media.php @@ -259,16 +259,18 @@ abstract class WP_Widget_Media extends WP_Widget { * Sanitizes the widget form values as they are saved. * * @since 4.8.0 + * @since 5.9.0 Renamed `$instance` to `$old_instance` to match parent class + * for PHP 8 named parameter support. * * @see WP_Widget::update() * @see WP_REST_Request::has_valid_params() * @see WP_REST_Request::sanitize_params() * * @param array $new_instance Values just sent to be saved. - * @param array $instance Previously saved values from database. + * @param array $old_instance Previously saved values from database. * @return array Updated safe values to be saved. */ - public function update( $new_instance, $instance ) { + public function update( $new_instance, $old_instance ) { $schema = $this->get_instance_schema(); foreach ( $schema as $field => $field_schema ) { @@ -303,10 +305,10 @@ abstract class WP_Widget_Media extends WP_Widget { if ( is_wp_error( $value ) ) { continue; } - $instance[ $field ] = $value; + $old_instance[ $field ] = $value; } - return $instance; + return $old_instance; } /**