• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP get_sites函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_id_from_blogname

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


示例17: get_blogs_of_user

/**
 * 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);
//.........这里部分代码省略.........
开发者ID:kucrut,项目名称:wordpress,代码行数:101,代码来源:user.php


示例18: wpmn_edit_network_assign_sites_metabox

/**
 * 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 
//.........这里部分代码省略.........
开发者ID:stuttter,项目名称:wp-multi-network,代码行数:101,代码来源:edit-network.php


示例19: subsites_info

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


示例20: get_site_by_path

/**
 * 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;
}
开发者ID:pbearne,项目名称:contrib2core,代码行数:93,代码来源:ms-load.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_size函数代码示例发布时间:2022-05-15
下一篇:
PHP get_siteid函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap