public static function get_sites($args)
 {
     // Use wp_get_sites() if WP version is lower than 4.6.0
     global $wp_version;
     if (version_compare($wp_version, '4.6.0', '<')) {
         return wp_get_sites($args);
     } else {
         foreach (get_sites($args) as $blog) {
             $blogs[] = (array) $blog;
             //Convert WP_Site object to array
         }
         return $blogs;
     }
 }
Exemple #2
0
            WPSEO_Options::reset_ms_blog($restoreblog);
            add_settings_error('wpseo_ms', 'settings_updated', sprintf(__('%s restored to default SEO settings.', 'wordpress-seo'), esc_html($blog->blogname)), 'updated');
        } else {
            add_settings_error('wpseo_ms', 'settings_updated', sprintf(__('Blog %s not found.', 'wordpress-seo'), esc_html($restoreblog)), 'error');
        }
        unset($restoreblog, $blog);
    }
}
/* Set up selectbox dropdowns for smaller networks (usability) */
$use_dropdown = true;
if (get_blog_count() > 100) {
    $use_dropdown = false;
} else {
    if (function_exists('get_sites')) {
        // WP 4.6+.
        $sites = array_map('get_object_vars', get_sites(array('deleted' => 0)));
    } else {
        $sites = wp_get_sites(array('deleted' => 0));
    }
    if (is_array($sites) && $sites !== array()) {
        $dropdown_input = array('-' => __('None', 'wordpress-seo'));
        foreach ($sites as $site) {
            $dropdown_input[$site['blog_id']] = $site['blog_id'] . ': ' . $site['domain'];
            $blog_states = array();
            if ($site['public'] === '1') {
                $blog_states[] = __('public', 'wordpress-seo');
            }
            if ($site['archived'] === '1') {
                $blog_states[] = __('archived', 'wordpress-seo');
            }
            if ($site['mature'] === '1') {
 /**
  * Moves site relations from deprecated site options to the new custom network table.
  *
  * @return void
  */
 private function import_site_relations()
 {
     // TODO: With WordPress 4.6 + 2, just use `get_sites()`, and remove `$is_pre_4_6`.
     $is_pre_4_6 = version_compare($GLOBALS['wp_version'], '4.6-RC1', '<');
     $all_sites = $is_pre_4_6 ? wp_get_sites() : get_sites();
     foreach ($all_sites as $site) {
         // TODO: With WordPress 4.6 + 2, just use `$site->id`.
         $site_id = $is_pre_4_6 ? $site['blog_id'] : $site->id;
         $linked = get_blog_option($site_id, 'inpsyde_multilingual_blog_relationship', []);
         if ($linked) {
             $this->site_relations->insert_relations($site_id, $linked);
         }
         delete_blog_option($site_id, 'inpsyde_multilingual_blog_relationship');
     }
 }
 /**
  * Returns an array of arrays containing information about each public blog hosted on this WPMU install.
  *
  * Only blogs marked as public and flagged as safe (mature flag off) are returned.
  *
  * @param  Integer $start   The first blog to return in the array.
  * @param  Integer $num     The number of blogs to return in the array (thus the size of the array).
  *                          Setting this to string 'all' returns all blogs from $start.
  * @param  Boolean $details Get also Postcount for each blog, default is False for a better performance.
  * @param  Integer $expires Time until expiration in seconds, default 86400s (1day).
  *
  * @return array   Returns an array of arrays each representing a blog.
  *                  Details are represented in the following format:
  *                      blog_id   (integer) ID of blog detailed.
  *                      domain    (string)  Domain used to access this blog.
  *                      path      (string)  Path used to access this blog.
  *                      postcount (integer) The number of posts in this blog.
  */
 public static function get_blog_list($start = 0, $num = 10, $details = FALSE, $expires = 86400)
 {
     // Since WP version 4.6.0 is a new function inside the core to get this value.
     if (function_exists('get_sites')) {
         return get_sites(array('number' => $num));
     }
     // For WordPress smaller version 4.6.0, available since WordPress 3.7.
     if (function_exists('wp_get_sites')) {
         return wp_get_sites(array('limit' => $num));
     }
     // Get blog list from cache.
     $blogs = get_site_transient('multisite_blog_list');
     // For debugging purpose.
     if (defined('WP_DEBUG') && WP_DEBUG) {
         $blogs = FALSE;
     }
     if (FALSE === $blogs) {
         global $wpdb;
         // Add limit for select.
         $limit = "LIMIT {$start}, {$num}";
         if ('all' === $num) {
             $limit = '';
         }
         $blogs = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\tSELECT blog_id, domain, path\n\t\t\t\t\tFROM {$wpdb->blogs}\n\t\t\t\t\tWHERE site_id = %d\n\t\t\t\t\tAND public = '1'\n\t\t\t\t\tAND archived = '0'\n\t\t\t\t\tAND mature = '0'\n\t\t\t\t\tAND spam = '0'\n\t\t\t\t\tAND deleted = '0'\n\t\t\t\t\tORDER BY registered ASC\n\t\t\t\t\t{$limit}\n\t\t\t\t", $wpdb->siteid), ARRAY_A);
         // Set the Transient cache.
         set_site_transient('multisite_blog_list', $blogs, $expires);
     }
     // Only if usable, set via var.
     if (TRUE === $details) {
         /**
          * Get data to each site in the network.
          *
          * @var array $blog_list
          */
         $blog_list = get_site_transient('multisite_blog_list_details');
         // For debugging purpose.
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $blog_list = FALSE;
         }
         if (FALSE === $blog_list) {
             global $wpdb;
             /**
              * The data details of each site of the network.
              *
              * @var array $details
              */
             foreach ((array) $blogs as $details) {
                 $blog_list[$details['blog_id']] = $details;
                 $blog_list[$details['blog_id']]['postcount'] = $wpdb->get_var("SELECT COUNT(ID)\n\t\t\t\t\t\tFROM " . $wpdb->get_blog_prefix($details['blog_id']) . "posts\n\t\t\t\t\t\tWHERE post_status='publish'\n\t\t\t\t\t\tAND post_type='post'");
             }
             // Set the Transient cache.
             set_site_transient('multisite_blog_list_details', $blog_list, $expires);
         }
         unset($blogs);
         $blogs = $blog_list;
     }
     if (FALSE === is_array($blogs)) {
         return array();
     }
     return $blogs;
 }
/**
 * Return an array of sites for a network or networks.
 *
 * @since 3.7.0
 * @deprecated 4.6.0
 * @see get_sites()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $args {
 *     Array of default arguments. Optional.
 *
 *     @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
 *                                 from all networks. Defaults to current network ID.
 *     @type int       $public     Retrieve public or non-public sites. Default null, for any.
 *     @type int       $archived   Retrieve archived or non-archived sites. Default null, for any.
 *     @type int       $mature     Retrieve mature or non-mature sites. Default null, for any.
 *     @type int       $spam       Retrieve spam or non-spam sites. Default null, for any.
 *     @type int       $deleted    Retrieve deleted or non-deleted sites. Default null, for any.
 *     @type int       $limit      Number of sites to limit the query to. Default 100.
 *     @type int       $offset     Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
 * }
 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
 *               an associative array of site data arrays, each containing the site (network) ID, blog ID,
 *               site domain and path, dates registered and modified, and the language ID. Also, boolean
 *               values for whether the site is public, archived, mature, spam, and/or deleted.
 */
function wp_get_sites($args = array())
{
    global $wpdb;
    _deprecated_function(__FUNCTION__, '4.6.0', 'get_sites()');
    if (wp_is_large_network()) {
        return array();
    }
    $defaults = array('network_id' => $wpdb->siteid, 'public' => null, 'archived' => null, 'mature' => null, 'spam' => null, 'deleted' => null, 'limit' => 100, 'offset' => 0);
    $args = wp_parse_args($args, $defaults);
    // Backwards compatibility
    if (is_array($args['network_id'])) {
        $args['network__in'] = $args['network_id'];
        $args['network_id'] = null;
    }
    if (is_numeric($args['limit'])) {
        $args['number'] = $args['limit'];
        $args['limit'] = null;
    }
    // Make sure count is disabled.
    $args['count'] = false;
    $_sites = get_sites($args);
    $results = array();
    foreach ($_sites as $_site) {
        $_site = get_site($_site);
        $results[] = $_site->to_array();
    }
    return $results;
}
 * @version 0.3
 * @todo Uninstall for multi-networks aswell
 */
//if uninstall not called from WordPress exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}
if (!is_multisite()) {
    ocs_uninstall();
} else {
    global $wp_version;
    if (version_compare($wp_version, '4.5.999', '<')) {
        // Sadly does not work for large networks -> return false
        $blogs = wp_get_sites();
    } else {
        $blogs = get_sites();
    }
    if (!empty($blogs)) {
        foreach ($blogs as $blog) {
            $blog = (array) $blog;
            ocs_uninstall(intval($blog['blog_id']));
        }
        ocs_uninstall('site');
    }
}
function ocs_uninstall($blog_id = false)
{
    // Delete all options
    $option_keys = array('off_canvas_sidebars_options');
    if ($blog_id) {
        if ($blog_id == 'site') {
Exemple #7
0
function ewww_image_optimizer_savings()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $wpdb;
    if (!function_exists('is_plugin_active_for_network') && is_multisite()) {
        // need to include the plugin library for the is_plugin_active function
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    if (is_multisite() && is_plugin_active_for_network(EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL)) {
        ewwwio_debug_message('querying savings for multi-site');
        if (function_exists('get_sites')) {
            ewwwio_debug_message('retrieving list of sites the easy way (4.6+)');
            add_filter('wp_is_large_network', 'ewww_image_optimizer_large_network', 20, 0);
            $blogs = get_sites(array('fields' => 'ids', 'number' => 10000));
            remove_filter('wp_is_large_network', 'ewww_image_optimizer_large_network', 20, 0);
        } elseif (function_exists('wp_get_sites')) {
            ewwwio_debug_message('retrieving list of sites the easy way (pre 4.6)');
            add_filter('wp_is_large_network', 'ewww_image_optimizer_large_network', 20, 0);
            $blogs = wp_get_sites(array('network_id' => $wpdb->siteid, 'limit' => 10000));
            remove_filter('wp_is_large_network', 'ewww_image_optimizer_large_network', 20, 0);
            /*		} else {
            			ewwwio_debug_message( 'retrieving list of sites the hard way' );
            			$query = "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
            			$blogs = $wpdb->get_results( $query, ARRAY_A );*/
        }
        $total_savings = 0;
        foreach ($blogs as $blog) {
            if (is_array($blog)) {
                $blog_id = $blog['blog_id'];
            } else {
                $blog_id = $blog;
            }
            switch_to_blog($blog_id);
            ewwwio_debug_message("getting savings for site: {$blog_id}");
            $table_name = $wpdb->prefix . 'ewwwio_images';
            if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
                ewww_image_optimizer_install_table();
            }
            $wpdb->query("DELETE FROM {$table_name} WHERE image_size > orig_size");
            $total_query = "SELECT SUM(orig_size-image_size) FROM {$table_name}";
            //ewwwio_debug_message( "query to be performed: $total_query" );
            $savings = $wpdb->get_var($total_query);
            ewwwio_debug_message("savings found: {$savings}");
            $total_savings += $savings;
            //ewwwio_debug_message( "savings so far: $total_savings" );
        }
        restore_current_blog();
    } else {
        ewwwio_debug_message('querying savings for single site');
        $total_savings = 0;
        $table_name = $wpdb->ewwwio_images;
        if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
            ewww_image_optimizer_install_table();
        }
        $wpdb->query('DELETE FROM ' . $wpdb->prefix . 'ewwwio_images WHERE image_size > orig_size');
        $total_query = "SELECT SUM(orig_size-image_size) FROM {$wpdb->ewwwio_images}";
        ewwwio_debug_message("query to be performed: {$total_query}");
        $total_savings = $wpdb->get_var($total_query);
        ewwwio_debug_message("savings found: {$total_savings}");
    }
    return $total_savings;
}
 function get_wpmu_posts($args = array())
 {
     global $wpdb;
     $blogArgs = array('network_id' => $wpdb->siteid, 'public' => is_user_logged_in() ? null : 1, 'archived' => null, 'mature' => null, 'spam' => null, 'deleted' => null, 'limit' => 999, 'offset' => 1);
     $blogs = get_sites($blogArgs);
     foreach ($blogs as $i => $blog) {
         $status = get_blog_status($blog->blog_id, 'public');
         if (!$status && (!is_user_logged_in() || !is_user_member_of_blog(get_current_user_id(), $blog->blog_id) && !is_super_admin())) {
             unset($blogs[$i]);
         }
     }
     $args = array_merge(array('posts_per_page' => 5, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true, 'paged' => get_query_var('paged') ? get_query_var('paged') : 1), $args);
     extract($args);
     $args['posts_per_page'] = -1;
     $args['paged'] = 1;
     $orderbyVal = $orderby === 'meta_value' ? $meta_key : $orderby;
     $posts = array();
     $current_blog = get_current_blog_id();
     foreach ($blogs as $blog) {
         switch_to_blog($blog->blog_id);
         $blog_posts = get_posts($args);
         foreach ($blog_posts as $blog_post) {
             $blog_post->blog_id = $blog->blog_id;
             if ($orderby === 'date') {
                 $ordering = strtotime($blog_post->{$orderbyVal});
             } else {
                 $ordering = $blog_post->{$orderbyVal};
             }
             while (isset($posts[$ordering])) {
                 $ordering = $ordering + 1;
             }
             $posts[$ordering] = $blog_post;
         }
     }
     switch_to_blog($current_blog);
     krsort($posts);
     if ($posts_per_page == -1) {
         return array_slice($posts, 0, count($posts));
     } else {
         return array_slice($posts, ($paged - 1) * $posts_per_page, $posts_per_page);
     }
 }
 /**
  * Handle the request to reassign sites
  *
  * @since 2.0.0
  */
 private function handle_reassign_sites()
 {
     // Coming in
     $to = isset($_POST['to']) ? array_map('absint', (array) $_POST['to']) : array();
     // Orphaning out
     $from = isset($_POST['from']) ? array_map('absint', (array) $_POST['from']) : array();
     // Bail early if no movement
     if (empty($to) && empty($from)) {
         return;
     }
     // Cast the network ID
     $network_id = (int) $_GET['id'];
     // Setup sites arrays
     $moving_to = $moving_from = array();
     // Query for sites in this network
     $sites_list = get_sites(array('network_id' => $network_id, 'fields' => 'ids'));
     // Moving out from current network
     foreach ($from as $site_id) {
         if (in_array($site_id, $sites_list, true)) {
             $moving_from[] = $site_id;
         }
     }
     // Moving into current network
     foreach ($to as $site_id) {
         if (!in_array($site_id, $sites_list, true)) {
             $moving_to[] = $site_id;
         }
     }
     // Merge into one array
     $moving = array_filter(array_merge($moving_to, $moving_from));
     // Loop through and move sites
     foreach ($moving as $site_id) {
         // Skip the main site of this network
         if (is_main_site_for_network($site_id)) {
             continue;
         }
         // Coming in
         if (in_array($site_id, $to) && !in_array($site_id, $sites_list, true)) {
             move_site($site_id, $network_id);
             // Orphaning out
         } elseif (in_array($site_id, $from, true)) {
             move_site($site_id, 0);
         }
     }
 }
 /**
  * Returns an array of site IDs.
  *
  * The function `wp_get_sites()` has been deprecated in WordPress 4.6 in favor of the new `get_sites()`.
  *
  * @since 2.0.2
  * @param boolean $all_networks Whether to return not only sites in the current network, but from all networks.
  * @return array Array of site IDs.
  */
 private static function _get_site_ids($all_networks = false)
 {
     if (!function_exists('get_sites') || !function_exists('get_current_network_id')) {
         $args = array();
         if ($all_networks) {
             $args['network_id'] = 0;
         }
         $sites = wp_get_sites($args);
         return wp_list_pluck($sites, 'blog_id');
     }
     $args = array('fields' => 'ids');
     if (!$all_networks) {
         $args['network_id'] = get_current_network_id();
     }
     return get_sites($args);
 }
 /**
  * Does the passed subsite (ID) exist?
  *
  * @param int $blog_id
  *
  * @return bool
  */
 public function subsite_exists($blog_id)
 {
     if (!is_multisite()) {
         return false;
     }
     if (version_compare($GLOBALS['wp_version'], '4.6', '>=')) {
         $blogs = get_sites(array('limit' => 0));
     } else {
         $blogs = wp_get_sites(array('limit' => 0));
     }
     if (empty($blogs)) {
         return false;
     }
     foreach ($blogs as $blog) {
         $blog = (array) $blog;
         if (!empty($blog['blog_id']) && $blog_id == $blog['blog_id']) {
             return true;
         }
     }
     return false;
 }
function get_blog_by_name($name)
{
    global $blog_list;
    if (!isset($blog_list)) {
        $blog_list = get_sites();
    }
    foreach ($blog_list as $key => $val) {
        if (strpos($val->domain, $name) !== false) {
            return $val->blog_id;
        }
    }
    return null;
}
/**
 * @var wpdb
 */
global $wpdb;
$tables = ['mlp_languages', 'multilingual_linked', 'mlp_site_relations'];
foreach ($tables as $table) {
    $wpdb->query("DROP TABLE IF EXISTS " . $wpdb->base_prefix . $table);
}
// ------ Site options ------
delete_site_option('inpsyde_multilingual');
delete_site_option('inpsyde_multilingual_cpt');
delete_site_option('inpsyde_multilingual_quicklink_options');
delete_site_option('state_modules');
delete_site_option('mlp_version');
delete_site_option('multilingual_press_check_db');
// ------ Blog options ------
// TODO: With WordPress 4.6 + 2, just use `get_sites()` and `$site->id`.
// Get the unaltered WordPress version.
require ABSPATH . WPINC . '/version.php';
/** @var string $wp_version */
$is_pre_4_6 = version_compare($wp_version, '4.6-RC1', '<');
$sites = $is_pre_4_6 ? wp_get_sites() : get_sites();
foreach ($sites as $site) {
    switch_to_blog($is_pre_4_6 ? $site['blog_id'] : $site->id);
    delete_option('inpsyde_multilingual_blog_relationship');
    delete_option('inpsyde_multilingual_redirect');
    delete_option('inpsyde_multilingual_flag_url');
    delete_option('inpsyde_multilingual_default_actions');
    delete_option('inpsyde_license_status_MultilingualPress Pro');
    restore_current_blog();
}
function acf_get_sites()
{
    // vars
    $sites = array();
    // WP >= 4.6
    if (function_exists('get_sites')) {
        $_sites = get_sites();
        foreach ($_sites as $_site) {
            $_site = get_site($_site);
            $sites[] = $_site->to_array();
        }
        // WP < 4.6
    } else {
        $sites = wp_get_sites();
    }
    // return
    return $sites;
}
 /**
  * @return array
  */
 public function getCurrentAdmins()
 {
     require_once ABSPATH . WPINC . '/user.php';
     if (is_multisite()) {
         if (function_exists("get_sites")) {
             $sites = get_sites(array('network_id' => null));
         } else {
             $sites = wp_get_sites(array('network_id' => null));
         }
     } else {
         $sites = array(array('blog_id' => get_current_blog_id()));
     }
     // not very efficient, but the WordPress API doesn't provide a good way to do this.
     $admins = array();
     foreach ($sites as $siteRow) {
         $siteRowArray = (array) $siteRow;
         $user_query = new WP_User_Query(array('blog_id' => $siteRowArray['blog_id'], 'role' => 'administrator'));
         $users = $user_query->get_results();
         if (is_array($users)) {
             /** @var WP_User $user */
             foreach ($users as $user) {
                 $admins[$user->ID] = 1;
             }
         }
     }
     // Add any super admins that aren't also admins on a network
     $superAdmins = get_super_admins();
     foreach ($superAdmins as $userLogin) {
         $user = get_user_by('login', $userLogin);
         if ($user) {
             $admins[$user->ID] = 1;
         }
     }
     return $admins;
 }
/**
 * Retrieves a sites ID given its (subdomain or directory) slug.
 *
 * @since MU
 * @since 4.7.0 Converted to use get_sites().
 *
 * @param string $slug A site's slug.
 * @return int|null The site ID, or null if no site is found for the given slug.
 */
function get_id_from_blogname($slug)
{
    $current_network = get_network();
    $slug = trim($slug, '/');
    if (is_subdomain_install()) {
        $domain = $slug . '.' . preg_replace('|^www\\.|', '', $current_network->domain);
        $path = $current_network->path;
    } else {
        $domain = $current_network->domain;
        $path = $current_network->path . $slug . '/';
    }
    $site_ids = get_sites(array('number' => 1, 'fields' => 'ids', 'domain' => $domain, 'path' => $path));
    if (empty($site_ids)) {
        return null;
    }
    return array_shift($site_ids);
}
Exemple #17
0
/**
 * Get the sites a user belongs to.
 *
 * @since 3.0.0
 * @since 4.7.0 Converted to use get_sites().
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int  $user_id User ID
 * @param bool $all     Whether to retrieve all sites, or only sites that are not
 *                      marked as deleted, archived, or spam.
 * @return array A list of the user's sites. An empty array if the user doesn't exist
 *               or belongs to no sites.
 */
function get_blogs_of_user($user_id, $all = false)
{
    global $wpdb;
    $user_id = (int) $user_id;
    // Logged out users can't have sites
    if (empty($user_id)) {
        return array();
    }
    /**
     * Filters the list of a user's sites before it is populated.
     *
     * Passing a non-null value to the filter will effectively short circuit
     * get_blogs_of_user(), returning that value instead.
     *
     * @since 4.6.0
     *
     * @param null|array $sites   An array of site objects of which the user is a member.
     * @param int        $user_id User ID.
     * @param bool       $all     Whether the returned array should contain all sites, including
     *                            those marked 'deleted', 'archived', or 'spam'. Default false.
     */
    $sites = apply_filters('pre_get_blogs_of_user', null, $user_id, $all);
    if (null !== $sites) {
        return $sites;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return array();
    }
    if (!is_multisite()) {
        $site_id = get_current_blog_id();
        $sites = array($site_id => new stdClass());
        $sites[$site_id]->userblog_id = $site_id;
        $sites[$site_id]->blogname = get_option('blogname');
        $sites[$site_id]->domain = '';
        $sites[$site_id]->path = '';
        $sites[$site_id]->site_id = 1;
        $sites[$site_id]->siteurl = get_option('siteurl');
        $sites[$site_id]->archived = 0;
        $sites[$site_id]->spam = 0;
        $sites[$site_id]->deleted = 0;
        return $sites;
    }
    $site_ids = array();
    if (isset($keys[$wpdb->base_prefix . 'capabilities']) && defined('MULTISITE')) {
        $site_ids[] = 1;
        unset($keys[$wpdb->base_prefix . 'capabilities']);
    }
    $keys = array_keys($keys);
    foreach ($keys as $key) {
        if ('capabilities' !== substr($key, -12)) {
            continue;
        }
        if ($wpdb->base_prefix && 0 !== strpos($key, $wpdb->base_prefix)) {
            continue;
        }
        $site_id = str_replace(array($wpdb->base_prefix, '_capabilities'), '', $key);
        if (!is_numeric($site_id)) {
            continue;
        }
        $site_ids[] = (int) $site_id;
    }
    $sites = array();
    if (!empty($site_ids)) {
        $args = array('number' => '', 'site__in' => $site_ids);
        if (!$all) {
            $args['archived'] = 0;
            $args['spam'] = 0;
            $args['deleted'] = 0;
        }
        $_sites = get_sites($args);
        foreach ($_sites as $site) {
            $sites[$site->id] = (object) array('userblog_id' => $site->id, 'blogname' => $site->blogname, 'domain' => $site->domain, 'path' => $site->path, 'site_id' => $site->network_id, 'siteurl' => $site->siteurl, 'archived' => $site->archived, 'mature' => $site->mature, 'spam' => $site->spam, 'deleted' => $site->deleted);
        }
    }
    /**
     * Filters the list of sites a user belongs to.
     *
     * @since MU
     *
     * @param array $sites   An array of site objects belonging to the user.
     * @param int   $user_id User ID.
     * @param bool  $all     Whether the returned sites array should contain all sites, including
     *                       those marked 'deleted', 'archived', or 'spam'. Default false.
     */
    return apply_filters('get_blogs_of_user', $sites, $user_id, $all);
}
/**
 * Metabox for assigning sites to a network
 *
 * @since 1.7.0
 *
 * @param WP_Network $network
 */
function wpmn_edit_network_assign_sites_metabox($network = null)
{
    // To
    $to = get_sites(array('network_id' => $network->id));
    // From
    $from = get_sites(array('network__not_in' => array($network->id)));
    ?>

	<table class="assign-sites widefat">
		<thead>
			<tr>
				<th><?php 
    esc_html_e('Available Sites', 'wp-multi-network');
    ?>
</th>
				<th>&nbsp;</th>
				<th><?php 
    esc_html_e('Network Sites', 'wp-multi-network');
    ?>
</th>
			</tr>
		</thead>
		<tr>
			<td class="column-available">
				<p class="description"><?php 
    esc_html_e('Subsites in other networks & orphaned sites without networks.', 'wp-multi-network');
    ?>
</p>
				<select name="from[]" id="from" multiple>

					<?php 
    foreach ($from as $site) {
        ?>

						<?php 
        if ((int) $site->site_id !== (int) $network->id && !is_main_site_for_network($site->blog_id)) {
            ?>

							<option value="<?php 
            echo esc_attr($site->blog_id);
            ?>
">
								<?php 
            echo esc_html(sprintf('%1$s (%2$s%3$s)', $site->name, $site->domain, $site->path));
            ?>
							</option>

						<?php 
        }
        ?>

					<?php 
    }
    ?>

				</select>
			</td>
			<td class="column-actions">
				<input type="button" name="unassign" id="unassign" class="button" value="&larr;">
				<input type="button" name="assign" id="assign" class="button" value="&rarr;">
			</td>
			<td class="column-assigned">
				<p class="description"><?php 
    esc_html_e('Only subsites of this network can be reassigned.', 'wp-multi-network');
    ?>
</p>
				<select name="to[]" id="to" multiple>

					<?php 
    foreach ($to as $site) {
        ?>

						<?php 
        if ((int) $site->site_id === (int) $network->id) {
            ?>

							<option value="<?php 
            echo esc_attr($site->blog_id);
            ?>
" <?php 
            disabled(is_main_site_for_network($site->blog_id));
            ?>
>
								<?php 
            echo esc_html(sprintf('%1$s (%2$s%3$s)', $site->name, $site->domain, $site->path));
            ?>
							</option>

						<?php 
        }
        ?>

					<?php 
    }
    ?>

				</select>
			</td>
		</tr>
	</table>

<?php 
}
 /**
  * Get array of subsite info keyed by their ID.
  *
  * @return array
  */
 public function subsites_info()
 {
     $subsites = array();
     if (!is_multisite()) {
         return $subsites;
     }
     if (version_compare($GLOBALS['wp_version'], '4.6', '>=')) {
         $sites = get_sites(array('limit' => 0));
     } else {
         $sites = wp_get_sites(array('limit' => 0));
     }
     if (!empty($sites)) {
         // We to fix up the urls in uploads as they all use primary site's base!
         $primary_url = site_url();
         foreach ($sites as $subsite) {
             $subsite = (array) $subsite;
             $subsites[$subsite['blog_id']]['site_url'] = get_site_url($subsite['blog_id']);
             $subsites[$subsite['blog_id']]['home_url'] = get_home_url($subsite['blog_id']);
             $subsites[$subsite['blog_id']]['uploads'] = $this->uploads_info($subsite['blog_id']);
             $subsites[$subsite['blog_id']]['uploads']['url'] = substr_replace($subsites[$subsite['blog_id']]['uploads']['url'], $subsites[$subsite['blog_id']]['site_url'], 0, strlen($primary_url));
             $subsites[$subsite['blog_id']]['uploads']['baseurl'] = substr_replace($subsites[$subsite['blog_id']]['uploads']['baseurl'], $subsites[$subsite['blog_id']]['site_url'], 0, strlen($primary_url));
         }
     }
     return $subsites;
 }
Exemple #20
0
/**
 * Retrieve a site object by its domain and path.
 *
 * @since 3.9.0
 * @since 4.6.0 Converted to use get_sites()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string   $domain   Domain to check.
 * @param string   $path     Path to check.
 * @param int|null $segments Path segments to use. Defaults to null, or the full path.
 * @return object|false Site object if successful. False when no site is found.
 */
function get_site_by_path($domain, $path, $segments = null)
{
    $path_segments = array_filter(explode('/', trim($path, '/')));
    /**
     * Filters the number of path segments to consider when searching for a site.
     *
     * @since 3.9.0
     *
     * @param int|null $segments The number of path segments to consider. WordPress by default looks at
     *                           one path segment following the network path. The function default of
     *                           null only makes sense when you know the requested path should match a site.
     * @param string   $domain   The requested domain.
     * @param string   $path     The requested path, in full.
     */
    $segments = apply_filters('site_by_path_segments_count', $segments, $domain, $path);
    if (null !== $segments && count($path_segments) > $segments) {
        $path_segments = array_slice($path_segments, 0, $segments);
    }
    $paths = array();
    while (count($path_segments)) {
        $paths[] = '/' . implode('/', $path_segments) . '/';
        array_pop($path_segments);
    }
    $paths[] = '/';
    /**
     * Determine a site by its domain and path.
     *
     * This allows one to short-circuit the default logic, perhaps by
     * replacing it with a routine that is more optimal for your setup.
     *
     * Return null to avoid the short-circuit. Return false if no site
     * can be found at the requested domain and path. Otherwise, return
     * a site object.
     *
     * @since 3.9.0
     *
     * @param null|bool|object $site     Site value to return by path.
     * @param string           $domain   The requested domain.
     * @param string           $path     The requested path, in full.
     * @param int|null         $segments The suggested number of paths to consult.
     *                                   Default null, meaning the entire path was to be consulted.
     * @param array            $paths    The paths to search for, based on $path and $segments.
     */
    $pre = apply_filters('pre_get_site_by_path', null, $domain, $path, $segments, $paths);
    if (null !== $pre) {
        return $pre;
    }
    /*
     * @todo
     * get_blog_details(), caching, etc. Consider alternative optimization routes,
     * perhaps as an opt-in for plugins, rather than using the pre_* filter.
     * For example: The segments filter can expand or ignore paths.
     * If persistent caching is enabled, we could query the DB for a path <> '/'
     * then cache whether we can just always ignore paths.
     */
    // Either www or non-www is supported, not both. If a www domain is requested,
    // query for both to provide the proper redirect.
    $domains = array($domain);
    if ('www.' === substr($domain, 0, 4)) {
        $domains[] = substr($domain, 4);
    }
    $args = array('domain__in' => $domains, 'path__in' => $paths, 'number' => 1);
    if (count($domains) > 1 && count($paths) > 1) {
        $args['orderby'] = 'domain_length path_length';
        $args['order'] = 'DESC DESC';
    } elseif (count($domains) > 1) {
        $args['orderby'] = 'domain_length';
        $args['order'] = 'DESC';
    } elseif (count($paths) > 1) {
        $args['orderby'] = 'path_length';
        $args['order'] = 'DESC';
    }
    $result = get_sites($args);
    $site = array_shift($result);
    if ($site) {
        // @todo get_blog_details()
        return $site;
    }
    return false;
}
 /**
  * Prepares the list of sites for display.
  *
  * @since 3.1.0
  * @since 4.6.0 Converted to use get_sites()
  *
  * @global string $s
  * @global string $mode
  * @global wpdb   $wpdb
  */
 public function prepare_items()
 {
     global $s, $mode, $wpdb;
     if (!empty($_REQUEST['mode'])) {
         $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
         set_user_setting('sites_list_mode', $mode);
     } else {
         $mode = get_user_setting('sites_list_mode', 'list');
     }
     $per_page = $this->get_items_per_page('sites_network_per_page');
     $pagenum = $this->get_pagenum();
     $s = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : '';
     $wild = '';
     if (false !== strpos($s, '*')) {
         $wild = '*';
         $s = trim($s, '*');
     }
     /*
      * If the network is large and a search is not being performed, show only
      * the latest sites with no paging in order to avoid expensive count queries.
      */
     if (!$s && wp_is_large_network()) {
         if (!isset($_REQUEST['orderby'])) {
             $_GET['orderby'] = $_REQUEST['orderby'] = '';
         }
         if (!isset($_REQUEST['order'])) {
             $_GET['order'] = $_REQUEST['order'] = 'DESC';
         }
     }
     $args = array('number' => intval($per_page), 'offset' => intval(($pagenum - 1) * $per_page), 'network_id' => get_current_network_id());
     if (empty($s)) {
         // Nothing to do.
     } elseif (preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $s) || preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.?$/', $s) || preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.?$/', $s) || preg_match('/^[0-9]{1,3}\\.$/', $s)) {
         // IPv4 address
         $sql = $wpdb->prepare("SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like($s) . (!empty($wild) ? '%' : ''));
         $reg_blog_ids = $wpdb->get_col($sql);
         if ($reg_blog_ids) {
             $args['site__in'] = $reg_blog_ids;
         }
     } elseif (is_numeric($s) && empty($wild)) {
         $args['ID'] = $s;
     } else {
         $args['search'] = $s;
         if (!is_subdomain_install()) {
             $args['search_columns'] = array('path');
         }
     }
     $order_by = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : '';
     if ('registered' === $order_by) {
         // registered is a valid field name.
     } elseif ('lastupdated' === $order_by) {
         $order_by = 'last_updated';
     } elseif ('blogname' === $order_by) {
         if (is_subdomain_install()) {
             $order_by = 'domain';
         } else {
             $order_by = 'path';
         }
     } elseif ('blog_id' === $order_by) {
         $order_by = 'id';
     } elseif (!$order_by) {
         $order_by = false;
     }
     $args['orderby'] = $order_by;
     if ($order_by) {
         $args['order'] = isset($_REQUEST['order']) && 'DESC' === strtoupper($_REQUEST['order']) ? "DESC" : "ASC";
     }
     if (wp_is_large_network()) {
         $args['no_found_rows'] = true;
     } else {
         $args['no_found_rows'] = false;
     }
     /**
      * Filters the arguments for the site query in the sites list table.
      *
      * @since 4.6.0
      *
      * @param array $args An array of get_sites() arguments.
      */
     $args = apply_filters('ms_sites_list_table_query_args', $args);
     $_sites = get_sites($args);
     if (is_array($_sites)) {
         update_site_cache($_sites);
         $this->items = array_slice($_sites, 0, $per_page);
     }
     $total_sites = get_sites(array_merge($args, array('count' => true, 'offset' => 0, 'number' => 0)));
     $this->set_pagination_args(array('total_items' => $total_sites, 'per_page' => $per_page));
 }
Exemple #22
0
/**
 * Update the network-wide site count.
 *
 * @since 3.7.0
 * @since 4.6.0 Converted to use get_sites()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function wp_update_network_site_counts()
{
    global $wpdb;
    $count = get_sites(array('network_id' => $wpdb->siteid, 'spam' => 0, 'deleted' => 0, 'archived' => 0, 'count' => true));
    update_site_option('blog_count', $count);
}
    wp_die(__('Sorry, you are not allowed to access this page.'), 403);
}
echo '<div class="wrap">';
echo '<h1>' . __('Upgrade Network') . '</h1>';
$action = isset($_GET['action']) ? $_GET['action'] : 'show';
switch ($action) {
    case "upgrade":
        $n = isset($_GET['n']) ? intval($_GET['n']) : 0;
        if ($n < 5) {
            /**
             * @global string $wp_db_version
             */
            global $wp_db_version;
            update_site_option('wpmu_upgrade_site', $wp_db_version);
        }
        $site_ids = get_sites(array('spam' => '0', 'deleted' => '0', 'archived' => '0', 'network_id' => get_current_network_id(), 'number' => 5, 'offset' => $n, 'fields' => 'ids', 'order' => 'DESC', 'orderby' => 'id'));
        if (empty($site_ids)) {
            echo '<p>' . __('All done!') . '</p>';
            break;
        }
        echo "<ul>";
        foreach ((array) $site_ids as $site_id) {
            switch_to_blog($site_id);
            $siteurl = site_url();
            $upgrade_url = admin_url('upgrade.php?step=upgrade_db');
            restore_current_blog();
            echo "<li>{$siteurl}</li>";
            $response = wp_remote_get($upgrade_url, array('timeout' => 120, 'httpversion' => '1.1', 'sslverify' => false));
            if (is_wp_error($response)) {
                wp_die(sprintf(__('Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: %2$s'), $siteurl, '<em>' . $response->get_error_message() . '</em>'));
            }
 /**
  * Get all the blog IDs for the multisite network used for table prefixes
  *
  * @return false|array
  */
 public function get_blog_ids()
 {
     if (!is_multisite()) {
         return false;
     }
     $args = array('limit' => false, 'spam' => 0, 'deleted' => 0, 'archived' => 0);
     if (version_compare($GLOBALS['wp_version'], '4.6', '>=')) {
         $blogs = get_sites($args);
     } else {
         $blogs = wp_get_sites($args);
     }
     $blog_ids = array();
     foreach ($blogs as $blog) {
         $blog = (array) $blog;
         $blog_ids[] = $blog['blog_id'];
     }
     return $blog_ids;
 }
/**
 * Saving the thumbnail when used on other multisites.
 *
 * @param number $post_id Id of the post.
 */
function afi_save_thumbnail($post_id)
{
    if (!isset($_POST['afi_metabox_nonce'])) {
        // WPCS: input var okay.
        return;
    }
    if (!wp_verify_nonce(sanitize_key($_POST['afi_metabox_nonce']), 'afi_metabox_' . $post_id)) {
        // WPCS: input var okay.
        return;
    }
    // Check if user has permissions to save data.
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    // Check if not an autosave.
    if (wp_is_post_autosave($post_id)) {
        return;
    }
    // Check if not a revision.
    if (wp_is_post_revision($post_id)) {
        return;
    }
    if (!isset($_POST['afi-img-src'])) {
        // WPCS: input var okay.
        return;
    }
    $image_url = sanitize_text_field(wp_unslash($_POST['afi-img-src']));
    // WPCS: input var okay.
    if ('' === $image_url) {
        delete_post_meta($post_id, '_afi_image');
        delete_post_meta($post_id, '_afi_img_src');
        delete_post_meta($post_id, '_thumbnail_id');
        // Getting all the posts that use the AFI image.
        $posts_with_afi = get_option('posts_with_afi_image', array());
        // Deleting the post ID since it is not using the AFI image anymore.
        if (in_array($post_id, $posts_with_afi, true)) {
            $index = array_search($post_id, $posts_with_afi, true);
            unset($posts_with_afi[$index]);
            // Reindexing the array.
            $posts_with_afi = array_values($posts_with_afi);
            update_option('posts_with_afi_image', $posts_with_afi);
        }
        return;
    }
    $image_id = afi_get_attachment_id_from_url($image_url);
    // Current site id.
    $current_blog_id = get_current_blog_id();
    // Flag to track if we have switched to another site.
    $switched_blog = false;
    $switched_count = 0;
    // If the image was not found, we need to look on other blog sites.
    if (is_multisite() && !$image_id) {
        global $wpdb;
        $sites_args = array('public' => 1, 'archived' => 0, 'spam' => 0, 'deleted' => 0);
        $sites = null;
        $deprecated = true;
        // WordPress 4.6 and up. We will not use the deprecated function.
        if (function_exists('get_sites') && class_exists('WP_Site_Query')) {
            $deprecated = false;
        }
        // WordPress 4.6 and up.
        if (!$deprecated) {
            $sites = get_sites($sites_args);
        } else {
            // WordPress below 4.6.
            $sites = wp_get_sites($sites_args);
        }
        foreach ($sites as $site) {
            $site_id = 0;
            // WordPress 4.6 and up.
            if (!$deprecated) {
                $site_id = $site->blog_id;
            } else {
                // WordPress below 4.6.
                $site_id = $site['blog_id'];
            }
            // Skip the site if it is current site we already checked above.
            if ($site_id === $current_blog_id) {
                continue;
            }
            // Switch to the new site.
            switch_to_blog($site_id);
            // Track that we have switched sites.
            $switched_blog = true;
            $switched_count++;
            // Get the image id on this latest site.
            $image_id = afi_get_attachment_id_from_url($image_url);
            // Break from the loop if the image was found, otherwise continue searching.
            if (false !== $image_id) {
                break;
            }
        }
    }
    $images = array();
    if (!$image_id) {
        // The Image was not found on our sites. It must be an image from another site.
        // Let's download it and save it in our main site.
        if (is_multisite() && true === $switched_blog) {
            for ($i = 0; $i < $switched_count; $i++) {
                restore_current_blog();
                // Restore for each switch.
            }
            // We have restored.
            $switched_blog = false;
        }
        $image_id = afi_save_external_image($image_url);
        $image_url = wp_get_attachment_url($image_id);
    }
    // Make sure we found an image.
    if ($image_id) {
        // Get meta data for that attachment id.
        $image_meta_data = wp_get_attachment_metadata($image_id);
        // Get the original, uploaded image.
        $original_image = wp_get_attachment_image_src($image_id, 'full');
        // Add original image to array of sizes.
        $images['full'] = array('url' => $original_image[0], 'width' => $image_meta_data['width'], 'height' => $image_meta_data['height']);
        // Add each generated size of the original image to the array of sizes.
        foreach ($image_meta_data['sizes'] as $size => $size_info) {
            $image = wp_get_attachment_image_src($image_id, $size);
            $images[$size] = array('url' => $image[0], 'width' => $size_info['width'], 'height' => $size_info['height']);
        }
    }
    // Return to the current site, if we switched during checking for images.
    if (is_multisite() && true === $switched_blog) {
        for ($i = 0; $i < $switched_count; $i++) {
            restore_current_blog();
            // Restore for each switch.
        }
        $switched_blog = false;
    }
    // Getting all the posts that use the AFI image.
    $posts_with_afi = get_option('posts_with_afi_image', array());
    // Saving our post ID.
    if (!in_array($post_id, $posts_with_afi, true)) {
        $posts_with_afi[] = $post_id;
        update_option('posts_with_afi_image', $posts_with_afi);
    }
    // Save images to post meta data.
    update_post_meta($post_id, '_afi_image', $images);
    update_post_meta($post_id, '_afi_img_src', $image_url);
    // Fake the `thumbnail_id` so the `has_post_thumbnail` works as intended on other sites.
    update_post_meta($post_id, '_thumbnail_id', $image_id);
}
Exemple #26
-1
 public function index()
 {
     $user = $this->session->userdata('login_check');
     if (isset($user)) {
         redirect('main');
     }
     $admin_user = $this->config->item('tableau_admin_user');
     $admin_pass = $this->config->item('tableau_admin_pass');
     $server_url = $this->config->item('tableau_server_url');
     $credentials = get_credentials($this->config->item('tableau_server_url'), '', $admin_user, $admin_pass);
     $this->form_validation->set_rules('user', 'User', 'required');
     $this->form_validation->set_rules('password', 'Password', 'required');
     $this->form_validation->set_rules('site_url', 'Site_url', 'required');
     //obtengo los sitios con credenciales de admin
     $sites_result = get_sites($server_url, $credentials['token']);
     if ($this->form_validation->run() === FALSE) {
         $data = array('sites' => $sites_result);
         $this->load->view('login_view', $data);
     } else {
         $user_id = $this->input->post('user');
         $password = $this->input->post('password');
         $site_url = $this->input->post('site_url');
         $response = get_credentials($server_url, $site_url, $user_id, $password);
         //Si hubo error de Login en el Server, redirecciono al login con un mensaje Flash
         if ($response['error_msg'] != '') {
             $this->session->set_flashdata('msg', (string) $response['error_msg']);
             redirect('login');
         }
         $this->token = $response['token'];
         $this->site_id = $response['site_id'];
         $this->user_id = $response['user_id'];
         $this->user_name = $user_id;
         $this->site_url = $site_url;
         //obtengo el nombre del Sitio para mostrar despues en Main
         foreach ($sites_result->sites->site as $key => $value) {
             if ((string) $this->site_id == (string) $value['id']) {
                 $this->site_name = (string) $value['name'];
             }
         }
         $this->session->set_userdata('site_url', $site_url);
         $this->session->set_userdata('login_check', $user_id);
         //Guardo las variables en cookies
         $this->set_cookie();
         redirect('/main');
     }
 }
 /**
  * Build list of sites on a multisite network
  *
  * For consistency, will also return result on single-site
  */
 public function list_sites()
 {
     $sites = array();
     if (is_multisite()) {
         // `get_sites()` won't be in Core until at least 4.6
         if (function_exists('get_sites')) {
             $_sites = get_sites(array('public' => 1, 'archived' => 0, 'spam' => 0, 'deleted' => 0, 'fields' => 'ids'));
         } else {
             // Add support for 4.4 and 4.5, as `get_sites()` wasn't introduced until 4.6
             $_sites = get_site_transient($this->cached_sites_list);
             if (!is_array($_sites)) {
                 global $wpdb;
                 $_sites = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs} WHERE `public` = 1 AND `archived` = 0 AND `spam` = 0 AND `deleted` = 0 LIMIT 1000;");
                 if (is_array($_sites)) {
                     set_site_transient($this->cached_sites_list, $_sites, 30 * MINUTE_IN_SECONDS);
                 } else {
                     $_sites = false;
                 }
             }
         }
         // Inflate raw list of site IDs, if available
         if (is_array($_sites)) {
             // Switch to the blog to ensure certain domain filtering is respected
             foreach ($_sites as $_site) {
                 switch_to_blog($_site);
                 $url_parts = wp_parse_args(parse_url(home_url()), array('host' => '', 'path' => ''));
                 $url = $url_parts['host'];
                 if (strlen($url_parts['path']) > 1) {
                     $url .= $url_parts['path'];
                     $url = untrailingslashit($url);
                 }
                 $sites[] = array('domain_name' => $url);
                 unset($url_parts, $url);
                 restore_current_blog();
             }
         } else {
             $sites = new WP_Error('no-sites-found', 'Failed to retrieve any sites for this multisite network.');
         }
     } else {
         // Provided for consistency, even though this provides no insightful response
         $sites[] = array('domain_name' => parse_url(home_url(), PHP_URL_HOST));
     }
     return new WP_REST_Response($sites);
 }
Exemple #28
-1
/**
 * Adjusts the query arguments for the Network Users list table to only show users in the network.
 *
 * It is usually undesirable to have a network administrator see all users regardless of whether
 * they're part of his/her network or not. This function ensures that only the global admin exposes
 * all users.
 *
 * @since 1.0.0
 * @access private
 *
 * @param array $args Original query arguments.
 * @return array Modified query arguments.
 */
function _ga_adjust_users_list_table_query_args($args)
{
    global $wpdb;
    if (!is_multinetwork() || !is_network_admin()) {
        return $args;
    }
    //TODO: When the time is right, this function should use the network_id argument that WP Network Roles introduces.
    $site_ids = get_sites(array('fields' => 'ids', 'network_id' => get_current_network_id()));
    // That's a large meta query, but it's all we can do here at this point.
    $site_queries = array();
    foreach ($site_ids as $site_id) {
        $site_queries[] = array('key' => $wpdb->get_blog_prefix($site_id) . 'capabilities', 'compare' => 'EXISTS');
    }
    $site_queries['relation'] = 'OR';
    if (empty($args['meta_query'])) {
        $args['meta_query'] = $site_queries;
    } else {
        $args['meta_query'] = array('relation' => 'AND', array($args['meta_query'], $site_queries));
    }
    return $args;
}
 /**
  * Run the uninstallation.
  *
  * Will check for Multisite and run uninstall() for each blog.
  *
  * @since 2.3.0
  */
 public static function run()
 {
     // Abort if not running in the WordPress context.
     if (!defined('WP_UNINSTALL_PLUGIN')) {
         die('Must be run within WordPress context.');
     }
     // Also abort if (somehow) it's some other plugin being uninstalled
     if (WP_UNINSTALL_PLUGIN != basename(__DIR__) . '/plugin-name.php') {
         die(sprintf('Illegal attempt to uninstall [Plugin Name] while uninstalling %s.', WP_UNINSTALL_PLUGIN));
     }
     // Check if this site is a Multisite installation
     if (is_multisite()) {
         // Run through each blog and perform the uninstall on each one
         $sites = get_sites(array('fields' => 'ids'));
         foreach ($sites as $site) {
             switch_to_blog($site);
             self::uninstall();
             restore_current_blog();
         }
     } else {
         self::uninstall();
     }
 }
 /**
  * Fired when the plugin is deactivated.
  *
  * @since    2.0.0
  *
  * @param    boolean    $network_wide    True if WPMU superadmin uses
  *                                       "Network Deactivate" action, false if
  *                                       WPMU is disabled or plugin is
  *                                       deactivated on an individual blog.
  */
 public function deactivate($network_wide)
 {
     if ($network_wide && function_exists('is_multisite') && is_multisite()) {
         // Get all blog ids of the current network
         $sites = get_sites(['fields' => 'ids']);
         foreach ($sites as $site) {
             switch_to_blog($site);
             $this->single_deactivate();
         }
         restore_current_blog();
     } else {
         $this->single_deactivate();
     }
 }