Cleanup network plugin loading. Props nacin. see #11644

git-svn-id: http://svn.automattic.com/wordpress/trunk@12930 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-02-02 21:41:17 +00:00
parent 7a4d409064
commit 1592ca9ff2
5 changed files with 78 additions and 116 deletions

View File

@ -544,23 +544,30 @@ function delete_plugins($plugins, $redirect = '' ) {
}
/**
* validate active plugins
* Validate active plugins
*
* validate all active plugins, deactivates invalid and
* returns an array of deactived ones.
* Validate all active plugins, deactivates invalid and
* returns an array of deactivated ones.
*
* @since unknown
* @return array invalid plugins, plugin as key, error as value
*/
function validate_active_plugins() {
$plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
// validate vartype: array
if ( !is_array( $plugins ) ) {
update_option('active_plugins', array());
return;
if ( ! is_array( $plugins ) ) {
update_option( 'active_plugins', array() );
$plugins = array();
}
if ( is_multisite() && is_super_admin() ) {
$network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
$plugins = array_merge( (array) $plugins, $network_plugins );
}
if ( empty( $plugins ) )
return;
$invalid = array();
// invalid plugins get deactivated
@ -659,13 +666,13 @@ function uninstall_plugin($plugin) {
/**
* Add a top level menu page
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -706,13 +713,13 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func
/**
* Add a top level menu page in the 'objects' section
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -730,13 +737,13 @@ function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $fu
/**
* Add a top level menu page in the 'utility' section
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -754,13 +761,13 @@ function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $f
/**
* Add a sub menu page
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page)
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
@ -813,13 +820,13 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,
/**
* Add sub menu page to the tools main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -832,13 +839,13 @@ function add_management_page( $page_title, $menu_title, $capability, $menu_slug,
/**
* Add sub menu page to the options main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -851,13 +858,13 @@ function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $f
/**
* Add sub menu page to the themes main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -870,13 +877,13 @@ function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $fun
/**
* Add sub menu page to the Users/Profile main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -892,13 +899,13 @@ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $fun
}
/**
* Add sub menu page to the Dashboard main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -911,13 +918,13 @@ function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug,
/**
* Add sub menu page to the posts main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -930,13 +937,13 @@ function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $fun
/**
* Add sub menu page to the media main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -949,13 +956,13 @@ function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $fun
/**
* Add sub menu page to the links main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -968,13 +975,13 @@ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $fun
/**
* Add sub menu page to the pages main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
@ -987,13 +994,13 @@ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $fun
/**
* Add sub menu page to the comments main menu.
*
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.

View File

@ -374,7 +374,7 @@ function wp_not_installed() {
* @since 3.0.0
* @return array Files to include
*/
function wp_muplugins_to_load() {
function wp_load_mu_plugins() {
$mu_plugins = array();
if ( !is_dir( WPMU_PLUGIN_DIR ) )
return $mu_plugins;
@ -401,22 +401,32 @@ function wp_muplugins_to_load() {
* @since 3.0.0
* @return array Files to include
*/
function wp_plugins_to_load() {
function wp_load_plugins() {
$plugins = array();
// Check for hacks file if the option is enabled
if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) )
$plugins[] = ABSPATH . 'my-hacks.php';
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
if ( !is_array( $active_plugins ) || defined( 'WP_INSTALLING' ) )
$active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
// Get active network plugins
if ( is_multisite() ) {
$active_sitewide_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
if ( !empty($active_sitewide_plugins) ) {
$active_plugins = array_merge( $active_plugins, array_keys( $active_sitewide_plugins ) );
sort( $active_plugins );
}
}
if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) )
return $plugins;
foreach ( $active_plugins as $plugin ) {
if ( validate_file( $plugin ) // $plugin must validate as file
|| '.php' != substr( $plugin, -4 ) // $plugin must end with '.php'
|| !file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
if ( ! validate_file( $plugin ) // $plugin must validate as file
&& '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
)
continue;
$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
}
return $plugins;

View File

@ -1932,19 +1932,7 @@ Thanks!
}
add_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' );
function mu_filter_plugins_list( $active_plugins ) {
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
if ( !$active_sitewide_plugins )
return $active_plugins;
$plugins = array_merge( (array) $active_plugins, array_keys( (array) $active_sitewide_plugins ) );
sort( $plugins );
return $plugins;
}
add_filter( 'active_plugins', 'mu_filter_plugins_list' );
/**
/**
* Whether to force SSL on content.
*
* @since 2.8.5

View File

@ -22,43 +22,6 @@ function is_subdomain_install() {
return false;
}
/**
* Returns array of sitewide plugin files to be included in global scope.
*
* @access private
* @since 3.0.0
* @return array Files to include
*/
function ms_network_plugins() {
$network_plugins = array();
$deleted_sitewide_plugins = array();
$wpmu_sitewide_plugins = (array) maybe_unserialize( get_site_option( 'wpmu_sitewide_plugins' ) );
foreach ( $wpmu_sitewide_plugins as $plugin_file => $activation_time ) {
if ( !$plugin_file )
continue;
if ( !file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) )
$deleted_sitewide_plugins[] = $plugin_file;
else
$network_plugins[] = WP_PLUGIN_DIR . '/' . $plugin_file;
}
if ( !empty( $deleted_sitewide_plugins ) ) {
$active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
/* Remove any deleted plugins from the wpmu_sitewide_plugins array */
foreach ( $deleted_sitewide_plugins as $plugin_file ) {
unset( $wpmu_sitewide_plugins[$plugin_file] );
unset( $active_sitewide_plugins[$plugin_file] );
}
update_site_option( 'wpmu_sitewide_plugins', $wpmu_sitewide_plugins );
update_site_option( 'active_sitewide_plugins', $wpmu_sitewide_plugins );
}
return $network_plugins;
}
/**
* Checks status of current blog.
*

View File

@ -136,16 +136,10 @@ if ( is_multisite() ) {
wp_default_constants( 'wp_included' );
// Load must-use plugins.
foreach( wp_muplugins_to_load() as $mu_plugin )
foreach ( wp_load_mu_plugins() as $mu_plugin ) {
include_once( $mu_plugin );
unset( $mu_plugin );
// Load network-wide plugins if multisite.
if ( is_multisite() ) {
foreach ( ms_network_plugins() as $plugin_file )
include_once( $plugin_file );
unset( $plugin_file );
}
unset( $mu_plugin );
do_action( 'muplugins_loaded' );
@ -170,7 +164,7 @@ require( ABSPATH . WPINC . '/vars.php' );
create_initial_taxonomies();
// Load active plugins.
foreach( wp_plugins_to_load() as $plugin )
foreach ( wp_load_plugins() as $plugin )
include_once( $plugin );
unset( $plugin );