Make WordPress Core

Ticket #49199: 49199.2.diff

File 49199.2.diff, 9.1 KB (added by audrasjb, 3 years ago)

Multisite support

  • src/wp-admin/css/themes.css

    diff --git a/src/wp-admin/css/themes.css b/src/wp-admin/css/themes.css
    index 2b26a75f49..79c70fada8 100644
    a b body.folded .theme-browser ~ .theme-overlay .theme-wrap { 
    688688        line-height: inherit;
    689689}
    690690
    691 .theme-overlay .theme-author a {
     691.theme-overlay .theme-author a,
     692.theme-overlay .theme-autoupdate a {
    692693        text-decoration: none;
    693694}
    694695
  • src/wp-admin/includes/theme.php

    diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
    index 2e8e0172d4..1420b91e6c 100644
    a b function wp_prepare_themes_for_js( $themes = null ) { 
    652652                        );
    653653                }
    654654
     655                $$wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
     656                $is_autoupdated_enabled = null;
     657                if ( in_array( $slug, $wp_auto_update_themes, true ) ) {
     658                        $is_autoupdated_enabled = true;
     659                }
     660
    655661                $prepared_themes[ $slug ] = array(
    656662                        'id'           => $slug,
    657663                        'name'         => $theme->display( 'Name' ),
    function wp_prepare_themes_for_js( $themes = null ) { 
    666672                        'hasUpdate'    => isset( $updates[ $slug ] ),
    667673                        'hasPackage'   => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
    668674                        'update'       => get_theme_update_available( $theme ),
     675                        'autoupdated'  => $is_autoupdated_enabled,
    669676                        'actions'      => array(
    670677                                'activate'  => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
    671678                                'customize' => $customize_action,
    672679                                'delete'    => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
     680                                'autoupdate' => current_user_can( 'update_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=autoupdate&stylesheet=' . $encoded_slug ), 'autoupdate-theme_' . $slug ) : null,
    673681                        ),
    674682                );
    675683        }
  • src/wp-admin/themes.php

    diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php
    index 244f573ce6..005401e263 100644
    a b if ( current_user_can( 'switch_themes' ) && isset( $_GET['action'] ) ) { 
    5353
    5454                wp_redirect( admin_url( 'themes.php?resumed=true' ) );
    5555                exit;
     56        } elseif ( 'autoupdate' == $_GET['action'] ) {
     57                check_admin_referer( 'autoupdate-theme_' . $_GET['stylesheet'] );
     58                $theme = wp_get_theme( $_GET['stylesheet'] );
     59                $slug = $theme->get_stylesheet();
     60
     61                if ( ! current_user_can( 'update_themes' ) ) {
     62                        wp_die(
     63                                '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
     64                                '<p>' . __( 'Sorry, you are not allowed to enable automatic update for themes.' ) . '</p>',
     65                                403
     66                        );
     67                }
     68
     69                $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
     70                if ( ! in_array( $slug, $wp_auto_update_themes, true ) ) {
     71                        $autoupdate_action    = 'enable';
     72                        $wp_auto_update_themes[] = $slug;
     73                } else {
     74                        $autoupdate_action    = 'disable';
     75                        $wp_auto_update_themes = array_diff( $wp_auto_update_themes, array( $slug ) );
     76                }
     77
     78                update_site_option( 'wp_auto_update_themes', $wp_auto_update_themes );
     79
     80                wp_redirect( admin_url( 'themes.php?autoupdated=' . $autoupdate_action ) );
     81                exit;
    5682        } elseif ( 'delete' == $_GET['action'] ) {
    5783                check_admin_referer( 'delete-theme_' . $_GET['stylesheet'] );
    5884                $theme = wp_get_theme( $_GET['stylesheet'] );
    if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) { 
    228254        ?>
    229255        <div id="message6" class="error"><p><?php _e( 'Theme could not be resumed because it triggered a <strong>fatal error</strong>.' ); ?></p></div>
    230256        <?php
     257} elseif ( isset( $_GET['autoupdated'] ) ) {
     258        $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
     259        $autoupdate_notice  = __( 'The selected theme won’t update automatically anymore.' );
     260        if ( 'enable' === $_GET['autoupdated'] ) {
     261                $autoupdate_notice = __( 'The selected theme will now update automatically.' );
     262        }
     263        ?>
     264        <div id="message7" class="updated notice is-dismissible"><p><?php echo $autoupdate_notice; ?></p></div>
     265        <?php
    231266}
    232267
    233268$ct = wp_get_theme();
    foreach ( $themes as $theme ) : 
    359394                        $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    360395                        ?>
    361396                        <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
     397                        <?php
     398                        /* translators: %s: Theme name. */
     399                        $aria_label_enable  = sprintf( _x( 'Enable automatic update for %s', 'theme' ), '{{ data.name }}' );
     400                        $aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' );
     401                        ?>
     402                        <# if ( data.autoupdated ) { #>
     403                                <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_disable; ?>"><?php _e( 'Disable auto update' ); ?></a>
     404                        <# } else { #>
     405                                <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_enable; ?>"><?php _e( 'Enable auto update' ); ?></a>
     406                        <# } #>
    362407                        <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
    363408                                <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
    364409                        <?php } ?>
    if ( ! is_multisite() && current_user_can( 'edit_themes' ) && $broken_themes ) { 
    562607                                        printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' );
    563608                                        ?>
    564609                                </p>
    565 
     610                                <p class="theme-autoupdate">
     611                                        <?php
     612                                        /* translators: %s: Theme name. */
     613                                        $aria_label_enable  = sprintf( _x( 'Enable automatic update for %s', 'theme' ), '{{ data.name }}' );
     614                                        $aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' );
     615                                        ?>
     616                                        <# if ( data.autoupdated ) { #>
     617                                                <a href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_disable; ?>"><span class="dashicons dashicons-update" aria-hidden="true"></span> <?php _e( 'Disable automatic updates' ); ?></a>
     618                                        <# } else { #>
     619                                                <a href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_enable; ?>"><span class="dashicons dashicons-update" aria-hidden="true"></span> <?php _e( 'Enable automatic updates' ); ?></a>
     620                                        <# } #>
     621                                </p>
    566622                                <# if ( data.hasUpdate ) { #>
    567623                                <div class="notice notice-warning notice-alt notice-large">
    568624                                        <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
    569625                                        {{{ data.update }}}
     626                                        <# if ( data.autoupdated ) { #>
     627                                                <?php
     628                                                $next_update_time = wp_next_scheduled( 'wp_version_check' );
     629                                                $time_to_next_update = human_time_diff( intval( $next_update_time ) );
     630                                                $autoupdate = sprintf(
     631                                                        /* translators: Time until the next update. */
     632                                                        __( 'Automatic update scheduled in %s.' ),
     633                                                        $time_to_next_update
     634                                                );
     635                                                ?>
     636                                                <p class="theme-autoupdate-enabled"><?php echo $autoupdate; ?></p>
     637                                        <# } #>
    570638                                </div>
    571639                                <# } #>
    572640                                <p class="theme-description">{{{ data.description }}}</p>
  • src/wp-admin/update-core.php

    diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php
    index 2093201149..a4d5eb022b 100644
    a b function list_theme_updates() { 
    478478
    479479        <tbody class="plugins">
    480480        <?php
     481        $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
     482
    481483        foreach ( $themes as $stylesheet => $theme ) {
    482484                $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
     485
     486                $autoupdate = '';
     487                if ( in_array( $stylesheet, $wp_auto_update_themes, true ) ) {
     488                        $next_update_time = wp_next_scheduled( 'wp_version_check' );
     489                        $time_to_next_update = human_time_diff( intval( $next_update_time ) );
     490                        $autoupdate = ' <p class="theme-autoupdate-enabled">';
     491                        $autoupdate .= sprintf(
     492                                /* translators: Time until the next update. */
     493                                __( 'Automatic update scheduled in %s.' ),
     494                                $time_to_next_update
     495                        );
     496                        $autoupdate .= '</p> ';
     497                }
    483498                ?>
    484499        <tr>
    485500                <td class="check-column">
    function list_theme_updates() { 
    501516                                $theme->display( 'Version' ),
    502517                                $theme->update['new_version']
    503518                        );
     519                        echo $autoupdate;
    504520                        ?>
    505521                </p></td>
    506522        </tr>
  • src/wp-includes/update.php

    diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php
    index dfb27b2aad..65844317e8 100644
    a b if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) { 
    813813        return;
    814814}
    815815
     816function wp_auto_update_theme( $update, $item ) {
     817        $$wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
     818        if ( in_array( $item->theme, $wp_auto_update_themes, true ) ) {
     819                return true;
     820        } else {
     821                return $update;
     822        }
     823}
     824
    816825add_action( 'admin_init', '_maybe_update_core' );
    817826add_action( 'wp_version_check', 'wp_version_check' );
    818827
    add_action( 'wp_update_themes', 'wp_update_themes' ); 
    831840add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 );
    832841
    833842add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
     843add_filter( 'auto_update_theme', 'wp_auto_update_theme', 10, 2 );
    834844
    835845add_action( 'init', 'wp_schedule_update_checks' );