Ticket #48850: 48850.11.diff
File 48850.11.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 3ec88eb7c2..097ac124ac 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 ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 242 if ( wp_is_plugins_auto_update_enabled() ) { 243 if ( in_array( $plugin_data['plugin'], $wp_auto_update_plugins, true ) ) { 244 $plugins['autoupdate_enabled'][ $plugin_file ] = $plugin_data; 245 } else { 246 $plugins['autoupdate_disabled'][ $plugin_file ] = $plugin_data; 247 } 248 } 249 } 234 250 } 235 251 236 252 if ( strlen( $s ) ) { … … class WP_Plugins_List_Table extends WP_List_Table { 491 507 $count 492 508 ); 493 509 break; 510 case 'autoupdate_enabled': 511 /* translators: %s: Number of plugins. */ 512 $text = _n( 513 'Automatic Update Enabled <span class="count">(%s)</span>', 514 'Automatic Update Enabled <span class="count">(%s)</span>', 515 $count 516 ); 517 break; 518 case 'autoupdate_disabled': 519 /* translators: %s: Number of plugins. */ 520 $text = _n( 521 'Automatic Update Disabled <span class="count">(%s)</span>', 522 'Automatic Update Disabled <span class="count">(%s)</span>', 523 $count 524 ); 525 break; 494 526 } 495 527 496 528 if ( 'search' !== $type ) { … … class WP_Plugins_List_Table extends WP_List_Table { 525 557 526 558 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 527 559 if ( current_user_can( 'update_plugins' ) ) { 528 $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' ); 529 563 } 530 564 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 531 565 $actions['delete-selected'] = __( 'Delete' ); … … class WP_Plugins_List_Table extends WP_List_Table { 958 992 } 959 993 } 960 994 995 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 996 if ( wp_is_plugins_auto_update_enabled() ) { 997 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 998 if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { 999 $aria_label = esc_attr( 1000 sprintf( 1001 /* translators: Plugin name. */ 1002 _x( 'Disable automatic updates for %s', 'plugin' ), 1003 $plugin_name 1004 ) 1005 ); 1006 echo '<p class="plugin-autoupdate-enabled">'; 1007 echo '<span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic update enabled' ); 1008 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1009 echo sprintf( 1010 ' | <a href="%s" class="edit" aria-label="%s">%s</a>', 1011 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1012 $aria_label, 1013 __( 'Disable' ) 1014 ); 1015 } 1016 echo '</p>'; 1017 } else { 1018 if ( current_user_can( 'update_plugins', $plugin_file ) ) { 1019 $aria_label = esc_attr( 1020 sprintf( 1021 /* translators: Plugin name. */ 1022 _x( 'Enable automatic updates for %s', 'plugin' ), 1023 $plugin_name 1024 ) 1025 ); 1026 echo '<p class="plugin-autoupdate-enabled">'; 1027 echo sprintf( 1028 '<a href="%s" class="edit" aria-label="%s"><span class="dashicons dashicons-update" aria-hidden="true"></span> %s</a>', 1029 wp_nonce_url( 'plugins.php?action=autoupdate&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page, 'autoupdate-plugin_' . $plugin_file ), 1030 $aria_label, 1031 __( 'Enable automatic updates' ) 1032 ); 1033 echo '</p>'; 1034 } 1035 } 1036 } 1037 } 1038 961 1039 echo '</td>'; 962 1040 break; 963 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 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..925a99e6e4 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' ) || ! wp_is_plugins_auto_update_enabled() ) { 161 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 162 } 163 164 if ( is_multisite() && ! is_network_admin() ) { 165 wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.' ) ); 166 } 167 168 if ( empty( $plugin ) ) { 169 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 170 exit; 171 } 172 173 check_admin_referer( 'autoupdate-plugin_' . $plugin ); 174 175 $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 176 177 if ( in_array( $plugin, $wp_auto_update_plugins, true ) ) { 178 $wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin ) ); 179 $action_type = 'disable-autoupdate=true'; 180 } else { 181 $wp_auto_update_plugins[] = $plugin; 182 $action_type = 'enable-autoupdate=true'; 183 } 184 185 update_site_option( 'wp_auto_update_plugins', $wp_auto_update_plugins ); 186 187 wp_redirect( self_admin_url( "plugins.php?$action_type&plugin_status=$status&paged=$page&s=$s" ) ); 188 189 exit; 190 191 case 'enable-autoupdate-selected': 192 if ( ! current_user_can( 'update_plugins' ) || ! wp_is_plugins_auto_update_enabled() ) { 193 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 194 } 195 196 if ( is_multisite() && ! is_network_admin() ) { 197 wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.' ) ); 198 } 199 200 check_admin_referer( 'bulk-plugins' ); 201 202 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 203 204 if ( empty( $plugins ) ) { 205 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 206 exit; 207 } 208 209 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 210 211 $new_autoupdated_plugins = array_merge( $previous_autoupdated_plugins, $plugins ); 212 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 213 214 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 215 216 wp_redirect( self_admin_url( "plugins.php?enable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 217 exit; 218 219 case 'disable-autoupdate-selected': 220 if ( ! current_user_can( 'update_plugins' ) || ! wp_is_plugins_auto_update_enabled() ) { 221 wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.' ) ); 222 } 223 224 if ( is_multisite() && ! is_network_admin() ) { 225 wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.' ) ); 226 } 227 228 check_admin_referer( 'bulk-plugins' ); 229 230 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 231 232 if ( empty( $plugins ) ) { 233 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 234 exit; 235 } 236 237 $previous_autoupdated_plugins = get_site_option( 'wp_auto_update_plugins', array() ); 238 239 $new_autoupdated_plugins = array_diff( $previous_autoupdated_plugins, $plugins ); 240 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 241 242 update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); 243 244 wp_redirect( self_admin_url( "plugins.php?disable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 245 exit; 246 159 247 case 'error_scrape': 160 248 if ( ! current_user_can( 'activate_plugin', $plugin ) ) { 161 249 wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) ); … … elseif ( isset( $_GET['deleted'] ) ) : 581 669 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div> 582 670 <?php elseif ( 'update-selected' == $action ) : ?> 583 671 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div> 672 <?php elseif ( isset( $_GET['enable-autoupdate'] ) ) : ?> 673 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins will now update automatically.' ); ?></p></div> 674 <?php elseif ( isset( $_GET['disable-autoupdate'] ) ) : ?> 675 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins won’t automatically update anymore.' ); ?></p></div> 584 676 <?php elseif ( isset( $_GET['resume'] ) ) : ?> 585 677 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div> 586 678 <?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' );