WordPress.org

Make WordPress Core

Ticket #11644: 11644.12.diff

File 11644.12.diff, 14.9 KB (added by ryan, 4 years ago)

wpmu_sitewide_plugins.diff plus integration of mu_filter_plugins_list() into wp_load_plugins()

  • 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; 
     
    401401 * @since 3.0.0 
    402402 * @return array Files to include 
    403403 */ 
    404 function wp_plugins_to_load() { 
     404function wp_load_plugins() { 
    405405        $plugins = array(); 
    406406 
    407407        // Check for hacks file if the option is enabled 
    408408        if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) 
    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        } 
    422432        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-includes/ms-functions.php

     
    19321932} 
    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 * 
    19501938 * @since 2.8.5 
  • 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 
    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 } 
    149  
    150144do_action( 'muplugins_loaded' ); 
    151145 
    152146// Check site status if multisite. 
     
    170164create_initial_taxonomies(); 
    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 ); 
    176170 
  • 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 
     
    659666 
    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 
    671678 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    706713 
    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 
    718725 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    730737 
    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 
    742749 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    754761 
    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 
    766773 * @param string $menu_title The text to be used for the menu 
     
    813820 
    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 
    825832 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    832839 
    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 
    844851 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    851858 
    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 
    863870 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    870877 
    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 
    882889 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    892899} 
    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 
    904911 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    911918 
    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 
    923930 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    930937 
    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 
    942949 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    949956 
    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 
    961968 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    968975 
    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 
    980987 * @param string $capability The capability required for this menu to be displayed to the user. 
     
    987994 
    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 
    9991006 * @param string $capability The capability required for this menu to be displayed to the user.