WordPress.org

Make WordPress Core

Changeset 12930


Ignore:
Timestamp:
02/02/2010 09:41:17 PM (11 years ago)
Author:
ryan
Message:

Cleanup network plugin loading. Props nacin. see #11644

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r12914 r12930  
    545545
    546546/**
    547  * validate active plugins
    548  *
    549  * validate all active plugins, deactivates invalid and
    550  * returns an array of deactived ones.
     547 * Validate active plugins
     548 *
     549 * Validate all active plugins, deactivates invalid and
     550 * returns an array of deactivated ones.
    551551 *
    552552 * @since unknown
     
    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());
     558    if ( ! is_array( $plugins ) ) {
     559        update_option( 'active_plugins', array() );
     560        $plugins = array();
     561    }
     562
     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 ) )
    561569        return;
    562     }
    563570
    564571    $invalid = array();
     
    660667/**
    661668 * Add a top level menu page
    662  * 
     669 *
    663670 * This function takes a capability which will be used to determine whether
    664671 * or not a page is included in the menu.
    665  * 
     672 *
    666673 * The function which is hooked in to handle the output of the page must check
    667674 * that the user has the required capability as well.
    668  * 
     675 *
    669676 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    670677 * @param string $menu_title The text to be used for the menu
     
    707714/**
    708715 * Add a top level menu page in the 'objects' section
    709  * 
     716 *
    710717 * This function takes a capability which will be used to determine whether
    711718 * or not a page is included in the menu.
    712  * 
     719 *
    713720 * The function which is hooked in to handle the output of the page must check
    714721 * that the user has the required capability as well.
    715  * 
     722 *
    716723 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    717724 * @param string $menu_title The text to be used for the menu
     
    731738/**
    732739 * Add a top level menu page in the 'utility' section
    733  * 
     740 *
    734741 * This function takes a capability which will be used to determine whether
    735742 * or not a page is included in the menu.
    736  * 
     743 *
    737744 * The function which is hooked in to handle the output of the page must check
    738745 * that the user has the required capability as well.
    739  * 
     746 *
    740747 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    741748 * @param string $menu_title The text to be used for the menu
     
    755762/**
    756763 * Add a sub menu page
    757  * 
     764 *
    758765 * This function takes a capability which will be used to determine whether
    759766 * or not a page is included in the menu.
    760  * 
     767 *
    761768 * The function which is hooked in to handle the output of the page must check
    762769 * that the user has the required capability as well.
    763  * 
     770 *
    764771 * @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page)
    765772 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
     
    814821/**
    815822 * Add sub menu page to the tools main menu.
    816 * 
     823*
    817824 * This function takes a capability which will be used to determine whether
    818825 * or not a page is included in the menu.
    819  * 
     826 *
    820827 * The function which is hooked in to handle the output of the page must check
    821828 * that the user has the required capability as well.
    822  * 
     829 *
    823830 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    824831 * @param string $menu_title The text to be used for the menu
     
    833840/**
    834841 * Add sub menu page to the options main menu.
    835 * 
     842*
    836843 * This function takes a capability which will be used to determine whether
    837844 * or not a page is included in the menu.
    838  * 
     845 *
    839846 * The function which is hooked in to handle the output of the page must check
    840847 * that the user has the required capability as well.
    841  * 
     848 *
    842849 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    843850 * @param string $menu_title The text to be used for the menu
     
    852859/**
    853860 * Add sub menu page to the themes main menu.
    854 * 
     861*
    855862 * This function takes a capability which will be used to determine whether
    856863 * or not a page is included in the menu.
    857  * 
     864 *
    858865 * The function which is hooked in to handle the output of the page must check
    859866 * that the user has the required capability as well.
    860  * 
     867 *
    861868 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    862869 * @param string $menu_title The text to be used for the menu
     
    871878/**
    872879 * Add sub menu page to the Users/Profile main menu.
    873 * 
     880*
    874881 * This function takes a capability which will be used to determine whether
    875882 * or not a page is included in the menu.
    876  * 
     883 *
    877884 * The function which is hooked in to handle the output of the page must check
    878885 * that the user has the required capability as well.
    879  * 
     886 *
    880887 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    881888 * @param string $menu_title The text to be used for the menu
     
    893900/**
    894901 * Add sub menu page to the Dashboard main menu.
    895 * 
     902*
    896903 * This function takes a capability which will be used to determine whether
    897904 * or not a page is included in the menu.
    898  * 
     905 *
    899906 * The function which is hooked in to handle the output of the page must check
    900907 * that the user has the required capability as well.
    901  * 
     908 *
    902909 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    903910 * @param string $menu_title The text to be used for the menu
     
    912919/**
    913920 * Add sub menu page to the posts main menu.
    914 * 
     921*
    915922 * This function takes a capability which will be used to determine whether
    916923 * or not a page is included in the menu.
    917  * 
     924 *
    918925 * The function which is hooked in to handle the output of the page must check
    919926 * that the user has the required capability as well.
    920  * 
     927 *
    921928 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    922929 * @param string $menu_title The text to be used for the menu
     
    931938/**
    932939 * Add sub menu page to the media main menu.
    933 * 
     940*
    934941 * This function takes a capability which will be used to determine whether
    935942 * or not a page is included in the menu.
    936  * 
     943 *
    937944 * The function which is hooked in to handle the output of the page must check
    938945 * that the user has the required capability as well.
    939  * 
     946 *
    940947 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    941948 * @param string $menu_title The text to be used for the menu
     
    950957/**
    951958 * Add sub menu page to the links main menu.
    952 * 
     959*
    953960 * This function takes a capability which will be used to determine whether
    954961 * or not a page is included in the menu.
    955  * 
     962 *
    956963 * The function which is hooked in to handle the output of the page must check
    957964 * that the user has the required capability as well.
    958  * 
     965 *
    959966 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    960967 * @param string $menu_title The text to be used for the menu
     
    969976/**
    970977 * Add sub menu page to the pages main menu.
    971 * 
     978*
    972979 * This function takes a capability which will be used to determine whether
    973980 * or not a page is included in the menu.
    974  * 
     981 *
    975982 * The function which is hooked in to handle the output of the page must check
    976983 * that the user has the required capability as well.
    977  * 
     984 *
    978985 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    979986 * @param string $menu_title The text to be used for the menu
     
    988995/**
    989996 * Add sub menu page to the comments main menu.
    990 * 
     997*
    991998 * This function takes a capability which will be used to determine whether
    992999 * or not a page is included in the menu.
    993  * 
     1000 *
    9941001 * The function which is hooked in to handle the output of the page must check
    9951002 * that the user has the required capability as well.
    996  * 
     1003 *
    9971004 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
    9981005 * @param string $menu_title The text to be used for the menu
  • trunk/wp-includes/load.php

    r12888 r12930  
    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 ) )
     
    402402 * @return array Files to include
    403403 */
    404 function wp_plugins_to_load() {
     404function wp_load_plugins() {
    405405    $plugins = array();
    406406
     
    409409            $plugins[] = ABSPATH . 'my-hacks.php';
    410410
    411     $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
    412     if ( !is_array( $active_plugins ) || defined( 'WP_INSTALLING' ) )
     411    $active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
     412
     413    // Get active network plugins
     414    if ( is_multisite() ) {
     415        $active_sitewide_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
     416        if ( !empty($active_sitewide_plugins) ) {
     417            $active_plugins = array_merge( $active_plugins, array_keys( $active_sitewide_plugins ) );
     418            sort( $active_plugins );
     419        }
     420    }
     421
     422    if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) )
    413423        return $plugins;
     424
    414425    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
     426        if ( ! validate_file( $plugin ) // $plugin must validate as file
     427            && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
     428            && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
    418429            )
    419             continue;
    420430        $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    421431    }
  • trunk/wp-includes/ms-functions.php

    r12900 r12930  
    19331933add_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' );
    19341934
    1935 function mu_filter_plugins_list( $active_plugins ) {
    1936     $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
    1937 
    1938     if ( !$active_sitewide_plugins )
    1939         return $active_plugins;
    1940 
    1941     $plugins = array_merge( (array) $active_plugins, array_keys( (array) $active_sitewide_plugins ) );
    1942     sort( $plugins );
    1943     return $plugins;
    1944 }
    1945 add_filter( 'active_plugins', 'mu_filter_plugins_list' );
    1946 
    1947  /**
     1935/**
    19481936 * Whether to force SSL on content.
    19491937 *
  • trunk/wp-includes/ms-load.php

    r12921 r12930  
    2121
    2222    return false;
    23 }
    24 
    25 /**
    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;
    6023}
    6124
  • trunk/wp-settings.php

    r12926 r12930  
    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 );
    142 
    143 // Load network-wide plugins if multisite.
    144 if ( is_multisite() ) {
    145     foreach ( ms_network_plugins() as $plugin_file )
    146         include_once( $plugin_file );
    147     unset( $plugin_file );
    148 }
    149143
    150144do_action( 'muplugins_loaded' );
     
    171165
    172166// Load active plugins.
    173 foreach( wp_plugins_to_load() as $plugin )
     167foreach ( wp_load_plugins() as $plugin )
    174168    include_once( $plugin );
    175169unset( $plugin );
Note: See TracChangeset for help on using the changeset viewer.