Ticket #48850: 48850.2.diff
File 48850.2.diff, 7.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..b22cd51df8 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 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 183 186 184 187 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 185 188 // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. … … class WP_Plugins_List_Table extends WP_List_Table { 233 236 // Populate the inactive list with plugins that aren't activated 234 237 $plugins['inactive'][ $plugin_file ] = $plugin_data; 235 238 } 239 240 if ( in_array( $plugin_data['plugin'], $wp_autoupdated_plugins, true ) ) { 241 $plugins['update-on'][ $plugin_file ] = $plugin_data; 242 } else { 243 $plugins['update-off'][ $plugin_file ] = $plugin_data; 244 } 236 245 } 237 246 238 247 if ( strlen( $s ) ) { … … class WP_Plugins_List_Table extends WP_List_Table { 493 502 $count 494 503 ); 495 504 break; 505 case 'update-on': 506 /* translators: %s: Number of plugins. */ 507 $text = _n( 508 'Auto Update On <span class="count">(%s)</span>', 509 'Auto Update On <span class="count">(%s)</span>', 510 $count 511 ); 512 break; 513 case 'update-off': 514 /* translators: %s: Number of plugins. */ 515 $text = _n( 516 'Auto Update Off <span class="count">(%s)</span>', 517 'Auto Update Off <span class="count">(%s)</span>', 518 $count 519 ); 520 break; 496 521 } 497 522 498 523 if ( 'search' !== $type ) { … … class WP_Plugins_List_Table extends WP_List_Table { 527 552 528 553 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 529 554 if ( current_user_can( 'update_plugins' ) ) { 530 $actions['update-selected'] = __( 'Update' ); 555 $actions['update-selected'] = __( 'Update' ); 556 $actions['enable-autoupdate-selected'] = __( 'Enable auto update' ); 557 $actions['disable-autoupdate-selected'] = __( 'Disable auto update' ); 531 558 } 532 559 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 533 560 $actions['delete-selected'] = __( 'Delete' ); … … class WP_Plugins_List_Table extends WP_List_Table { 960 987 } 961 988 } 962 989 990 $wp_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 991 if ( in_array( $plugin_file, $wp_autoupdated_plugins, true ) ) { 992 echo '<p class="plugin-autoupdate-enabled"><span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic update activated' ) . '</p>'; 993 } 994 963 995 echo '</td>'; 964 996 break; 965 997 default: -
src/wp-admin/plugins.php
diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index acebd8e452..91e138f6b2 100644
a b if ( $action ) { 154 154 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); 155 155 exit; 156 156 157 case 'enable-autoupdate-selected': 158 if ( ! current_user_can( 'update_plugins' ) ) { 159 wp_die( __( 'Sorry, you are not allowed to enable plugin automatic updates.' ) ); 160 } 161 162 check_admin_referer( 'bulk-plugins' ); 163 164 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 165 166 if ( empty( $plugins ) ) { 167 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 168 exit; 169 } 170 171 $previous_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 172 $new_autoupdated_plugins = array_merge( $previous_autoupdated_plugins, $plugins ); 173 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 174 update_option( 'wp_autoupdated_plugins', $new_autoupdated_plugins ); 175 176 wp_redirect( self_admin_url( "plugins.php?enable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 177 exit; 178 179 case 'disable-autoupdate-selected': 180 if ( ! current_user_can( 'update_plugins' ) ) { 181 wp_die( __( 'Sorry, you are not allowed to disable plugin automatic updates.' ) ); 182 } 183 184 check_admin_referer( 'bulk-plugins' ); 185 186 $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); 187 188 if ( empty( $plugins ) ) { 189 wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); 190 exit; 191 } 192 193 $previous_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 194 $new_autoupdated_plugins = array_diff( $previous_autoupdated_plugins, $plugins ); 195 $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); 196 update_option( 'wp_autoupdated_plugins', $new_autoupdated_plugins ); 197 198 wp_redirect( self_admin_url( "plugins.php?disable-autoupdate=true&plugin_status=$status&paged=$page&s=$s" ) ); 199 exit; 200 157 201 case 'error_scrape': 158 202 if ( ! current_user_can( 'activate_plugin', $plugin ) ) { 159 203 wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) ); … … elseif ( isset( $_GET['deleted'] ) ) : 578 622 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div> 579 623 <?php elseif ( 'update-selected' == $action ) : ?> 580 624 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div> 625 <?php elseif ( isset( $_GET['enable-autoupdate'] ) ) : ?> 626 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins will now update automatically.' ); ?></p></div> 627 <?php elseif ( isset( $_GET['disable-autoupdate'] ) ) : ?> 628 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins won’t automatically update anymore.' ); ?></p></div> 581 629 <?php elseif ( isset( $_GET['resume'] ) ) : ?> 582 630 <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div> 583 631 <?php endif; ?> -
src/wp-includes/update.php
diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php index dfb27b2aad..31222f3207 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_autoupdated_plugins = get_option( 'wp_autoupdated_plugins', array() ); 818 if ( in_array( $item->plugin, $wp_autoupdated_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' );