Ticket #48850: 48850.8.diff
File 48850.8.diff, 12.8 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..df8d172011 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 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 183 187 184 188 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 185 189 // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. … … class WP_Plugins_List_Table extends WP_List_Table { 233 237 // Populate the inactive list with plugins that aren't activated 234 238 $plugins['inactive'][ $plugin_file ] = $plugin_data; 235 239 } 240 241 if ( in_array( $plugin_data['plugin'], $wp_auto_update_plugins, true ) ) { 242 $plugins['update-on'][ $plugin_file ] = $plugin_data; 243 } else { 244 $plugins['update-off'][ $plugin_file ] = $plugin_data; 245 } 236 246 } 237 247 238 248 if ( strlen( $s ) ) { … … class WP_Plugins_List_Table extends WP_List_Table { 493 503 $count 494 504 ); 495 505 break; 506 case 'update-on': 507 /* translators: %s: Number of plugins. */ 508 $text = _n( 509 'Auto Update On <span class="count">(%s)</span>', 510 'Auto Update On <span class="count">(%s)</span>', 511 $count 512 ); 513 break; 514 case 'update-off': 515 /* translators: %s: Number of plugins. */ 516 $text = _n( 517 'Auto Update Off <span class="count">(%s)</span>', 518 'Auto Update Off <span class="count">(%s)</span>', 519 $count 520 ); 521 break; 496 522 } 497 523 498 524 if ( 'search' !== $type ) { … … class WP_Plugins_List_Table extends WP_List_Table { 527 553 528 554 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 529 555 if ( current_user_can( 'update_plugins' ) ) { 530 $actions['update-selected'] = __( 'Update' ); 556 $actions['update-selected'] = __( 'Update' ); 557 $actions['enable-autoupdate-selected'] = __( 'Enable auto update' ); 558 $actions['disable-autoupdate-selected'] = __( 'Disable auto update' ); 531 559 } 532 560 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 533 561 $actions['delete-selected'] = __( 'Delete' ); … … class WP_Plugins_List_Table extends WP_List_Table { 960 988 } 961 989 } 962 990 991 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 992 if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { 993 $aria_label = esc_attr( 994 sprintf( 995 /* translators: Plugin name. */ 996 _x( 'Disable automatic updates for %s', 'plugin' ), 997 $plugin_name 998 ) 999 ); 1000 echo '<p class="plugin-autoupdate-enabled">'; 1001 echo '<span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic update enabled' ); 1002 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1003 echo sprintf( 1004 ' | <a href="%s" class="edit" aria-label="%s">%s</a>', 1005 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1006 $aria_label, 1007 __( 'Disable' ) 1008 ); 1009 } 1010 echo '</p>'; 1011 } else { 1012 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1013 $aria_label = esc_attr( 1014 sprintf( 1015 /* translators: Plugin name. */ 1016 _x( 'Enable automatic updates for %s', 'plugin' ), 1017 $plugin_name 1018 ) 1019 ); 1020 echo '<p class="plugin-autoupdate-enabled">'; 1021 echo sprintf( 1022 '<a href="%s" class="edit" aria-label="%s"><span class="dashicons dashicons-update" aria-hidden="true"></span> %s</a>', 1023 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1024 $aria_label, 1025 __( 'Enable automatic updates' ) 1026 ); 1027 echo '</p>'; 1028 } 1029 } 1030 963 1031 echo '</td>'; 964 1032 break; 965 1033 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..ff157ed034 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 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 510 $autoupdate = ''; 511 if ( in_array( $plugin_data['plugin'], $wp_auto_update_plugins, true ) ) { 512 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 513 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 514 echo ' <span class="plugin-autoupdate-enabled">'; 515 printf( 516 /* translators: Time until the next update. */ 517 __( 'Automatic update scheduled in %s.' ), 518 $time_to_next_update 519 ); 520 echo '</span> '; 521 } 509 522 } else { 510 523 printf( 511 524 /* 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..a7fb2a2e59 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 update plugins.' ) ); 160 } 161 162 if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) { 163 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 164 exit; 165 } 166 167 if ( empty( $plugin ) ) { 168 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 169 exit; 170 } 171 172 check_admin_referer( 'autoupdate-plugin_' . $plugin ); 173 174 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 175 176 if ( in_array( $plugin, $wp_auto_update_plugins, true ) ) { 177 $wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin ) ); 178 $action_type = 'disable-autoupdate=true'; 179 } else { 180 $wp_auto_update_plugins[] = $plugin; 181 $action_type = 'enable-autoupdate=true'; 182 } 183 184 update_site_option( 'wp_auto_update_plugins', $wp_auto_update_plugins ); 185 186 wp_redirect( self_admin_url( "plugins.php?$action_type&plugin_status=$status&paged=$page&s=$s" ) ); 187 188 exit; 189 190 case 'enable-autoupdate-selected': 191 if ( ! current_user_can( 'update_plugins' ) ) { 192 wp_die( __( 'Sorry, you are not allowed to enable plugin automatic updates.' ) ); 193 } 194 195 check_admin_referer( 'bulk-plugins' ); 196 197 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 198 199 if ( empty( $plugins ) ) { 200 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 201 exit; 202 } 203 204 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 205 206 $new_autoupdated_plugins = array_merge( $previous_autoupdated_plugins, $plugins ); 207 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 208 209 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 210 211 wp_redirect( self_admin_url( "plugins.php?enable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 212 exit; 213 214 case 'disable-autoupdate-selected': 215 if ( ! current_user_can( 'update_plugins' ) ) { 216 wp_die( __( 'Sorry, you are not allowed to disable plugin automatic updates.' ) ); 217 } 218 219 check_admin_referer( 'bulk-plugins' ); 220 221 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 222 223 if ( empty( $plugins ) ) { 224 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 225 exit; 226 } 227 228 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 229 230 $new_autoupdated_plugins = array_diff( $previous_autoupdated_plugins, $plugins ); 231 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 232 233 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 234 235 wp_redirect( self_admin_url( "plugins.php?disable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 236 exit; 237 157 238 case 'error_scrape': 158 239 if ( ! current_user_can( 'activate_plugin', $plugin ) ) { 159 240 wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) ); … … elseif ( isset( $_GET['deleted'] ) ) : 578 659 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div> 579 660 <?php elseif ( 'update-selected' == $action ) : ?> 580 661 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div> 662 <?php elseif ( isset( $_GET['enable-autoupdate'] ) ) : ?> 663 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins will now update automatically.' ); ?></p></div> 664 <?php elseif ( isset( $_GET['disable-autoupdate'] ) ) : ?> 665 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins won’t automatically update anymore.' ); ?></p></div> 581 666 <?php elseif ( isset( $_GET['resume'] ) ) : ?> 582 667 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div> 583 668 <?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..0f673441b0 100644
a b function list_plugin_updates() { 328 328 329 329 <tbody class="plugins"> 330 330 <?php 331 // Get autoupdated plugins 332 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 333 331 334 foreach ( (array) $plugins as $plugin_file => $plugin_data ) { 332 335 $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true ); 333 336 … … function list_plugin_updates() { 395 398 ); 396 399 397 400 $checkbox_id = 'checkbox_' . md5( $plugin_data->Name ); 401 402 $autoupdate = ''; 403 if ( in_array( $plugin_data->update->plugin, $wp_auto_update_plugins, true ) ) { 404 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 405 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 406 $autoupdate = ' <span class="plugin-autoupdate-enabled">'; 407 $autoupdate .= sprintf( 408 /* translators: Time until the next update. */ 409 __( 'Automatic update scheduled in %s.' ), 410 $time_to_next_update 411 ); 412 $autoupdate .= '</span> '; 413 } 398 414 ?> 399 415 <tr> 400 416 <td class="check-column"> … … function list_plugin_updates() { 418 434 $plugin_data->Version, 419 435 $plugin_data->update->new_version 420 436 ); 421 echo ' ' . $details . $ compat . $upgrade_notice;437 echo ' ' . $details . $autoupdate . $compat . $upgrade_notice; 422 438 ?> 423 439 </p></td> 424 440 </tr> -
src/wp-includes/update.php
diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php index dfb27b2aad..e3f69e3050 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_plugin( $update, $item ) { 817 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 818 if ( in_array( $item->plugin, $wp_auto_update_plugins, 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_plugin', 'wp_auto_update_plugin', 10, 2 ); 834 844 835 845 add_action( 'init', 'wp_schedule_update_checks' );