Ticket #48850: 48850.9.diff
File 48850.9.diff, 14.2 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/class-wp-plugins-list-table.php
diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index a36ec05221..76817209aa 100644
a b class WP_Plugins_List_Table extends WP_List_Table { 40 40 ); 41 41 42 42 $status = 'all'; 43 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused' ) ) ) {43 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'update-on', 'update-off' ) ) ) { 44 44 $status = $_REQUEST['plugin_status']; 45 45 } 46 46 … … class WP_Plugins_List_Table extends WP_List_Table { 100 100 'mustuse' => array(), 101 101 'dropins' => array(), 102 102 'paused' => array(), 103 'update-on' => array(), 104 'update-off' => array(), 103 105 ); 104 106 105 107 $screen = $this->screen; … … class WP_Plugins_List_Table extends WP_List_Table { 179 181 update_option( 'recently_activated', $recently_activated ); 180 182 } 181 183 182 $plugin_info = get_site_transient( 'update_plugins' ); 184 $plugin_info = get_site_transient( 'update_plugins' ); 185 186 if ( wp_is_plugins_auto_update_enabled() ) { 187 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 188 } 183 189 184 190 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 185 191 // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. … … class WP_Plugins_List_Table extends WP_List_Table { 233 239 // Populate the inactive list with plugins that aren't activated 234 240 $plugins['inactive'][ $plugin_file ] = $plugin_data; 235 241 } 242 243 if ( wp_is_plugins_auto_update_enabled() ) { 244 if ( in_array( $plugin_data['plugin'], $wp_auto_update_plugins, true ) ) { 245 $plugins['update-on'][ $plugin_file ] = $plugin_data; 246 } else { 247 $plugins['update-off'][ $plugin_file ] = $plugin_data; 248 } 249 } 236 250 } 237 251 238 252 if ( strlen( $s ) ) { … … class WP_Plugins_List_Table extends WP_List_Table { 493 507 $count 494 508 ); 495 509 break; 510 case 'update-on': 511 /* translators: %s: Number of plugins. */ 512 $text = _n( 513 'Auto Update On <span class="count">(%s)</span>', 514 'Auto Update On <span class="count">(%s)</span>', 515 $count 516 ); 517 break; 518 case 'update-off': 519 /* translators: %s: Number of plugins. */ 520 $text = _n( 521 'Auto Update Off <span class="count">(%s)</span>', 522 'Auto Update Off <span class="count">(%s)</span>', 523 $count 524 ); 525 break; 496 526 } 497 527 498 528 if ( 'search' !== $type ) { … … class WP_Plugins_List_Table extends WP_List_Table { 527 557 528 558 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 529 559 if ( current_user_can( 'update_plugins' ) ) { 530 $actions['update-selected'] = __( 'Update' ); 560 $actions['update-selected'] = __( 'Update' ); 561 $actions['enable-autoupdate-selected'] = __( 'Enable auto update' ); 562 $actions['disable-autoupdate-selected'] = __( 'Disable auto update' ); 531 563 } 532 564 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 533 565 $actions['delete-selected'] = __( 'Delete' ); … … class WP_Plugins_List_Table extends WP_List_Table { 960 992 } 961 993 } 962 994 995 if ( wp_is_plugins_auto_update_enabled() ) { 996 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 997 if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { 998 $aria_label = esc_attr( 999 sprintf( 1000 /* translators: Plugin name. */ 1001 _x( 'Disable automatic updates for %s', 'plugin' ), 1002 $plugin_name 1003 ) 1004 ); 1005 echo '<p class="plugin-autoupdate-enabled">'; 1006 echo '<span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic update enabled' ); 1007 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1008 echo sprintf( 1009 ' | <a href="%s" class="edit" aria-label="%s">%s</a>', 1010 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1011 $aria_label, 1012 __( 'Disable' ) 1013 ); 1014 } 1015 echo '</p>'; 1016 } else { 1017 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1018 $aria_label = esc_attr( 1019 sprintf( 1020 /* translators: Plugin name. */ 1021 _x( 'Enable automatic updates for %s', 'plugin' ), 1022 $plugin_name 1023 ) 1024 ); 1025 echo '<p class="plugin-autoupdate-enabled">'; 1026 echo sprintf( 1027 '<a href="%s" class="edit" aria-label="%s"><span class="dashicons dashicons-update" aria-hidden="true"></span> %s</a>', 1028 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1029 $aria_label, 1030 __( 'Enable automatic updates' ) 1031 ); 1032 echo '</p>'; 1033 } 1034 } 1035 } 1036 963 1037 echo '</td>'; 964 1038 break; 965 1039 default: -
src/wp-admin/includes/update.php
diff --git a/src/wp-admin/includes/update.php b/src/wp-admin/includes/update.php index 0caa04a963..56d8ed304a 100644
a b function wp_plugin_update_row( $file, $plugin_data ) { 506 506 esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) ) 507 507 ) 508 508 ); 509 if ( wp_is_plugins_auto_update_enabled() ) { 510 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 511 $autoupdate = ''; 512 if ( in_array( $plugin_data['plugin'], $wp_auto_update_plugins, true ) ) { 513 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 514 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 515 echo ' <span class="plugin-autoupdate-enabled">'; 516 printf( 517 /* translators: Time until the next update. */ 518 __( 'Automatic update scheduled in %s.' ), 519 $time_to_next_update 520 ); 521 echo '</span> '; 522 } 523 } 509 524 } else { 510 525 printf( 511 526 /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number 5: URL to Update PHP page. */ -
src/wp-admin/plugins.php
diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 459a2f82f6..e80ffc2dcb 100644
a b if ( $action ) { 154 154 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); 155 155 exit; 156 156 157 case 'autoupdate': 158 if ( ! current_user_can( 'update_plugins' ) ) { 159 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 160 } 161 162 if ( ! wp_is_plugins_auto_update_enabled() ) { 163 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 164 } 165 166 if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) { 167 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 168 exit; 169 } 170 171 if ( empty( $plugin ) ) { 172 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 173 exit; 174 } 175 176 check_admin_referer( 'autoupdate-plugin_' . $plugin ); 177 178 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 179 180 if ( in_array( $plugin, $wp_auto_update_plugins, true ) ) { 181 $wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin ) ); 182 $action_type = 'disable-autoupdate=true'; 183 } else { 184 $wp_auto_update_plugins[] = $plugin; 185 $action_type = 'enable-autoupdate=true'; 186 } 187 188 update_site_option( 'wp_auto_update_plugins', $wp_auto_update_plugins ); 189 190 wp_redirect( self_admin_url( "plugins.php?$action_type&plugin_status=$status&paged=$page&s=$s" ) ); 191 192 exit; 193 194 case 'enable-autoupdate-selected': 195 if ( ! current_user_can( 'update_plugins' ) ) { 196 wp_die( __( 'Sorry, you are not allowed to enable plugin automatic updates.' ) ); 197 } 198 199 if ( ! wp_is_plugins_auto_update_enabled() ) { 200 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 201 } 202 203 check_admin_referer( 'bulk-plugins' ); 204 205 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 206 207 if ( empty( $plugins ) ) { 208 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 209 exit; 210 } 211 212 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 213 214 $new_autoupdated_plugins = array_merge( $previous_autoupdated_plugins, $plugins ); 215 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 216 217 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 218 219 wp_redirect( self_admin_url( "plugins.php?enable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 220 exit; 221 222 case 'disable-autoupdate-selected': 223 if ( ! current_user_can( 'update_plugins' ) ) { 224 wp_die( __( 'Sorry, you are not allowed to disable plugin automatic updates.' ) ); 225 } 226 227 if ( ! wp_is_plugins_auto_update_enabled() ) { 228 wp_die( __( 'Sorry, you are not allowed to disable plugins automatic updates.' ) ); 229 } 230 231 check_admin_referer( 'bulk-plugins' ); 232 233 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 234 235 if ( empty( $plugins ) ) { 236 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 237 exit; 238 } 239 240 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 241 242 $new_autoupdated_plugins = array_diff( $previous_autoupdated_plugins, $plugins ); 243 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 244 245 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 246 247 wp_redirect( self_admin_url( "plugins.php?disable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 248 exit; 249 157 250 case 'error_scrape': 158 251 if ( ! current_user_can( 'activate_plugin', $plugin ) ) { 159 252 wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) ); … … elseif ( isset( $_GET['deleted'] ) ) : 578 671 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div> 579 672 <?php elseif ( 'update-selected' == $action ) : ?> 580 673 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div> 674 <?php elseif ( isset( $_GET['enable-autoupdate'] ) ) : ?> 675 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins will now update automatically.' ); ?></p></div> 676 <?php elseif ( isset( $_GET['disable-autoupdate'] ) ) : ?> 677 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins won’t automatically update anymore.' ); ?></p></div> 581 678 <?php elseif ( isset( $_GET['resume'] ) ) : ?> 582 679 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div> 583 680 <?php endif; ?> -
src/wp-admin/update-core.php
diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php index 2093201149..545b138727 100644
a b function list_plugin_updates() { 328 328 329 329 <tbody class="plugins"> 330 330 <?php 331 // Get autoupdated plugins 332 if ( wp_is_plugins_auto_update_enabled() ) { 333 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 334 } 335 331 336 foreach ( (array) $plugins as $plugin_file => $plugin_data ) { 332 337 $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true ); 333 338 … … function list_plugin_updates() { 395 400 ); 396 401 397 402 $checkbox_id = 'checkbox_' . md5( $plugin_data->Name ); 403 404 if ( wp_is_plugins_auto_update_enabled() ) { 405 $autoupdate = ''; 406 if ( in_array( $plugin_data->update->plugin, $wp_auto_update_plugins, true ) ) { 407 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 408 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 409 $autoupdate = ' <span class="plugin-autoupdate-enabled">'; 410 $autoupdate .= sprintf( 411 /* translators: Time until the next update. */ 412 __( 'Automatic update scheduled in %s.' ), 413 $time_to_next_update 414 ); 415 $autoupdate .= '</span> '; 416 } 417 } 398 418 ?> 399 419 <tr> 400 420 <td class="check-column"> … … function list_plugin_updates() { 418 438 $plugin_data->Version, 419 439 $plugin_data->update->new_version 420 440 ); 421 echo ' ' . $details . $ compat . $upgrade_notice;441 echo ' ' . $details . $autoupdate . $compat . $upgrade_notice; 422 442 ?> 423 443 </p></td> 424 444 </tr> -
src/wp-includes/update.php
diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php index dfb27b2aad..90b7a60d76 100644
a b if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) { 813 813 return; 814 814 } 815 815 816 /** 817 * Autoupdate selected plugins. 818 * 819 * @since 5.4.0 820 */ 821 function wp_auto_update_plugin( $update, $item ) { 822 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 823 if ( in_array( $item->plugin, $wp_auto_update_plugins, true ) ) { 824 return true; 825 } else { 826 return $update; 827 } 828 } 829 830 /** 831 * Checks whether plugins manual autoupdate is enabled. 832 * 833 * @since 5.4.0 834 */ 835 function wp_is_plugins_auto_update_enabled() { 836 $enabled = ! defined( 'WP_DISABLE_PLUGINS_AUTO_UPDATE' ) || ! WP_DISABLE_PLUGINS_AUTO_UPDATE; 837 838 /** 839 * Filters whether plugins manual autoupdate is enabled. 840 * 841 * @since 5.4.0 842 * 843 * @param bool $enabled True if plugins auto udpate is enabled, false otherwise. 844 */ 845 return apply_filters( 'wp_plugins_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_plugin', 'wp_auto_update_plugin', 10, 2 ); 834 867 835 868 add_action( 'init', 'wp_schedule_update_checks' );