示例#1
0
/**
 * check_is_wpmu_plugin_on_activate()
 *
 * When a plugin is activated for just a single blog this function checks to see
 * if the plugin is only supposed to be activated for an entire site (mu-plugin)
 * If so, deactivate it for the blog, and activate it site wide.
 */
function check_wpmu_plugins_on_bulk_activate($plugins)
{
    if ($plugins) {
        foreach ($plugins as $plugin) {
            if (is_wpmu_sitewide_plugin($plugin)) {
                deactivate_plugins($plugin);
                if (is_site_admin()) {
                    activate_sitewide_plugin($plugin);
                }
            }
        }
    }
}
<?php

require_once 'admin.php';
if (!is_site_admin()) {
    wp_die(__('You do not have permission to access this page.'));
}
if (!isset($_GET['action']) || !isset($_GET['plugin'])) {
    wp_redirect('plugins.php');
}
if ('activate' == $_GET['action']) {
    check_admin_referer('activate-sitewide-plugin');
    if (!activate_sitewide_plugin($_GET['plugin'])) {
        wp_redirect('plugins.php?error=true');
    } else {
        do_action('activate_sitewide_plugin', $_GET['plugin']);
        wp_redirect('plugins.php?activate=true');
    }
} else {
    if ('deactivate' == $_GET['action']) {
        check_admin_referer('deactivate-sitewide-plugin');
        if (!deactivate_sitewide_plugin($_GET['plugin'])) {
            wp_redirect('plugins.php?error=true');
        } else {
            do_action('deactivate_sitewide_plugin', $_GET['plugin']);
            wp_redirect('plugins.php?deactivate=true');
        }
    }
}
die;