Ticket #48850: 48850.6.diff
File 48850.6.diff, 15.1 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..e19f4bce95 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 ( $screen->in_admin( 'network' ) ) { 187 $wp_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 188 } else { 189 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 190 } 183 191 184 192 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 185 193 // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. … … class WP_Plugins_List_Table extends WP_List_Table { 233 241 // Populate the inactive list with plugins that aren't activated 234 242 $plugins['inactive'][ $plugin_file ] = $plugin_data; 235 243 } 244 245 if ( in_array( $plugin_data['plugin'], $wp_autoupdated_plugins, true ) ) { 246 $plugins['update-on'][ $plugin_file ] = $plugin_data; 247 } else { 248 $plugins['update-off'][ $plugin_file ] = $plugin_data; 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 ( $screen->in_admin( 'network' ) ) { 996 $wp_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 997 } else { 998 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 999 } 1000 if ( in_array( $plugin_file, $wp_autoupdated_plugins, true ) ) { 1001 $aria_label = esc_attr( 1002 sprintf( 1003 /* translators: Plugin name. */ 1004 _x( 'Disable automatic updates for %s', 'plugin' ), 1005 $plugin_name 1006 ) 1007 ); 1008 echo '<p class="plugin-autoupdate-enabled">'; 1009 echo '<span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic update enabled' ); 1010 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1011 echo sprintf( 1012 ' | <a href="%s" class="edit" aria-label="%s">%s</a>', 1013 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1014 $aria_label, 1015 __( 'Disable' ) 1016 ); 1017 } 1018 echo '</p>'; 1019 } else { 1020 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1021 $aria_label = esc_attr( 1022 sprintf( 1023 /* translators: Plugin name. */ 1024 _x( 'Enable automatic updates for %s', 'plugin' ), 1025 $plugin_name 1026 ) 1027 ); 1028 echo '<p class="plugin-autoupdate-enabled">'; 1029 echo sprintf( 1030 '<a href="%s" class="edit" aria-label="%s"><span class="dashicons dashicons-update" aria-hidden="true"></span> %s</a>', 1031 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1032 $aria_label, 1033 __( 'Enable automatic updates' ) 1034 ); 1035 echo '</p>'; 1036 } 1037 } 1038 963 1039 echo '</td>'; 964 1040 break; 965 1041 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..a7689aba83 100644
a b function wp_plugin_update_row( $file, $plugin_data ) { 488 488 ); 489 489 } else { 490 490 if ( $compatible_php ) { 491 if ( is_network_admin() ) { 492 $wp_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 493 } else { 494 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 495 } 496 $autoupdate = ''; 497 if ( in_array( $plugin_data['plugin'], $wp_autoupdated_plugins, true ) ) { 498 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 499 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 500 $autoupdate = ' <span class="plugin-autoupdate-enabled">'; 501 $autoupdate .= sprintf( 502 /* translators: Time until the next update. */ 503 __( 'Automatic update scheduled in %s.' ), 504 $time_to_next_update 505 ); 506 $autoupdate .= '</span> '; 507 } 491 508 printf( 492 /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes . */493 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>. ' ),509 /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes, 7: Automatic update informations. */ 510 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>. %7$s' ), 494 511 $plugin_name, 495 512 esc_url( $details_url ), 496 513 sprintf( … … function wp_plugin_update_row( $file, $plugin_data ) { 504 521 'class="update-link" aria-label="%s"', 505 522 /* translators: %s: Plugin name. */ 506 523 esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) ) 507 ) 524 ), 525 $autoupdate 508 526 ); 509 527 } else { 510 528 printf( -
src/wp-admin/plugins.php
diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 459a2f82f6..5b2415a0e8 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 if ( is_network_admin() ) { 175 $autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 176 } else { 177 $autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 178 } 179 180 if ( in_array( $plugin, $autoupdated_plugins, true ) ) { 181 $autoupdated_plugins = array_diff( $autoupdated_plugins, array( $plugin ) ); 182 $action_type = 'disable-autoupdate=true'; 183 } else { 184 $autoupdated_plugins[] = $plugin; 185 $action_type = 'enable-autoupdate=true'; 186 } 187 188 if ( is_network_admin() ) { 189 update_site_option( 'wp_autoupdated_plugins', $autoupdated_plugins ); 190 } else { 191 update_option( 'wp_autoupdated_plugins', $autoupdated_plugins ); 192 } 193 194 wp_redirect( self_admin_url( "plugins.php?$action_type&plugin_status=$status&paged=$page&s=$s" ) ); 195 196 exit; 197 198 case 'enable-autoupdate-selected': 199 if ( ! current_user_can( 'update_plugins' ) ) { 200 wp_die( __( 'Sorry, you are not allowed to enable plugin 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 if ( is_network_admin() ) { 213 $previous_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 214 } else { 215 $previous_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 216 } 217 218 $new_autoupdated_plugins = array_merge( $previous_autoupdated_plugins, $plugins ); 219 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 220 221 if ( is_network_admin() ) { 222 update_site_option( 'wp_autoupdated_plugins', $new_autoupdated_plugins ); 223 } else { 224 update_option( 'wp_autoupdated_plugins', $new_autoupdated_plugins ); 225 } 226 227 wp_redirect( self_admin_url( "plugins.php?enable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 228 exit; 229 230 case 'disable-autoupdate-selected': 231 if ( ! current_user_can( 'update_plugins' ) ) { 232 wp_die( __( 'Sorry, you are not allowed to disable plugin automatic updates.' ) ); 233 } 234 235 check_admin_referer( 'bulk-plugins' ); 236 237 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 238 239 if ( empty( $plugins ) ) { 240 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 241 exit; 242 } 243 244 if ( is_network_admin() ) { 245 $previous_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 246 } else { 247 $previous_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 248 } 249 250 $new_autoupdated_plugins = array_diff( $previous_autoupdated_plugins, $plugins ); 251 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 252 253 if ( is_network_admin() ) { 254 update_site_option( 'wp_autoupdated_plugins', $new_autoupdated_plugins ); 255 } else { 256 update_option( 'wp_autoupdated_plugins', $new_autoupdated_plugins ); 257 } 258 259 wp_redirect( self_admin_url( "plugins.php?disable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 260 exit; 261 157 262 case 'error_scrape': 158 263 if ( ! current_user_can( 'activate_plugin', $plugin ) ) { 159 264 wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) ); … … elseif ( isset( $_GET['deleted'] ) ) : 578 683 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div> 579 684 <?php elseif ( 'update-selected' == $action ) : ?> 580 685 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div> 686 <?php elseif ( isset( $_GET['enable-autoupdate'] ) ) : ?> 687 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins will now update automatically.' ); ?></p></div> 688 <?php elseif ( isset( $_GET['disable-autoupdate'] ) ) : ?> 689 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins won’t automatically update anymore.' ); ?></p></div> 581 690 <?php elseif ( isset( $_GET['resume'] ) ) : ?> 582 691 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div> 583 692 <?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..47b0bb6eeb 100644
a b function list_plugin_updates() { 328 328 329 329 <tbody class="plugins"> 330 330 <?php 331 // Get autoupdated plugins 332 if ( is_network_admin() ) { 333 $wp_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 334 } else { 335 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 336 } 337 331 338 foreach ( (array) $plugins as $plugin_file => $plugin_data ) { 332 339 $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true ); 333 340 … … function list_plugin_updates() { 395 402 ); 396 403 397 404 $checkbox_id = 'checkbox_' . md5( $plugin_data->Name ); 405 406 $autoupdate = ''; 407 if ( in_array( $plugin_data->update->plugin, $wp_autoupdated_plugins, true ) ) { 408 $next_update_time = wp_next_scheduled( 'wp_version_check' ); 409 $time_to_next_update = human_time_diff( intval( $next_update_time ) ); 410 $autoupdate = ' <span class="plugin-autoupdate-enabled">'; 411 $autoupdate .= sprintf( 412 /* translators: Time until the next update. */ 413 __( 'Automatic update scheduled in %s.' ), 414 $time_to_next_update 415 ); 416 $autoupdate .= '</span> '; 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..7b96f3aad1 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 if ( is_multisite() ) { 818 $wp_autoupdated_plugins = get_site_option( 'wp_autoupdated_plugins', array() ); 819 } else { 820 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 821 } 822 if ( in_array( $item->plugin, $wp_autoupdated_plugins, true ) ) { 823 return true; 824 } else { 825 return $update; 826 } 827 } 828 816 829 add_action( 'admin_init', '_maybe_update_core' ); 817 830 add_action( 'wp_version_check', 'wp_version_check' ); 818 831 … … add_action( 'wp_update_themes', 'wp_update_themes' ); 831 844 add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 ); 832 845 833 846 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); 847 add_filter( 'auto_update_plugin', 'wp_auto_update_plugin', 10, 2 ); 834 848 835 849 add_action( 'init', 'wp_schedule_update_checks' );