当前位置: 首页>>代码示例>>PHP>>正文


PHP get_sites函数代码示例

本文整理汇总了PHP中get_sites函数的典型用法代码示例。如果您正苦于以下问题:PHP get_sites函数的具体用法?PHP get_sites怎么用?PHP get_sites使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_sites函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_sites

 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;
     }
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:14,代码来源:tools.php

示例2: add_settings_error

            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') {
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:31,代码来源:network.php

示例3: import_site_relations

 /**
  * 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');
     }
 }
开发者ID:inpsyde,项目名称:multilingual-press,代码行数:20,代码来源:Updater.php

示例4: get_blog_list

 /**
  * 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;
 }
开发者ID:bueltge,项目名称:wordpress-multisite-enhancements,代码行数:79,代码来源:class-core.php

示例5: wp_get_sites

/**
 * 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;
}
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:55,代码来源:ms-deprecated.php

示例6: ocs_uninstall

 * @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') {
开发者ID:JoryHogeveen,项目名称:off-canvas-sidebars,代码行数:31,代码来源:uninstall.php

示例7: ewww_image_optimizer_savings

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;
}
开发者ID:crazyyy,项目名称:bessarabia,代码行数:62,代码来源:common.php

示例8: get_wpmu_posts

 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);
     }
 }
开发者ID:creativelittledots,项目名称:wp-kit-core,代码行数:42,代码来源:helpers.php

示例9: handle_reassign_sites

 /**
  * 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);
         }
     }
 }
开发者ID:stuttter,项目名称:wp-multi-network,代码行数:50,代码来源:class-wp-ms-networks-admin.php

示例10: _get_site_ids

 /**
  * 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);
 }
开发者ID:felixarntz,项目名称:leavesandlove-wp-plugin-util,代码行数:25,代码来源:leavesandlove-wp-plugin-loader.php

示例11: subsite_exists

 /**
  * 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;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:28,代码来源:wpmdbpro-multisite-tools.php

示例12: get_blog_by_name

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;
}
开发者ID:jacobraccuia,项目名称:dailybeatmedia,代码行数:13,代码来源:functions.php

示例13: foreach

/**
 * @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();
}
开发者ID:inpsyde,项目名称:multilingual-press,代码行数:31,代码来源:uninstall.php

示例14: acf_get_sites

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;
}
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:18,代码来源:install-network.php

示例15: getCurrentAdmins

 /**
  * @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;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:38,代码来源:wfLog.php


注:本文中的get_sites函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。