Make WordPress Core

Changeset 49241


Ignore:
Timestamp:
10/20/2020 05:37:16 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Introduce a wrapper for the auto_update_{$type} filter checks.

This allows for cleaner checks whether auto-updates are forced for a plugin or theme.

Follow-up to [48750].

Props rebasaurus, garrett-eclipse, SergeyBiryukov.
Fixes #50875.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r48802 r49241  
    978978                                }
    979979
    980                                 $type = 'plugin';
    981                                 /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    982                                 $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
     980                                $auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, (object) $item );
    983981
    984982                                if ( ! is_null( $auto_update_forced ) ) {
    … …  
    11221120                        }
    11231121
    1124                         $type = 'theme';
    1125                         /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    1126                         $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
     1122                        $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
    11271123
    11281124                        if ( ! is_null( $auto_update_forced ) ) {
    … …  
    12101206                                }
    12111207
    1212                                 $type = 'theme';
    1213                                 /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    1214                                 $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
     1208                                $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
    12151209
    12161210                                if ( ! is_null( $auto_update_forced ) ) {
    … …  
    13001294                                }
    13011295
    1302                                 $type = 'theme';
    1303                                 /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    1304                                 $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
     1296                                $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
    13051297
    13061298                                if ( ! is_null( $auto_update_forced ) ) {
    … …  
    13281320
    13291321                                $theme_version_string       .= ' | ' . $auto_updates_string;
    1330                                 $theme_version_string_debug .= ',' . $auto_updates_string;
     1322                                $theme_version_string_debug .= ', ' . $auto_updates_string;
    13311323                        }
    13321324
  • trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php

    r49108 r49241  
    182182                        $filter_payload = array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
    183183
    184                         $type = 'theme';
    185                         /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    186                         $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $filter_payload );
     184                        $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );
    187185
    188186                        if ( ! is_null( $auto_update_forced ) ) {
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r48968 r49241  
    230230                                'compatibility' => new stdClass(),
    231231                        );
     232
    232233                        $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $plugin_data, $filter_payload ) );
    233234
    234                         $type = 'plugin';
    235                         /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    236                         $auto_update_forced = apply_filters( "auto_update_{$type}", null, $filter_payload );
     235                        $auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, $filter_payload );
    237236
    238237                        if ( ! is_null( $auto_update_forced ) ) {
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r49237 r49241  
    23992399                );
    24002400
    2401                 $type = 'plugin';
    2402                 /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    2403                 $test_plugins_enabled = apply_filters( "auto_update_{$type}", true, $mock_plugin );
    2404 
    2405                 $type = 'theme';
    2406                 /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    2407                 $test_themes_enabled = apply_filters( "auto_update_{$type}", true, $mock_theme );
     2401                $test_plugins_enabled = wp_is_auto_update_forced_for_item( 'plugin', true, $mock_plugin );
     2402                $test_themes_enabled  = wp_is_auto_update_forced_for_item( 'theme', true, $mock_theme );
    24082403
    24092404                $ui_enabled_for_plugins = wp_is_auto_update_enabled_for_type( 'plugin' );
  • trunk/src/wp-admin/includes/theme.php

    r49011 r49241  
    717717                }
    718718
    719                 $type = 'theme';
    720                 /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
    721                 $auto_update_forced = apply_filters( "auto_update_{$type}", null, $auto_update_filter_payload );
     719                $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $auto_update_filter_payload );
    722720
    723721                $prepared_themes[ $slug ] = array(
  • trunk/src/wp-admin/includes/update.php

    r49108 r49241  
    10471047
    10481048/**
     1049 * Checks whether auto-updates are forced for an item.
     1050 *
     1051 * @since 5.6.0
     1052 *
     1053 * @param string    $type   The type of update being checked: 'theme' or 'plugin'.
     1054 * @param bool|null $update Whether to update. The value of null is internally used
     1055 *                          to detect whether nothing has hooked into this filter.
     1056 * @param object    $item   The update offer.
     1057 * @return bool True if auto-updates are forced for `$item`, false otherwise.
     1058 */
     1059function wp_is_auto_update_forced_for_item( $type, $update, $item ) {
     1060        /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
     1061        return apply_filters( "auto_update_{$type}", $update, $item );
     1062}
     1063
     1064/**
    10491065 * Determines the appropriate auto-update message to be displayed.
    10501066 *
Note: See TracChangeset for help on using the changeset viewer.