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. git-svn-id: https://develop.svn.wordpress.org/trunk@49241 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
310d8eb83d
commit
6b5b87db58
@ -977,9 +977,7 @@ class WP_Debug_Data {
|
||||
$item = array_merge( $item, array_intersect_key( $plugin, $item ) );
|
||||
}
|
||||
|
||||
$type = 'plugin';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, (object) $item );
|
||||
|
||||
if ( ! is_null( $auto_update_forced ) ) {
|
||||
$enabled = $auto_update_forced;
|
||||
@ -1121,9 +1119,7 @@ class WP_Debug_Data {
|
||||
);
|
||||
}
|
||||
|
||||
$type = 'theme';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
|
||||
|
||||
if ( ! is_null( $auto_update_forced ) ) {
|
||||
$enabled = $auto_update_forced;
|
||||
@ -1209,9 +1205,7 @@ class WP_Debug_Data {
|
||||
);
|
||||
}
|
||||
|
||||
$type = 'theme';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
|
||||
|
||||
if ( ! is_null( $auto_update_forced ) ) {
|
||||
$enabled = $auto_update_forced;
|
||||
@ -1299,9 +1293,7 @@ class WP_Debug_Data {
|
||||
);
|
||||
}
|
||||
|
||||
$type = 'theme';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
|
||||
|
||||
if ( ! is_null( $auto_update_forced ) ) {
|
||||
$enabled = $auto_update_forced;
|
||||
|
@ -181,9 +181,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
||||
|
||||
$filter_payload = array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
|
||||
|
||||
$type = 'theme';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $filter_payload );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );
|
||||
|
||||
if ( ! is_null( $auto_update_forced ) ) {
|
||||
$theme->auto_update_forced = $auto_update_forced;
|
||||
|
@ -229,11 +229,10 @@ class WP_Plugins_List_Table extends WP_List_Table {
|
||||
'requires_php' => '',
|
||||
'compatibility' => new stdClass(),
|
||||
);
|
||||
|
||||
$filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $plugin_data, $filter_payload ) );
|
||||
|
||||
$type = 'plugin';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, $filter_payload );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, $filter_payload );
|
||||
|
||||
if ( ! is_null( $auto_update_forced ) ) {
|
||||
$plugin_data['auto-update-forced'] = $auto_update_forced;
|
||||
|
@ -2398,13 +2398,8 @@ class WP_Site_Health {
|
||||
'requires_php' => '5.6.20',
|
||||
);
|
||||
|
||||
$type = 'plugin';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$test_plugins_enabled = apply_filters( "auto_update_{$type}", true, $mock_plugin );
|
||||
|
||||
$type = 'theme';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$test_themes_enabled = apply_filters( "auto_update_{$type}", true, $mock_theme );
|
||||
$test_plugins_enabled = wp_is_auto_update_forced_for_item( 'plugin', true, $mock_plugin );
|
||||
$test_themes_enabled = wp_is_auto_update_forced_for_item( 'theme', true, $mock_theme );
|
||||
|
||||
$ui_enabled_for_plugins = wp_is_auto_update_enabled_for_type( 'plugin' );
|
||||
$ui_enabled_for_themes = wp_is_auto_update_enabled_for_type( 'theme' );
|
||||
|
@ -716,9 +716,7 @@ function wp_prepare_themes_for_js( $themes = null ) {
|
||||
);
|
||||
}
|
||||
|
||||
$type = 'theme';
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
$auto_update_forced = apply_filters( "auto_update_{$type}", null, $auto_update_filter_payload );
|
||||
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $auto_update_filter_payload );
|
||||
|
||||
$prepared_themes[ $slug ] = array(
|
||||
'id' => $slug,
|
||||
|
@ -1045,6 +1045,22 @@ function wp_is_auto_update_enabled_for_type( $type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether auto-updates are forced for an item.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param string $type The type of update being checked: 'theme' or 'plugin'.
|
||||
* @param bool|null $update Whether to update. The value of null is internally used
|
||||
* to detect whether nothing has hooked into this filter.
|
||||
* @param object $item The update offer.
|
||||
* @return bool True if auto-updates are forced for `$item`, false otherwise.
|
||||
*/
|
||||
function wp_is_auto_update_forced_for_item( $type, $update, $item ) {
|
||||
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
|
||||
return apply_filters( "auto_update_{$type}", $update, $item );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the appropriate auto-update message to be displayed.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user