Security: Add user interface to auto-update themes and plugins.

Building on core update mechanisms, this adds the ability to enable automatic updates for themes and plugins to the WordPress admin. 

Fixes: #50052.
Props: afercia, afragen, audrasjb, azaozz, bookdude13, davidperonne, desrosj, gmays, gmays, javiercasares, karmatosed, knutsp, mapk, mukesh27, netweb, nicolaskulka, nielsdeblaauw, paaljoachim, passoniate, pbiron, pedromendonca, whodunitagency, whyisjake, wpamitkumar, and xkon.

Built from https://develop.svn.wordpress.org/trunk@47835


git-svn-id: http://core.svn.wordpress.org/trunk@47611 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake
2020-05-20 18:49:09 +00:00
parent 2a86d8d534
commit 661b929e1e
28 changed files with 1159 additions and 55 deletions

View File

@@ -435,7 +435,12 @@ function wp_plugin_update_row( $file, $plugin_data ) {
$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
/** @var WP_Plugins_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
$wp_list_table = _get_list_table(
'WP_Plugins_List_Table',
array(
'screen' => get_current_screen(),
)
);
if ( is_network_admin() || ! is_multisite() ) {
if ( is_network_admin() ) {
@@ -933,3 +938,76 @@ function wp_recovery_mode_nag() {
</div>
<?php
}
/**
* Checks whether auto-updates are enabled.
*
* @since 5.5.0
*
* @param string $type The type of update being checked: 'theme' or 'plugin'.
* @return bool True if auto-updates are enabled for `$type`, false otherwise.
*/
function wp_is_auto_update_enabled_for_type( $type ) {
switch ( $type ) {
case 'plugin':
/**
* Filters whether plugins manual auto-update is enabled.
*
* @since 5.5.0
*
* @param bool $enabled True if plugins auto-update is enabled, false otherwise.
*/
return apply_filters( 'wp_plugins_auto_update_enabled', true );
case 'theme':
/**
* Filters whether plugins manual auto-update is enabled.
*
* @since 5.5.0
*
* @param bool True if themes auto-update is enabled, false otherwise.
*/
return apply_filters( 'wp_themes_auto_update_enabled', true );
}
return false;
}
/**
* Determines the appropriate update message to be displayed.
*
* @since 5.5.0
*
* @return string The update message to be shown.
*/
function wp_get_auto_update_message() {
$next_update_time = wp_next_scheduled( 'wp_version_check' );
// Check if event exists.
if ( false === $next_update_time ) {
return __( 'There may be a problem with WP-Cron. Automatic update not scheduled.' );
}
// See if cron is disabled
$cron_disabled = defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON;
if ( $cron_disabled ) {
return __( 'WP-Cron is disabled. Automatic updates not available.' );
}
$time_to_next_update = human_time_diff( intval( $next_update_time ) );
// See if cron is overdue.
$overdue = ( time() - $next_update_time ) > 0;
if ( $overdue ) {
return sprintf(
/* translators: Duration that WP-Cron has been overdue. */
__( 'There may be a problem with WP-Cron. Automatic update overdue by %s.' ),
$time_to_next_update
);
} else {
return sprintf(
/* translators: Time until the next update. */
__( 'Auto-update scheduled in %s.' ),
$time_to_next_update
);
}
}