Ticket #20104: 20104.2.diff
File 20104.2.diff, 15.5 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/plugin.php
572 572 * @since 2.5.0 573 573 * 574 574 * @param string|array $plugins Single plugin or list of plugins to deactivate. 575 * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network. 576 * A value of null (the default) will deactivate plugins for both the site and the network. 575 577 * @param bool $silent Prevent calling deactivation hooks. Default is false. 576 578 */ 577 function deactivate_plugins( $plugins, $silent = false ) {579 function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { 578 580 if ( is_multisite() ) 579 581 $network_current = get_site_option( 'active_sitewide_plugins', array() ); 580 582 $current = get_option( 'active_plugins', array() ); … … 585 587 if ( ! is_plugin_active($plugin) ) 586 588 continue; 587 589 588 $network_ wide =is_plugin_active_for_network( $plugin );590 $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); 589 591 590 592 if ( ! $silent ) 591 do_action( 'deactivate_plugin', $plugin, $network_ wide);593 do_action( 'deactivate_plugin', $plugin, $network_deactivating ); 592 594 593 if ( $network_wide ) { 595 if ( false !== $network_wide ) { 596 if ( ! is_plugin_active_for_network( $plugin ) ) 597 continue; 594 598 $do_network = true; 595 599 unset( $network_current[ $plugin ] ); 596 } else { 600 } 601 602 if ( true !== $network_wide ) { 597 603 $key = array_search( $plugin, $current ); 598 604 if ( false !== $key ) { 599 605 $do_blog = true; … … 602 608 } 603 609 604 610 if ( ! $silent ) { 605 do_action( 'deactivate_' . $plugin, $network_ wide);606 do_action( 'deactivated_plugin', $plugin, $network_ wide);611 do_action( 'deactivate_' . $plugin, $network_deactivating ); 612 do_action( 'deactivated_plugin', $plugin, $network_deactivating ); 607 613 } 608 614 } 609 615 -
wp-admin/includes/class-wp-plugins-list-table.php
13 13 global $status, $page; 14 14 15 15 $status = 'all'; 16 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', ' network', 'mustuse', 'dropins', 'search' ) ) )16 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) 17 17 $status = $_REQUEST['plugin_status']; 18 18 19 19 if ( isset($_REQUEST['s']) ) … … 78 78 79 79 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 ); 80 80 81 $recently_activated = get_option( 'recently_activated', array() ); 81 if ( ! $screen->is_network ) { 82 $recently_activated = get_option( 'recently_activated', array() ); 82 83 83 $one_week = 7*24*60*60; 84 foreach ( $recently_activated as $key => $time ) 85 if ( $time + $one_week < time() ) 86 unset( $recently_activated[$key] ); 87 update_option( 'recently_activated', $recently_activated ); 84 $one_week = 7*24*60*60; 85 foreach ( $recently_activated as $key => $time ) 86 if ( $time + $one_week < time() ) 87 unset( $recently_activated[$key] ); 88 update_option( 'recently_activated', $recently_activated ); 89 } 88 90 89 91 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 90 92 // Filter into individual sections 91 if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !$screen->is_network ) { 92 unset( $plugins['all'][ $plugin_file] ); 93 } elseif ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) { 93 if ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) { 94 94 unset( $plugins['all'][ $plugin_file ] ); 95 } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) { 96 $plugins['network'][ $plugin_file ] = $plugin_data; 97 } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) ) 95 } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) ) 98 96 || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) { 99 97 $plugins['active'][ $plugin_file ] = $plugin_data; 100 98 } else { … … 215 213 case 'inactive': 216 214 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); 217 215 break; 218 case 'network':219 $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );220 break;221 216 case 'mustuse': 222 217 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); 223 218 break; … … 248 243 249 244 $screen = get_current_screen(); 250 245 251 if ( 'active' != $status ) { 252 $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected'; 253 $actions[ $action ] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' ); 254 } 246 if ( 'active' != $status ) 247 $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' ); 255 248 256 249 if ( 'inactive' != $status && 'recent' != $status ) 257 250 $actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' ); … … 283 276 284 277 echo '<div class="alignleft actions">'; 285 278 286 if ( 'recently_activated' == $status ) 279 $screen = get_current_screen(); 280 281 if ( ! $screen->is_network && 'recently_activated' == $status ) 287 282 submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false ); 288 283 elseif ( 'top' == $which && 'mustuse' == $status ) 289 284 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>'; … … 321 316 322 317 // preorder 323 318 $actions = array( 324 'network_deactivate' => '', 'deactivate' => '', 325 'network_only' => '', 'activate' => '', 326 'network_activate' => '', 319 'deactivate' => '', 320 'activate' => '', 327 321 'edit' => '', 328 322 'delete' => '', 329 323 ); … … 348 342 if ( $plugin_data['Description'] ) 349 343 $description .= '<p>' . $plugin_data['Description'] . '</p>'; 350 344 } else { 351 $is_active_for_network = is_plugin_active_for_network($plugin_file);352 345 if ( $screen->is_network ) 353 $is_active = $is_active_for_network;346 $is_active = is_plugin_active_for_network( $plugin_file ); 354 347 else 355 348 $is_active = is_plugin_active( $plugin_file ); 356 349 357 if ( $is_active_for_network && !is_super_admin() && !$screen->is_network )358 return;359 360 350 if ( $screen->is_network ) { 361 if ( $is_active _for_network) {351 if ( $is_active ) { 362 352 if ( current_user_can( 'manage_network_plugins' ) ) 363 $actions[' network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';353 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; 364 354 } else { 365 355 if ( current_user_can( 'manage_network_plugins' ) ) 366 $actions[' network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';356 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; 367 357 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) 368 358 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; 369 359 } -
wp-admin/plugins.php
12 12 if ( is_multisite() ) { 13 13 $menu_perms = get_site_option( 'menu_items', array() ); 14 14 15 if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )15 if ( empty( $menu_perms['plugins'] ) && ! current_user_can( 'manage_network_plugins' ) ) 16 16 wp_die( __( 'Cheatin’ uh?' ) ); 17 17 } 18 18 … … 31 31 $_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']); 32 32 33 33 if ( $action ) { 34 $network_wide = false;35 if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )36 $network_wide = true;37 34 38 35 switch ( $action ) { 39 36 case 'activate': … … 42 39 43 40 check_admin_referer('activate-plugin_' . $plugin); 44 41 45 $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), $network_wide);42 $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() ); 46 43 if ( is_wp_error( $result ) ) { 47 44 if ( 'unexpected_output' == $result->get_error_code() ) { 48 45 $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s"); … … 53 50 } 54 51 } 55 52 56 $recent = (array)get_option('recently_activated');57 if ( isset($recent[ $plugin ]) ) {58 unset( $recent[ $plugin ]);59 update_option( 'recently_activated', $recent);53 if ( ! is_network_admin() ) { 54 $recent = (array) get_option( 'recently_activated' ); 55 unset( $recent[ $plugin ] ); 56 update_option( 'recently_activated', $recent ); 60 57 } 58 61 59 if ( isset($_GET['from']) && 'import' == $_GET['from'] ) { 62 60 wp_redirect( self_admin_url("import.php?import=" . str_replace('-importer', '', dirname($plugin))) ); // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix 63 61 } else { … … 66 64 exit; 67 65 break; 68 66 case 'activate-selected': 69 case 'network-activate-selected':70 67 if ( ! current_user_can('activate_plugins') ) 71 68 wp_die(__('You do not have sufficient permissions to activate plugins for this site.')); 72 69 … … 75 72 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 76 73 77 74 // Only activate plugins which are not already active. 78 $check = $network_wide? 'is_plugin_active_for_network' : 'is_plugin_active';75 $check = is_network_admin() ? 'is_plugin_active_for_network' : 'is_plugin_active'; 79 76 foreach ( $plugins as $i => $plugin ) 80 77 if ( $check( $plugin ) ) 81 78 unset( $plugins[ $i ] ); … … 85 82 exit; 86 83 } 87 84 88 activate_plugins($plugins, self_admin_url('plugins.php?error=true'), $network_wide);85 activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin() ); 89 86 90 $recent = (array)get_option('recently_activated'); 91 foreach ( $plugins as $plugin => $time) 92 if ( isset($recent[ $plugin ]) ) 93 unset($recent[ $plugin ]); 87 if ( ! is_network_admin() ) { 88 $recent = (array) get_option('recently_activated' ); 89 foreach ( $plugins as $plugin ) 90 unset( $recent[ $plugin ] ); 91 update_option( 'recently_activated', $recent ); 92 } 94 93 95 update_option('recently_activated', $recent);96 97 94 wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") ); 98 95 exit; 99 96 break; … … 153 150 wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.')); 154 151 155 152 check_admin_referer('deactivate-plugin_' . $plugin); 156 deactivate_plugins($plugin); 157 update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated')); 153 154 if ( ! is_network_admin() && is_plugin_active_for_network() ) { 155 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") ); 156 exit; 157 } 158 159 deactivate_plugins( $plugin, false, is_network_admin() ); 160 if ( ! is_network_admin() ) 161 update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 158 162 if ( headers_sent() ) 159 163 echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />"; 160 164 else … … 168 172 check_admin_referer('bulk-plugins'); 169 173 170 174 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 171 $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated. 175 // Do not deactivate plugins which are already deactivated. 176 if ( is_network_admin() ) { 177 $plugins = array_filter( $plugins, 'is_plugin_active_for_network' ); 178 } else { 179 $plugins = array_filter( $plugins, 'is_plugin_active' ); 180 $plugins = array_diff( $plugins, array_filter( $plugins, 'is_plugin_active_for_network' ) ); 181 } 172 182 if ( empty($plugins) ) { 173 183 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") ); 174 184 exit; 175 185 } 176 186 177 deactivate_plugins( $plugins);187 deactivate_plugins( $plugins, false, is_network_admin() ); 178 188 179 $deactivated = array(); 180 foreach ( $plugins as $plugin ) 181 $deactivated[ $plugin ] = time(); 189 if ( ! is_network_admin() ) { 190 $deactivated = array(); 191 foreach ( $plugins as $plugin ) 192 $deactivated[ $plugin ] = time(); 193 update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) ); 194 } 182 195 183 update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));184 196 wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") ); 185 197 exit; 186 198 break; … … 305 317 exit; 306 318 break; 307 319 case 'clear-recent-list': 308 update_option('recently_activated', array()); 320 if ( ! is_network_admin() ) 321 update_option( 'recently_activated', array() ); 309 322 break; 310 323 } 311 324 } -
wp-admin/plugin-editor.php
65 65 if ( is_plugin_active($file) ) 66 66 deactivate_plugins($file, true); 67 67 68 update_option('recently_activated', array($file => time()) + (array)get_option('recently_activated')); 68 if ( ! is_network_admin() ) 69 update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) ); 69 70 70 71 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide)); 71 72 exit;