diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
index 2e8e0172d4..7a182c48d6 100644
|
a
|
b
|
function wp_prepare_themes_for_js( $themes = null ) {
|
| 652 | 652 | ); |
| 653 | 653 | } |
| 654 | 654 | |
| | 655 | $autoupdated_themes = get_option( 'wp_autoupdated_themes', array() ); |
| | 656 | $is_autoupdated_enabled = null; |
| | 657 | if ( in_array( $slug, $autoupdated_themes, true ) ) { |
| | 658 | $is_autoupdated_enabled = true; |
| | 659 | } |
| | 660 | |
| 655 | 661 | $prepared_themes[ $slug ] = array( |
| 656 | 662 | 'id' => $slug, |
| 657 | 663 | 'name' => $theme->display( 'Name' ), |
| … |
… |
function wp_prepare_themes_for_js( $themes = null ) {
|
| 666 | 672 | 'hasUpdate' => isset( $updates[ $slug ] ), |
| 667 | 673 | 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ), |
| 668 | 674 | 'update' => get_theme_update_available( $theme ), |
| | 675 | 'autoupdated' => $is_autoupdated_enabled, |
| 669 | 676 | 'actions' => array( |
| 670 | 677 | 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, |
| 671 | 678 | 'customize' => $customize_action, |
| 672 | 679 | '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, |
| 673 | 681 | ), |
| 674 | 682 | ); |
| 675 | 683 | } |
diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php
index ccd918eae9..fdba385e0f 100644
|
a
|
b
|
if ( current_user_can( 'switch_themes' ) && isset( $_GET['action'] ) ) {
|
| 53 | 53 | |
| 54 | 54 | wp_redirect( admin_url( 'themes.php?resumed=true' ) ); |
| 55 | 55 | 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 | $autoupdated_themes = get_option( 'wp_autoupdated_themes', array() ); |
| | 70 | if ( ! in_array( $slug, $autoupdated_themes, true ) ) { |
| | 71 | $autoupdate_action = 'enable'; |
| | 72 | $autoupdated_themes[] = $slug; |
| | 73 | } else { |
| | 74 | $autoupdate_action = 'disable'; |
| | 75 | $autoupdated_themes = array_diff( $autoupdated_themes, array( $slug ) ); |
| | 76 | } |
| | 77 | |
| | 78 | update_option( 'wp_autoupdated_themes', $autoupdated_themes ); |
| | 79 | |
| | 80 | wp_redirect( admin_url( 'themes.php?autoupdated=' . $autoupdate_action ) ); |
| | 81 | exit; |
| 56 | 82 | } elseif ( 'delete' == $_GET['action'] ) { |
| 57 | 83 | check_admin_referer( 'delete-theme_' . $_GET['stylesheet'] ); |
| 58 | 84 | $theme = wp_get_theme( $_GET['stylesheet'] ); |
| … |
… |
if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) {
|
| 228 | 254 | ?> |
| 229 | 255 | <div id="message6" class="error"><p><?php _e( 'Theme could not be resumed because it triggered a <strong>fatal error</strong>.' ); ?></p></div> |
| 230 | 256 | <?php |
| | 257 | } elseif ( isset( $_GET['autoupdated'] ) ) { |
| | 258 | $autoupdated_themes = get_option( 'wp_autoupdated_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 |
| 231 | 266 | } |
| 232 | 267 | |
| 233 | 268 | $ct = wp_get_theme(); |
| … |
… |
foreach ( $themes as $theme ) :
|
| 362 | 397 | $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); |
| 363 | 398 | ?> |
| 364 | 399 | <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> |
| | 400 | <?php |
| | 401 | /* translators: %s: Theme name. */ |
| | 402 | $aria_label_enable = sprintf( _x( 'Enable automatic update for %s', 'theme' ), '{{ data.name }}' ); |
| | 403 | $aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' ); |
| | 404 | ?> |
| | 405 | <# if ( data.autoupdated ) { #> |
| | 406 | <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_disable; ?>"><?php _e( 'Disable auto update' ); ?></a> |
| | 407 | <# } else { #> |
| | 408 | <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_enable; ?>"><?php _e( 'Enable auto update' ); ?></a> |
| | 409 | <# } #> |
| 365 | 410 | <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?> |
| 366 | 411 | <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a> |
| 367 | 412 | <?php } ?> |
| … |
… |
if ( ! is_multisite() && current_user_can( 'edit_themes' ) && $broken_themes ) {
|
| 573 | 618 | <div class="notice notice-warning notice-alt notice-large"> |
| 574 | 619 | <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3> |
| 575 | 620 | {{{ data.update }}} |
| | 621 | <# if ( data.autoupdated ) { #> |
| | 622 | <?php |
| | 623 | $next_update_time = wp_next_scheduled( 'wp_version_check' ); |
| | 624 | $time_to_next_update = human_time_diff( intval( $next_update_time ) ); |
| | 625 | $autoupdate = sprintf( |
| | 626 | /* translators: Time until the next update. */ |
| | 627 | __( 'Automatic update scheduled in %s.' ), |
| | 628 | $time_to_next_update |
| | 629 | ); |
| | 630 | ?> |
| | 631 | <p class="theme-autoupdate-enabled"><?php echo $autoupdate; ?></p> |
| | 632 | <# } #> |
| 576 | 633 | </div> |
| 577 | 634 | <# } #> |
| 578 | 635 | <p class="theme-description">{{{ data.description }}}</p> |
| … |
… |
if ( ! is_multisite() && current_user_can( 'edit_themes' ) && $broken_themes ) {
|
| 605 | 662 | <# if ( data.actions.activate ) { #> |
| 606 | 663 | <a href="{{{ data.actions.activate }}}" class="button activate" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a> |
| 607 | 664 | <# } #> |
| | 665 | <?php |
| | 666 | /* translators: %s: Theme name. */ |
| | 667 | $aria_label_enable = sprintf( _x( 'Enable automatic update for %s', 'theme' ), '{{ data.name }}' ); |
| | 668 | $aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' ); |
| | 669 | ?> |
| | 670 | <# if ( data.autoupdated ) { #> |
| | 671 | <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_disable; ?>"><?php _e( 'Disable auto update' ); ?></a> |
| | 672 | <# } else { #> |
| | 673 | <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_enable; ?>"><?php _e( 'Enable auto update' ); ?></a> |
| | 674 | <# } #> |
| 608 | 675 | <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a> |
| 609 | 676 | </div> |
| 610 | 677 | |
diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php
index 2093201149..0d0794ad4c 100644
|
a
|
b
|
function list_theme_updates() {
|
| 478 | 478 | |
| 479 | 479 | <tbody class="plugins"> |
| 480 | 480 | <?php |
| | 481 | $wp_autoupdated_themes = get_option( 'wp_autoupdated_themes', array() ); |
| | 482 | |
| 481 | 483 | foreach ( $themes as $stylesheet => $theme ) { |
| 482 | 484 | $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) ); |
| | 485 | |
| | 486 | $autoupdate = ''; |
| | 487 | if ( in_array( $stylesheet, $wp_autoupdated_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 = ' <span 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 .= '</span> '; |
| | 497 | } |
| 483 | 498 | ?> |
| 484 | 499 | <tr> |
| 485 | 500 | <td class="check-column"> |
| … |
… |
function list_theme_updates() {
|
| 501 | 516 | $theme->display( 'Version' ), |
| 502 | 517 | $theme->update['new_version'] |
| 503 | 518 | ); |
| | 519 | echo $autoupdate; |
| 504 | 520 | ?> |
| 505 | 521 | </p></td> |
| 506 | 522 | </tr> |
diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php
index dfb27b2aad..04d3444d16 100644
|
a
|
b
|
if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
|
| 813 | 813 | return; |
| 814 | 814 | } |
| 815 | 815 | |
| | 816 | function wp_auto_update_theme( $update, $item ) { |
| | 817 | $wp_autoupdated_themes = get_option( 'wp_autoupdated_themes', array() ); |
| | 818 | if ( in_array( $item->theme, $wp_autoupdated_themes, true ) ) { |
| | 819 | return true; |
| | 820 | } else { |
| | 821 | return $update; |
| | 822 | } |
| | 823 | } |
| | 824 | |
| 816 | 825 | add_action( 'admin_init', '_maybe_update_core' ); |
| 817 | 826 | add_action( 'wp_version_check', 'wp_version_check' ); |
| 818 | 827 | |
| … |
… |
add_action( 'wp_update_themes', 'wp_update_themes' );
|
| 831 | 840 | add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 ); |
| 832 | 841 | |
| 833 | 842 | add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); |
| | 843 | add_filter( 'auto_update_theme', 'wp_auto_update_theme', 10, 2 ); |
| 834 | 844 | |
| 835 | 845 | add_action( 'init', 'wp_schedule_update_checks' ); |