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

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 );