Make WordPress Core

Changeset 52997


Ignore:
Timestamp:
03/27/2022 02:43:25 PM (20 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-plugin-upgrader.php

    r52351 r52997  
    506506     * @since 4.1.0 Added a return value.
    507507     *
    508      * @param bool|WP_Error $return Upgrade offer return.
    509      * @param array         $plugin Plugin package arguments.
    510      * @return bool|WP_Error The passed in $return param or WP_Error.
    511      */
    512     public function deactivate_plugin_before_upgrade( $return, $plugin ) {
    513 
    514         if ( is_wp_error( $return ) ) { // Bypass.
    515             return $return;
     508     * @param bool|WP_Error $response The installation response before the installation has started.
     509     * @param array         $plugin   Plugin package arguments.
     510     * @return bool|WP_Error The original `$response` parameter or WP_Error.
     511     */
     512    public function deactivate_plugin_before_upgrade( $response, $plugin ) {
     513
     514        if ( is_wp_error( $response ) ) { // Bypass.
     515            return $response;
    516516        }
    517517
    518518        // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
    519519        if ( wp_doing_cron() ) {
    520             return $return;
     520            return $response;
    521521        }
    522522
     
    531531        }
    532532
    533         return $return;
     533        return $response;
    534534    }
    535535
     
    541541     * @since 5.4.0
    542542     *
    543      * @param bool|WP_Error $return Upgrade offer return.
    544      * @param array         $plugin Plugin package arguments.
    545      * @return bool|WP_Error The passed in $return param or WP_Error.
    546      */
    547     public function active_before( $return, $plugin ) {
    548         if ( is_wp_error( $return ) ) {
    549             return $return;
     543     * @param bool|WP_Error $response The installation response before the installation has started.
     544     * @param array         $plugin   Plugin package arguments.
     545     * @return bool|WP_Error The original `$response` parameter or WP_Error.
     546     */
     547    public function active_before( $response, $plugin ) {
     548        if ( is_wp_error( $response ) ) {
     549            return $response;
    550550        }
    551551
    552552        // Only enable maintenance mode when in cron (background update).
    553553        if ( ! wp_doing_cron() ) {
    554             return $return;
     554            return $response;
    555555        }
    556556
     
    559559        // Only run if plugin is active.
    560560        if ( ! is_plugin_active( $plugin ) ) {
    561             return $return;
     561            return $response;
    562562        }
    563563
     
    567567        }
    568568
    569         return $return;
     569        return $response;
    570570    }
    571571
     
    577577     * @since 5.4.0
    578578     *
    579      * @param bool|WP_Error $return Upgrade offer return.
    580      * @param array         $plugin Plugin package arguments.
    581      * @return bool|WP_Error The passed in $return param or WP_Error.
    582      */
    583     public function active_after( $return, $plugin ) {
    584         if ( is_wp_error( $return ) ) {
    585             return $return;
     579     * @param bool|WP_Error $response The installation response after the installation has finished.
     580     * @param array         $plugin   Plugin package arguments.
     581     * @return bool|WP_Error The original `$response` parameter or WP_Error.
     582     */
     583    public function active_after( $response, $plugin ) {
     584        if ( is_wp_error( $response ) ) {
     585            return $response;
    586586        }
    587587
    588588        // Only disable maintenance mode when in cron (background update).
    589589        if ( ! wp_doing_cron() ) {
    590             return $return;
     590            return $response;
    591591        }
    592592
    593593        $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
    594594
    595         // Only run if plugin is active
     595        // Only run if plugin is active.
    596596        if ( ! is_plugin_active( $plugin ) ) {
    597             return $return;
     597            return $response;
    598598        }
    599599
     
    603603        }
    604604
    605         return $return;
     605        return $response;
    606606    }
    607607
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r52986 r52997  
    478478
    479479        /**
    480          * Filters the install response before the installation has started.
     480         * Filters the installation response before the installation has started.
    481481         *
    482482         * Returning a value that could be evaluated as a `WP_Error` will effectively
     
    485485         * @since 2.8.0
    486486         *
    487          * @param bool|WP_Error $response   Response.
     487         * @param bool|WP_Error $response   Installation response.
    488488         * @param array         $hook_extra Extra arguments passed to hooked filters.
    489489         */
Note: See TracChangeset for help on using the changeset viewer.