Make WordPress Core


Ignore:
Timestamp:
01/29/2010 09:45:32 PM (14 years ago)
Author:
ryan
Message:

Integrate sitewide plugin handling into activate_plugins(), deactivate_plugins(), and plugins.php. fixes #11767 see #11644

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/plugins.php

    r12848 r12903  
    2828    $default_status = 'all';
    2929$status = isset($_REQUEST['plugin_status']) ? $_REQUEST['plugin_status'] : $default_status;
    30 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'search')) )
     30if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'search')) )
    3131    $status = 'all';
    3232if ( $status != $default_status && 'search' != $status )
     
    3939
    4040if ( !empty($action) ) {
     41    $network_wide = false;
     42    if ( isset($_GET['networkwide']) && is_multisite() && is_super_admin() )
     43        $network_wide = true;
     44
    4145    switch ( $action ) {
    4246        case 'activate':
     
    4650            check_admin_referer('activate-plugin_' . $plugin);
    4751
    48             $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin);
     52            $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
    4953            if ( is_wp_error( $result ) )
    5054                wp_die($result);
     
    7276            }
    7377
    74             activate_plugins($plugins, 'plugins.php?error=true');
     78            activate_plugins($plugins, 'plugins.php?error=true', $network_wide);
    7579
    7680            $recent = (array)get_option('recently_activated');
     
    341345$recently_activated = get_option('recently_activated', array());
    342346$upgrade_plugins = array();
     347$network_plugins = array();
    343348
    344349set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 );
     
    354359foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
    355360
    356     //Translate, Apply Markup, Sanitize HTML
     361    // Translate, Apply Markup, Sanitize HTML
    357362    $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
    358363    $all_plugins[ $plugin_file ] = $plugin_data;
    359364
    360     //Filter into individual sections
    361     if ( is_plugin_active($plugin_file) ) {
     365    // Filter into individual sections
     366    if ( is_plugin_active_for_network($plugin_file) && is_super_admin() ) {
     367        $network_plugins[ $plugin_file ] = $plugin_data;
     368    } elseif ( is_plugin_active($plugin_file) ) {
    362369        $active_plugins[ $plugin_file ] = $plugin_data;
    363370    } else {
     
    379386$total_recent_plugins = count($recent_plugins);
    380387$total_upgrade_plugins = count($upgrade_plugins);
     388$total_network_plugins = count($network_plugins);
    381389
    382390//Searching.
     
    409417$plugins = &$$plugin_array_name;
    410418
    411 //Paging.
     419// Paging.
    412420$total_this_page = "total_{$status}_plugins";
    413421$total_this_page = $$total_this_page;
     
    471479        $actions = array();
    472480        $is_active = is_plugin_active($plugin_file);
    473 
    474         if ( $is_active )
    475             $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
    476         else
     481        $is_active_for_network = is_plugin_active_for_network($plugin_file);
     482
     483        if ( $is_active_for_network && !is_super_admin() )
     484            continue;
     485
     486        if ( $is_active ) {
     487            if ( $is_active_for_network ) {
     488                if ( is_super_admin() )
     489                    $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
     490            } else {
     491                $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
     492            }
     493        } else {
    477494            $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
    478 
    479         if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
     495            if ( is_multisite() && is_super_admin() )
     496                $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
     497        }
     498
     499        if ( !is_multisite() && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    480500            $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    481501
     
    593613    $status_links[] = "<li><a href='plugins.php?plugin_status=inactive' $class>" . sprintf( _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $total_inactive_plugins ), number_format_i18n( $total_inactive_plugins ) ) . '</a>';
    594614}
     615if ( ! empty($network_plugins) ) {
     616    $class = ( 'network' == $status ) ? ' class="current"' : '';
     617    $status_links[] = "<li><a href='plugins.php?plugin_status=network' $class>" . sprintf( _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $total_network_plugins ), number_format_i18n( $total_network_plugins ) ) . '</a>';
     618}
    595619if ( ! empty($upgrade_plugins) ) {
    596620    $class = ( 'upgrade' == $status ) ? ' class="current"' : '';
Note: See TracChangeset for help on using the changeset viewer.