mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@51789 git-svn-id: http://core.svn.wordpress.org/trunk@51396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f2f05f8e04
commit
68e0c5e520
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-51788';
|
||||
$wp_version = '5.9-alpha-51789';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user