Ticket #48850: 48850.10.diff
File 48850.10.diff, 15.0 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 3ec88eb7c2..7b9cac9fbe 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', 'autoupdate_enabled', 'autoupdate_disabled' ) ) ) { 44 44 $status = $_REQUEST['plugin_status']; 45 45 } 46 46 … … class WP_Plugins_List_Table extends WP_List_Table { 91 91 $all_plugins = apply_filters( 'all_plugins', get_plugins() ); 92 92 93 93 $plugins = array( 94 'all' => $all_plugins, 95 'search' => array(), 96 'active' => array(), 97 'inactive' => array(), 98 'recently_activated' => array(), 99 'upgrade' => array(), 100 'mustuse' => array(), 101 'dropins' => array(), 102 'paused' => array(), 94 'all' => $all_plugins, 95 'search' => array(), 96 'active' => array(), 97 'inactive' => array(), 98 'recently_activated' => array(), 99 'upgrade' => array(), 100 'mustuse' => array(), 101 'dropins' => array(), 102 'paused' => array(), 103 'autoupdate_enabled' => array(), 104 'autoupdate_disabled' => array(), 103 105 ); 104 106 105 107 $screen = $this->screen; … … class WP_Plugins_List_Table extends WP_List_Table { 177 179 update_option( 'recently_activated', $recently_activated ); 178 180 } 179 181 180 $plugin_info = get_site_transient( 'update_plugins' ); 182 $plugin_info = get_site_transient( 'update_plugins' ); 183 184 if ( wp_is_plugins_auto_update_enabled() ) { 185 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 186 } 181 187 182 188 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 183 189 // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. … … class WP_Plugins_List_Table extends WP_List_Table { 231 237 // Populate the inactive list with plugins that aren't activated. 232 238 $plugins['inactive'][ $plugin_file ] = $plugin_data; 233 239 } 240 241 if ( wp_is_plugins_auto_update_enabled() ) { 242 if ( in_array( $plugin_data['plugin'], $wp_auto_update_plugins, true ) ) { 243 $plugins['autoupdate_enabled'][ $plugin_file ] = $plugin_data; 244 } else { 245 $plugins['autoupdate_disabled'][ $plugin_file ] = $plugin_data; 246 } 247 } 234 248 } 235 249 236 250 if ( strlen( $s ) ) { … … class WP_Plugins_List_Table extends WP_List_Table { 491 505 $count 492 506 ); 493 507 break; 508 case 'autoupdate_enabled': 509 /* translators: %s: Number of plugins. */ 510 $text = _n( 511 'Automatic Update Enabled <span class="count">(%s)</span>', 512 'Automatic Update Enabled <span class="count">(%s)</span>', 513 $count 514 ); 515 break; 516 case 'autoupdate_disabled': 517 /* translators: %s: Number of plugins. */ 518 $text = _n( 519 'Automatic Update Disabled <span class="count">(%s)</span>', 520 'Automatic Update Disabled <span class="count">(%s)</span>', 521 $count 522 ); 523 break; 494 524 } 495 525 496 526 if ( 'search' !== $type ) { … … class WP_Plugins_List_Table extends WP_List_Table { 525 555 526 556 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 527 557 if ( current_user_can( 'update_plugins' ) ) { 528 $actions['update-selected'] = __( 'Update' ); 558 $actions['update-selected'] = __( 'Update' ); 559 $actions['enable-autoupdate-selected'] = __( 'Enable auto update' ); 560 $actions['disable-autoupdate-selected'] = __( 'Disable auto update' ); 529 561 } 530 562 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 531 563 $actions['delete-selected'] = __( 'Delete' ); … … class WP_Plugins_List_Table extends WP_List_Table { 958 990 } 959 991 } 960 992 993 if ( wp_is_plugins_auto_update_enabled() ) { 994 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 995 if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { 996 $aria_label = esc_attr( 997 sprintf( 998 /* translators: Plugin name. */ 999 _x( 'Disable automatic updates for %s', 'plugin' ), 1000 $plugin_name 1001 ) 1002 ); 1003 echo '<p class="plugin-autoupdate-enabled">'; 1004 echo '<span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic update enabled' ); 1005 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1006 echo sprintf( 1007 ' | <a href="%s" class="edit" aria-label="%s">%s</a>', 1008 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1009 $aria_label, 1010 __( 'Disable' ) 1011 ); 1012 } 1013 echo '</p>'; 1014 } else { 1015 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1016 $aria_label = esc_attr( 1017 sprintf( 1018 /* translators: Plugin name. */ 1019 _x( 'Enable automatic updates for %s', 'plugin' ), 1020 $plugin_name 1021 ) 1022 ); 1023 echo '<p class="plugin-autoupdate-enabled">'; 1024 echo sprintf( 1025 '<a href="%s" class="edit" aria-label="%s"><span class="dashicons dashicons-update" aria-hidden="true"></span> %s</a>', 1026 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1027 $aria_label, 1028 __( 'Enable automatic updates' ) 1029 ); 1030 echo '</p>'; 1031 } 1032 } 1033 } 1034 961 1035 echo '</td>'; 962 1036 break; 963 1037 default: -
src/wp-admin/includes/update.php
diff --git a/src/wp-admin/includes/update.php b/src/wp-admin/includes/update.php index 384e1f98fa..bdfda8f6f8 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 ed2deb7315..cdf15b969f 100644
a b if ( $action ) { 156 156 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); 157 157 exit; 158 158 159 case 'autoupdate': 160 if ( ! current_user_can( 'update_plugins' ) ) { 161 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 162 } 163 164 if ( ! wp_is_plugins_auto_update_enabled() ) { 165 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 166 } 167 168 if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) { 169 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 170 exit; 171 } 172 173 if ( empty( $plugin ) ) { 174 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 175 exit; 176 } 177 178 check_admin_referer( 'autoupdate-plugin_' . $plugin ); 179 180 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 181 182 if ( in_array( $plugin, $wp_auto_update_plugins, true ) ) { 183 $wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin ) ); 184 $action_type = 'disable-autoupdate=true'; 185 } else { 186 $wp_auto_update_plugins[] = $plugin; 187 $action_type = 'enable-autoupdate=true'; 188 } 189 190 update_site_option( 'wp_auto_update_plugins', $wp_auto_update_plugins ); 191 192 wp_redirect( self_admin_url( "plugins.php?$action_type&plugin_status=$status&paged=$page&s=$s" ) ); 193 194 exit; 195 196 case 'enable-autoupdate-selected': 197 if ( ! current_user_can( 'update_plugins' ) ) { 198 wp_die( __( 'Sorry, you are not allowed to enable plugin automatic updates.' ) ); 199 } 200 201 if ( ! wp_is_plugins_auto_update_enabled() ) { 202 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 203 } 204 205 check_admin_referer( 'bulk-plugins' ); 206 207 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 208 209 if ( empty( $plugins ) ) { 210 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 211 exit; 212 } 213 214 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 215 216 $new_autoupdated_plugins = array_merge( $previous_autoupdated_plugins, $plugins ); 217 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 218 219 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 220 221 wp_redirect( self_admin_url( "plugins.php?enable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 222 exit; 223 224 case 'disable-autoupdate-selected': 225 if ( ! current_user_can( 'update_plugins' ) ) { 226 wp_die( __( 'Sorry, you are not allowed to disable plugin automatic updates.' ) ); 227 } 228 229 if ( ! wp_is_plugins_auto_update_enabled() ) { 230 wp_die( __( 'Sorry, you are not allowed to disable plugins automatic updates.' ) ); 231 } 232 233 check_admin_referer( 'bulk-plugins' ); 234 235 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 236 237 if ( empty( $plugins ) ) { 238 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 239 exit; 240 } 241 242 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 243 244 $new_autoupdated_plugins = array_diff( $previous_autoupdated_plugins, $plugins ); 245 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 246 247 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 248 249 wp_redirect( self_admin_url( "plugins.php?disable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 250 exit; 251 159 252 case 'error_scrape': 160 253 if ( ! current_user_can( 'activate_plugin', $plugin ) ) { 161 254 wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) ); … … elseif ( isset( $_GET['deleted'] ) ) : 581 674 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div> 582 675 <?php elseif ( 'update-selected' == $action ) : ?> 583 676 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div> 677 <?php elseif ( isset( $_GET['enable-autoupdate'] ) ) : ?> 678 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins will now update automatically.' ); ?></p></div> 679 <?php elseif ( isset( $_GET['disable-autoupdate'] ) ) : ?> 680 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins won’t automatically update anymore.' ); ?></p></div> 584 681 <?php elseif ( isset( $_GET['resume'] ) ) : ?> 585 682 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div> 586 683 <?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 0f075e6442..0f988baeb9 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 125a6e3084..8ed0690f83 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 ) && wp_is_plugins_auto_update_enabled() ) { 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' );