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
This commit is contained in:
Tonya Mork 2021-09-09 20:12:58 +00:00
parent ec3b4135da
commit cc1632c046
2 changed files with 14 additions and 10 deletions

View File

@ -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;
}
/**

View File

@ -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;
}
/**