Ticket #49199: 49199.3.diff
File 49199.3.diff, 10.2 KB (added by , 5 years ago) |
---|
-
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 { 688 688 line-height: inherit; 689 689 } 690 690 691 .theme-overlay .theme-author a { 691 .theme-overlay .theme-author a, 692 .theme-overlay .theme-autoupdate a { 692 693 text-decoration: none; 693 694 } 694 695 -
src/wp-admin/includes/theme.php
diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 2e8e0172d4..7389bef60d 100644
a b function wp_prepare_themes_for_js( $themes = null ) { 652 652 ); 653 653 } 654 654 655 $is_autoupdated_enabled = null; 656 if ( wp_is_themes_auto_update_enabled() ) { 657 $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); 658 if ( in_array( $slug, $wp_auto_update_themes, true ) ) { 659 $is_autoupdated_enabled = true; 660 } 661 } 662 655 663 $prepared_themes[ $slug ] = array( 656 664 'id' => $slug, 657 665 'name' => $theme->display( 'Name' ), … … function wp_prepare_themes_for_js( $themes = null ) { 666 674 'hasUpdate' => isset( $updates[ $slug ] ), 667 675 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ), 668 676 'update' => get_theme_update_available( $theme ), 677 'autoupdated' => $is_autoupdated_enabled, 669 678 'actions' => array( 670 679 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, 671 680 'customize' => $customize_action, 672 681 'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, 682 'autoupdate' => current_user_can( 'update_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=autoupdate&stylesheet=' . $encoded_slug ), 'autoupdate-theme_' . $slug ) : null, 673 683 ), 674 684 ); 675 685 } -
src/wp-admin/themes.php
diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index 244f573ce6..6c9c45ea14 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 if ( ! wp_is_themes_auto_update_enabled() ) { 70 wp_die( 71 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . 72 '<p>' . __( 'Sorry, you are not allowed to enable automatic update for themes.' ) . '</p>', 73 403 74 ); 75 } 76 77 $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); 78 if ( ! in_array( $slug, $wp_auto_update_themes, true ) ) { 79 $autoupdate_action = 'enable'; 80 $wp_auto_update_themes[] = $slug; 81 } else { 82 $autoupdate_action = 'disable'; 83 $wp_auto_update_themes = array_diff( $wp_auto_update_themes, array( $slug ) ); 84 } 85 86 update_site_option( 'wp_auto_update_themes', $wp_auto_update_themes ); 87 88 wp_redirect( admin_url( 'themes.php?autoupdated=' . $autoupdate_action ) ); 89 exit; 56 90 } elseif ( 'delete' == $_GET['action'] ) { 57 91 check_admin_referer( 'delete-theme_' . $_GET['stylesheet'] ); 58 92 $theme = wp_get_theme( $_GET['stylesheet'] ); … … if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) { 228 262 ?> 229 263 <div id="message6" class="error"><p><?php _e( 'Theme could not be resumed because it triggered a <strong>fatal error</strong>.' ); ?></p></div> 230 264 <?php 265 } elseif ( isset( $_GET['autoupdated'] ) ) { 266 $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); 267 $autoupdate_notice = __( 'The selected theme won’t update automatically anymore.' ); 268 if ( 'enable' === $_GET['autoupdated'] ) { 269 $autoupdate_notice = __( 'The selected theme will now update automatically.' ); 270 } 271 ?> 272 <div id="message7" class="updated notice is-dismissible"><p><?php echo $autoupdate_notice; ?></p></div> 273 <?php 231 274 } 232 275 233 276 $ct = wp_get_theme(); … … foreach ( $themes as $theme ) : 359 402 $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); 360 403 ?> 361 404 <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> 405 <?php 406 if ( wp_is_themes_auto_update_enabled() ) { 407 /* translators: %s: Theme name. */ 408 $aria_label_enable = sprintf( _x( 'Enable automatic update for %s', 'theme' ), '{{ data.name }}' ); 409 $aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' ); 410 ?> 411 <# if ( data.autoupdated ) { #> 412 <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_disable; ?>"><?php _e( 'Disable auto update' ); ?></a> 413 <# } else { #> 414 <a class="button autoupdate" href="{{{ data.actions.autoupdate }}}" aria-label="<?php echo $aria_label_enable; ?>"><?php _e( 'Enable auto update' ); ?></a> 415 <# } #> 416 <?php } ?> 362 417 <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?> 363 418 <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a> 364 419 <?php } ?> … … if ( ! is_multisite() && current_user_can( 'edit_themes' ) && $broken_themes ) { 562 617 printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); 563 618 ?> 564 619 </p> 565 620 <?php if ( wp_is_themes_auto_update_enabled() ) : ?> 621 <p class="theme-autoupdate"> 622 <?php 623 /* translators: %s: Theme name. */ 624 $aria_label_enable = sprintf( _x( 'Enable automatic update for %s', 'theme' ), '{{ data.name }}' ); 625 $aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' ); 626 ?> 627 <# if ( data.autoupdated ) { #> 628 <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> 629 <# } else { #> 630 <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> 631 <# } #> 632 </p> 633 <?php endif; ?> 566 634 <# if ( data.hasUpdate ) { #> 567 635 <div class="notice notice-warning notice-alt notice-large"> 568 636 <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3> 569 637 {{{ data.update }}} 638 <# if ( data.autoupdated ) { #> 639 <?php 640 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 641 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 642 $autoupdate = sprintf( 643 /* translators: Time until the next update. */ 644 __( 'Automatic update scheduled in %s.' ), 645 $time_to_next_update 646 ); 647 ?> 648 <p class="theme-autoupdate-enabled"><?php echo $autoupdate; ?></p> 649 <# } #> 570 650 </div> 571 651 <# } #> 572 652 <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..870534179c 100644
a b function list_theme_updates() { 478 478 479 479 <tbody class="plugins"> 480 480 <?php 481 if ( wp_is_themes_auto_update_enabled() ) { 482 $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); 483 } 484 481 485 foreach ( $themes as $stylesheet => $theme ) { 482 486 $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) ); 487 488 $autoupdate = ''; 489 if ( wp_is_themes_auto_update_enabled() ) { 490 if ( in_array( $stylesheet, $wp_auto_update_themes, true ) ) { 491 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 492 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 493 $autoupdate = ' <p class="theme-autoupdate-enabled">'; 494 $autoupdate .= sprintf( 495 /* translators: Time until the next update. */ 496 __( 'Automatic update scheduled in %s.' ), 497 $time_to_next_update 498 ); 499 $autoupdate .= '</p> '; 500 } 501 } 483 502 ?> 484 503 <tr> 485 504 <td class="check-column"> … … function list_theme_updates() { 501 520 $theme->display( 'Version' ), 502 521 $theme->update['new_version'] 503 522 ); 523 echo $autoupdate; 504 524 ?> 505 525 </p></td> 506 526 </tr> -
src/wp-includes/update.php
diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php index dfb27b2aad..2832834d87 100644
a b if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) { 813 813 return; 814 814 } 815 815 816 /** 817 * Autoupdate selected themes. 818 * 819 * @since 5.4.0 820 */ 821 function wp_auto_update_theme( $update, $item ) { 822 $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); 823 if ( in_array( $item->theme, $wp_auto_update_themes, true ) ) { 824 return true; 825 } else { 826 return $update; 827 } 828 } 829 830 /** 831 * Checks whether themes manual autoupdate is enabled. 832 * 833 * @since 5.4.0 834 */ 835 function wp_is_themes_auto_update_enabled() { 836 $enabled = ! defined( 'WP_DISABLE_THEMES_AUTO_UPDATE' ) || ! WP_DISABLE_THEMES_AUTO_UPDATE; 837 838 /** 839 * Filters whether themes manual autoupdate is enabled. 840 * 841 * @since 5.4.0 842 * 843 * @param bool $enabled True if themes auto udpate is enabled, false otherwise. 844 */ 845 return apply_filters( 'wp_themes_auto_update_enabled', $enabled ); 846 } 847 816 848 add_action( 'admin_init', '_maybe_update_core' ); 817 849 add_action( 'wp_version_check', 'wp_version_check' ); 818 850 … … add_action( 'wp_update_themes', 'wp_update_themes' ); 831 863 add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 ); 832 864 833 865 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); 866 add_filter( 'auto_update_theme', 'wp_auto_update_theme', 10, 2 ); 834 867 835 868 add_action( 'init', 'wp_schedule_update_checks' );