WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/20/2020 06:47:24 PM (11 months ago)
Author:
whyisjake
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/update.php

    r47808 r47835  
    436436
    437437    /** @var WP_Plugins_List_Table $wp_list_table */
    438     $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
     438    $wp_list_table = _get_list_table(
     439        'WP_Plugins_List_Table',
     440        array(
     441            'screen' => get_current_screen(),
     442        )
     443    );
    439444
    440445    if ( is_network_admin() || ! is_multisite() ) {
     
    934939    <?php
    935940}
     941
     942/**
     943 * Checks whether auto-updates are enabled.
     944 *
     945 * @since 5.5.0
     946 *
     947 * @param string $type    The type of update being checked: 'theme' or 'plugin'.
     948 * @return bool True if auto-updates are enabled for `$type`, false otherwise.
     949 */
     950function wp_is_auto_update_enabled_for_type( $type ) {
     951    switch ( $type ) {
     952        case 'plugin':
     953            /**
     954             * Filters whether plugins manual auto-update is enabled.
     955             *
     956             * @since 5.5.0
     957             *
     958             * @param bool $enabled True if plugins auto-update is enabled, false otherwise.
     959             */
     960            return apply_filters( 'wp_plugins_auto_update_enabled', true );
     961        case 'theme':
     962            /**
     963             * Filters whether plugins manual auto-update is enabled.
     964             *
     965             * @since 5.5.0
     966             *
     967             * @param bool True if themes auto-update is enabled, false otherwise.
     968             */
     969            return apply_filters( 'wp_themes_auto_update_enabled', true );
     970    }
     971
     972    return false;
     973}
     974
     975/**
     976 * Determines the appropriate update message to be displayed.
     977 *
     978 * @since 5.5.0
     979 *
     980 * @return string The update message to be shown.
     981 */
     982function wp_get_auto_update_message() {
     983    $next_update_time = wp_next_scheduled( 'wp_version_check' );
     984
     985    // Check if event exists.
     986    if ( false === $next_update_time ) {
     987        return __( 'There may be a problem with WP-Cron. Automatic update not scheduled.' );
     988    }
     989
     990    // See if cron is disabled
     991    $cron_disabled = defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON;
     992    if ( $cron_disabled ) {
     993        return __( 'WP-Cron is disabled. Automatic updates not available.' );
     994    }
     995
     996    $time_to_next_update = human_time_diff( intval( $next_update_time ) );
     997
     998    // See if cron is overdue.
     999    $overdue = ( time() - $next_update_time ) > 0;
     1000    if ( $overdue ) {
     1001        return sprintf(
     1002            /* translators: Duration that WP-Cron has been overdue. */
     1003            __( 'There may be a problem with WP-Cron. Automatic update overdue by %s.' ),
     1004            $time_to_next_update
     1005        );
     1006    } else {
     1007        return sprintf(
     1008            /* translators: Time until the next update. */
     1009            __( 'Auto-update scheduled in %s.' ),
     1010            $time_to_next_update
     1011        );
     1012    }
     1013}
Note: See TracChangeset for help on using the changeset viewer.