Changeset 12903 for trunk/wp-admin/includes/plugin.php
- Timestamp:
- 01/29/2010 09:45:32 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/plugin.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/plugin.php
r12891 r12903 264 264 265 265 /** 266 * Check whether the plugin is active for the entire network. 267 * 268 * @since 3.0.0 269 * 270 * @param string $plugin Base plugin path from plugins directory. 271 * @return bool True, if active for the network, otherwise false. 272 */ 273 function is_plugin_active_for_network( $plugin ){ 274 if ( !is_multisite() ) 275 return false; 276 277 $plugins = get_site_option( 'active_sitewide_plugins'); 278 if ( isset($plugins[$plugin]) ) 279 return true; 280 281 return false; 282 } 283 284 /** 285 * Checks for "Site Wide Only: true" in the plugin header to see if this should 286 * be activated as a network wide MU plugin. 287 * 288 * @since 3.0.0 289 * 290 * @todo Use API for getting arbitrary plugin headers. 291 * 292 * @param $file Plugin to check 293 * $return bool True if plugin is network only, false otherwise. 294 */ 295 function is_network_only_plugin( $file ) { 296 /* Open the plugin file for reading to check if this is a ms-plugin. */ 297 $fp = @fopen( WP_PLUGIN_DIR . '/' . $file, 'r' ); 298 299 /* Pull only the first 8kiB of the file in. */ 300 $plugin_data = @fread( $fp, 8192 ); 301 302 /* PHP will close file handle, but we are good citizens. */ 303 @fclose($fp); 304 305 if ( preg_match( '|Site Wide Only:(.*)true$|mi', $plugin_data ) ) 306 return true; 307 308 return false; 309 } 310 311 /** 266 312 * Attempts activation of plugin in a "sandbox" and redirects on success. 267 313 * … … 285 331 * @param string $plugin Plugin path to main plugin file with plugin data. 286 332 * @param string $redirect Optional. URL to redirect to. 333 * @param bool $network_wide Whether to enable the plugin for all sites in the network or just the current site. Multisite only. Default is false. 287 334 * @return WP_Error|null WP_Error on invalid file or null on success. 288 335 */ 289 function activate_plugin( $plugin, $redirect = '' ) { 290 $current = get_option( 'active_plugins', array() ); 336 function activate_plugin( $plugin, $redirect = '', $network_wide = false) { 291 337 $plugin = plugin_basename( trim( $plugin ) ); 338 339 if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) { 340 $network_wide = true; 341 $current = get_site_option( 'active_sitewide_plugins', array() ); 342 } else { 343 $current = get_option( 'active_plugins', array() ); 344 } 292 345 293 346 $valid = validate_plugin($plugin); … … 300 353 ob_start(); 301 354 @include(WP_PLUGIN_DIR . '/' . $plugin); 302 $current[] = $plugin;303 sort($current);304 355 do_action( 'activate_plugin', trim( $plugin) ); 305 update_option('active_plugins', $current); 356 if ( $network_wide ) { 357 $current[$plugin] = time(); 358 update_site_option( 'active_sitewide_plugins', $current ); 359 } else { 360 $current[] = $plugin; 361 sort($current); 362 update_option('active_plugins', $current); 363 } 306 364 do_action( 'activate_' . trim( $plugin ) ); 307 365 do_action( 'activated_plugin', trim( $plugin) ); … … 324 382 */ 325 383 function deactivate_plugins( $plugins, $silent = false ) { 384 $network_current = get_site_option( 'active_sitewide_plugins', array() ); 326 385 $current = get_option( 'active_plugins', array() ); 386 $do_blog = $do_network = false; 327 387 328 388 foreach ( (array) $plugins as $plugin ) { … … 333 393 do_action( 'deactivate_plugin', trim( $plugin ) ); 334 394 335 $key = array_search( $plugin, (array) $current ); 336 337 if ( false !== $key ) 338 array_splice( $current, $key, 1 ); 395 if ( is_plugin_active_for_network($plugin) ) { 396 // Deactivate network wide 397 $do_network = true; 398 unset($network_current[$plugin]); 399 } else { 400 // Deactivate for this blog only 401 $do_blog = true; 402 $key = array_search( $plugin, (array) $current ); 403 404 if ( false !== $key ) 405 array_splice( $current, $key, 1 ); 406 } 339 407 340 408 //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output. … … 345 413 } 346 414 347 update_option('active_plugins', $current); 415 if ( $do_blog ) 416 update_option('active_plugins', $current); 417 if ( $do_network ) 418 update_site_option( 'active_sitewide_plugins', $network_current ); 348 419 } 349 420
Note: See TracChangeset
for help on using the changeset viewer.