Ticket #11644: wpmu_sitewide_plugins.diff

File wpmu_sitewide_plugins.diff, 5.5 KB (added by nacin, 2 years ago)

Merges loading of sitewide/network plugins and validation of them into WP core. Removes ms_network_plugins() and only removes invalid plugins from the stored option when in wp-admin.

  • wp-admin/includes/plugin.php

     
    544544} 
    545545 
    546546/** 
    547  * validate active plugins 
     547 * Validate active plugins 
    548548 * 
    549  * validate all active plugins, deactivates invalid and 
    550  * returns an array of deactived ones. 
     549 * Validate all active plugins, deactivates invalid and 
     550 * returns an array of deactivated ones. 
    551551 * 
    552552 * @since unknown 
    553553 * @return array invalid plugins, plugin as key, error as value 
    554554 */ 
    555555function validate_active_plugins() { 
    556556        $plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ); 
    557  
    558557        // validate vartype: array 
    559         if ( !is_array( $plugins ) ) { 
    560                 update_option('active_plugins', array()); 
    561                 return; 
     558        if ( ! is_array( $plugins ) ) { 
     559                update_option( 'active_plugins', array() ); 
     560                $plugins = array(); 
    562561        } 
    563562 
     563        if ( is_multisite() && is_super_admin() ) { 
     564                $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); 
     565                $plugins = array_merge( (array) $plugins, $network_plugins ); 
     566        } 
     567 
     568        if ( empty( $plugins ) ) 
     569                return; 
     570 
    564571        $invalid = array(); 
    565572 
    566573        // invalid plugins get deactivated 
  • wp-includes/load.php

     
    374374 * @since 3.0.0 
    375375 * @return array Files to include 
    376376 */ 
    377 function wp_muplugins_to_load() { 
     377function wp_load_mu_plugins() { 
    378378        $mu_plugins = array(); 
    379379        if ( !is_dir( WPMU_PLUGIN_DIR ) ) 
    380380                return $mu_plugins; 
     
    399399 * 
    400400 * @access private 
    401401 * @since 3.0.0 
     402 * @param bool $network Whether to return network-wide plugins. Default false. 
    402403 * @return array Files to include 
    403404 */ 
    404 function wp_plugins_to_load() { 
     405function wp_load_plugins( $network = false ) { 
    405406        $plugins = array(); 
    406407 
    407408        // Check for hacks file if the option is enabled 
    408409        if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) 
    409410                        $plugins[] = ABSPATH . 'my-hacks.php'; 
    410411 
    411         $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ); 
    412         if ( !is_array( $active_plugins ) || defined( 'WP_INSTALLING' ) ) 
     412        if ( $network && is_multisite() ) 
     413                $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); 
     414        else 
     415                $active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ); 
     416 
     417        if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) ) 
    413418                return $plugins; 
     419 
    414420        foreach ( $active_plugins as $plugin ) { 
    415                 if ( validate_file( $plugin ) // $plugin must validate as file 
    416                         || '.php' != substr( $plugin, -4 ) // $plugin must end with '.php' 
    417                         || !file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 
     421                if ( ! validate_file( $plugin ) // $plugin must validate as file 
     422                        && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' 
     423                        && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 
    418424                        ) 
    419                         continue; 
    420425                $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 
    421426        } 
    422427        return $plugins; 
  • wp-includes/ms-load.php

     
    2323} 
    2424 
    2525/** 
    26  * Returns array of sitewide plugin files to be included in global scope. 
    27  * 
    28  * @access private 
    29  * @since 3.0.0 
    30  * @return array Files to include 
    31  */ 
    32 function ms_network_plugins() { 
    33         $network_plugins = array(); 
    34         $deleted_sitewide_plugins = array(); 
    35         $wpmu_sitewide_plugins = (array) maybe_unserialize( get_site_option( 'wpmu_sitewide_plugins' ) ); 
    36         foreach ( $wpmu_sitewide_plugins as $plugin_file => $activation_time ) { 
    37                 if ( !$plugin_file ) 
    38                         continue; 
    39  
    40                 if ( !file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) 
    41                         $deleted_sitewide_plugins[] = $plugin_file; 
    42                 else 
    43                         $network_plugins[] = WP_PLUGIN_DIR . '/' . $plugin_file; 
    44         } 
    45  
    46         if ( !empty( $deleted_sitewide_plugins ) ) { 
    47                 $active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) ); 
    48  
    49                 /* Remove any deleted plugins from the wpmu_sitewide_plugins array */ 
    50                 foreach ( $deleted_sitewide_plugins as $plugin_file ) { 
    51                         unset( $wpmu_sitewide_plugins[$plugin_file] ); 
    52                         unset( $active_sitewide_plugins[$plugin_file] ); 
    53                 } 
    54  
    55                 update_site_option( 'wpmu_sitewide_plugins', $wpmu_sitewide_plugins ); 
    56                 update_site_option( 'active_sitewide_plugins', $wpmu_sitewide_plugins ); 
    57         } 
    58  
    59         return $network_plugins; 
    60 } 
    61  
    62 /** 
    6326 * Checks status of current blog. 
    6427 * 
    6528 * Checks if the blog is deleted, inactive, archived, or spammed. 
  • wp-settings.php

     
    136136wp_default_constants( 'wp_included' ); 
    137137 
    138138// Load must-use plugins. 
    139 foreach( wp_muplugins_to_load() as $mu_plugin ) 
     139foreach( wp_load_mu_plugins() as $mu_plugin ) { 
    140140        include_once( $mu_plugin ); 
     141} 
    141142unset( $mu_plugin ); 
    142143 
    143144// Load network-wide plugins if multisite. 
    144145if ( is_multisite() ) { 
    145         foreach ( ms_network_plugins() as $plugin_file ) 
     146        foreach ( wp_load_plugins( true ) as $plugin_file ) { 
    146147                include_once( $plugin_file ); 
     148        } 
    147149        unset( $plugin_file ); 
    148150} 
    149151 
     
    170172create_initial_taxonomies(); 
    171173 
    172174// Load active plugins. 
    173 foreach( wp_plugins_to_load() as $plugin ) 
     175foreach( wp_load_plugins() as $plugin ) 
    174176        include_once( $plugin ); 
    175177unset( $plugin ); 
    176178