Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-plugin-upgrader.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit renames the `$return` variable in `Plugin_Upgrader` class methods to `$response` and updates the documentation accordingly.

Follow-up to [47409], [52946], [52996].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52997


git-svn-id: http://core.svn.wordpress.org/trunk@52586 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-03-27 14:45:04 +00:00
parent 6ada28a47b
commit 0cde19b503
3 changed files with 30 additions and 30 deletions

View File

@ -505,19 +505,19 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 2.8.0 * @since 2.8.0
* @since 4.1.0 Added a return value. * @since 4.1.0 Added a return value.
* *
* @param bool|WP_Error $return Upgrade offer return. * @param bool|WP_Error $response The installation response before the installation has started.
* @param array $plugin Plugin package arguments. * @param array $plugin Plugin package arguments.
* @return bool|WP_Error The passed in $return param or WP_Error. * @return bool|WP_Error The original `$response` parameter or WP_Error.
*/ */
public function deactivate_plugin_before_upgrade( $return, $plugin ) { public function deactivate_plugin_before_upgrade( $response, $plugin ) {
if ( is_wp_error( $return ) ) { // Bypass. if ( is_wp_error( $response ) ) { // Bypass.
return $return; return $response;
} }
// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it. // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
if ( wp_doing_cron() ) { if ( wp_doing_cron() ) {
return $return; return $response;
} }
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
@ -530,7 +530,7 @@ class Plugin_Upgrader extends WP_Upgrader {
deactivate_plugins( $plugin, true ); deactivate_plugins( $plugin, true );
} }
return $return; return $response;
} }
/** /**
@ -540,25 +540,25 @@ class Plugin_Upgrader extends WP_Upgrader {
* *
* @since 5.4.0 * @since 5.4.0
* *
* @param bool|WP_Error $return Upgrade offer return. * @param bool|WP_Error $response The installation response before the installation has started.
* @param array $plugin Plugin package arguments. * @param array $plugin Plugin package arguments.
* @return bool|WP_Error The passed in $return param or WP_Error. * @return bool|WP_Error The original `$response` parameter or WP_Error.
*/ */
public function active_before( $return, $plugin ) { public function active_before( $response, $plugin ) {
if ( is_wp_error( $return ) ) { if ( is_wp_error( $response ) ) {
return $return; return $response;
} }
// Only enable maintenance mode when in cron (background update). // Only enable maintenance mode when in cron (background update).
if ( ! wp_doing_cron() ) { if ( ! wp_doing_cron() ) {
return $return; return $response;
} }
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
// Only run if plugin is active. // Only run if plugin is active.
if ( ! is_plugin_active( $plugin ) ) { if ( ! is_plugin_active( $plugin ) ) {
return $return; return $response;
} }
// Change to maintenance mode. Bulk edit handles this separately. // Change to maintenance mode. Bulk edit handles this separately.
@ -566,7 +566,7 @@ class Plugin_Upgrader extends WP_Upgrader {
$this->maintenance_mode( true ); $this->maintenance_mode( true );
} }
return $return; return $response;
} }
/** /**
@ -576,25 +576,25 @@ class Plugin_Upgrader extends WP_Upgrader {
* *
* @since 5.4.0 * @since 5.4.0
* *
* @param bool|WP_Error $return Upgrade offer return. * @param bool|WP_Error $response The installation response after the installation has finished.
* @param array $plugin Plugin package arguments. * @param array $plugin Plugin package arguments.
* @return bool|WP_Error The passed in $return param or WP_Error. * @return bool|WP_Error The original `$response` parameter or WP_Error.
*/ */
public function active_after( $return, $plugin ) { public function active_after( $response, $plugin ) {
if ( is_wp_error( $return ) ) { if ( is_wp_error( $response ) ) {
return $return; return $response;
} }
// Only disable maintenance mode when in cron (background update). // Only disable maintenance mode when in cron (background update).
if ( ! wp_doing_cron() ) { if ( ! wp_doing_cron() ) {
return $return; return $response;
} }
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
// Only run if plugin is active // Only run if plugin is active.
if ( ! is_plugin_active( $plugin ) ) { if ( ! is_plugin_active( $plugin ) ) {
return $return; return $response;
} }
// Time to remove maintenance mode. Bulk edit handles this separately. // Time to remove maintenance mode. Bulk edit handles this separately.
@ -602,7 +602,7 @@ class Plugin_Upgrader extends WP_Upgrader {
$this->maintenance_mode( false ); $this->maintenance_mode( false );
} }
return $return; return $response;
} }
/** /**

View File

@ -477,14 +477,14 @@ class WP_Upgrader {
$this->skin->feedback( 'installing_package' ); $this->skin->feedback( 'installing_package' );
/** /**
* Filters the install response before the installation has started. * Filters the installation response before the installation has started.
* *
* Returning a value that could be evaluated as a `WP_Error` will effectively * Returning a value that could be evaluated as a `WP_Error` will effectively
* short-circuit the installation, returning that value instead. * short-circuit the installation, returning that value instead.
* *
* @since 2.8.0 * @since 2.8.0
* *
* @param bool|WP_Error $response Response. * @param bool|WP_Error $response Installation response.
* @param array $hook_extra Extra arguments passed to hooked filters. * @param array $hook_extra Extra arguments passed to hooked filters.
*/ */
$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] ); $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-alpha-52996'; $wp_version = '6.0-alpha-52997';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.