Make WordPress Core


Ignore:
Timestamp:
05/20/2020 06:47:24 PM (6 years 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/class-wp-debug-data.php

    r47762 r47835  
    859859                $plugins        = get_plugins();
    860860                $plugin_updates = get_plugin_updates();
     861                $auto_updates   = array();
     862
     863                $auto_updates_enabled      = wp_is_auto_update_enabled_for_type( 'plugin' );
     864                $auto_updates_enabled_str  = __( 'Auto-updates enabled' );
     865                $auto_updates_disabled_str = __( 'Auto-updates disabled' );
     866
     867                if ( $auto_updates_enabled ) {
     868                        $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
     869                }
    861870
    862871                foreach ( $plugins as $plugin_path => $plugin ) {
     
    893902                        }
    894903
     904                        if ( $auto_updates_enabled ) {
     905                                if ( in_array( $plugin_path, $auto_updates, true ) ) {
     906                                        $plugin_version_string       .= ' | ' . $auto_updates_enabled_str;
     907                                        $plugin_version_string_debug .= ', ' . $auto_updates_enabled_str;
     908                                } else {
     909                                        $plugin_version_string       .= ' | ' . $auto_updates_disabled_str;
     910                                        $plugin_version_string_debug .= ', ' . $auto_updates_disabled_str;
     911                                }
     912                        }
     913
    895914                        $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
    896915                                'label' => $plugin['Name'],
     
    915934                $active_theme_version       = $active_theme->version;
    916935                $active_theme_version_debug = $active_theme_version;
     936
     937                $auto_updates         = array();
     938                $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
     939                if ( $auto_updates_enabled ) {
     940                        $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
     941                }
    917942
    918943                if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
     
    9811006                        ),
    9821007                );
    983 
     1008                if ( $auto_updates_enabled ) {
     1009                        if ( in_array( $active_theme->stylesheet, $auto_updates ) ) {
     1010                                $theme_auto_update_string = __( 'Enabled' );
     1011                        } else {
     1012                                $theme_auto_update_string = __( 'Disabled' );
     1013                        }
     1014
     1015                        $info['wp-active-theme']['fields']['auto_update'] = array(
     1016                                'label' => __( 'Auto-update' ),
     1017                                'value' => $theme_auto_update_string,
     1018                                'debug' => $theme_auto_update_string,
     1019                        );
     1020                }
    9841021                $parent_theme = $active_theme->parent();
    9851022
     
    10271064                                ),
    10281065                        );
     1066                        if ( $auto_updates_enabled ) {
     1067                                if ( in_array( $parent_theme->stylesheet, $auto_updates ) ) {
     1068                                        $parent_theme_auto_update_string = __( 'Enabled' );
     1069                                } else {
     1070                                        $parent_theme_auto_update_string = __( 'Disabled' );
     1071                                }
     1072
     1073                                $info['wp-parent-theme']['fields']['auto_update'] = array(
     1074                                        'label' => __( 'Auto-update' ),
     1075                                        'value' => $parent_theme_auto_update_string,
     1076                                        'debug' => $parent_theme_auto_update_string,
     1077                                );
     1078                        }
    10291079                }
    10301080
     
    10741124                                $theme_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
    10751125                                $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
     1126                        }
     1127
     1128                        if ( $auto_updates_enabled ) {
     1129                                if ( in_array( $theme_slug, $auto_updates ) ) {
     1130                                        $theme_version_string       .= ' | ' . $auto_updates_enabled_str;
     1131                                        $theme_version_string_debug .= ',' . $auto_updates_enabled_str;
     1132                                } else {
     1133                                        $theme_version_string       .= ' | ' . $auto_updates_disabled_str;
     1134                                        $theme_version_string_debug .= ', ' . $auto_updates_disabled_str;
     1135                                }
    10761136                        }
    10771137
Note: See TracChangeset for help on using the changeset viewer.