/** * Returns an array of arrays containing information about each public blog hosted on this WPMU install. * * Only sites 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 sites to return in the array (thus the size of the array). * Setting this to string 'all' returns all sites from $start. * @param Integer $expires Time until expiration in seconds, default 86400s (1day). * * @return array|bool * 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. */ function get_blog_list($start = 0, $num = 10, $expires = 86400) { if (!is_multisite()) { return FALSE; } if (!class_exists('Multisite_Core')) { require_once __DIR__ . '/class-core.php'; new Multisite_Core(); } return Multisite_Core::get_blog_list($start, $num, $expires); }
/** * Add Favicon from each blog to Multisite Menu of "My Sites". * * Use the filter hook to change style * Hook: multisite_enhancements_add_admin_bar_favicon * * @since 0.0.2 */ public function set_admin_bar_blog_icon() { // Only usable if the user is logged in and use the admin bar. if (!is_user_logged_in() || !is_admin_bar_showing()) { return; } if (function_exists('wp_get_sites')) { // Since 3.7 inside the Core. $blogs = wp_get_sites(array('limit' => $this->sites_limit)); } else { // Use alternative to core function get_blog_list(). $blogs = Multisite_Core::get_blog_list(0, 'all'); } $output = ''; foreach ((array) $blogs as $blog) { $custom_icon = FALSE; // Validate, that we use nly int value. $blog_id = (int) $blog['blog_id']; $stylesheet = get_blog_option($blog_id, 'stylesheet'); // Get stylesheet directory uri. $theme_root_uri = get_theme_root_uri($stylesheet); $stylesheet_dir_uri = "{$theme_root_uri}/{$stylesheet}"; // Get stylesheet directory. $theme_root = get_theme_root($stylesheet); $stylesheet_dir = "{$theme_root}/{$stylesheet}"; // Create favicon directory and directory url locations. $favicon_dir_uri = $this->get_favicon_path($blog_id, $stylesheet_dir_uri, 'url'); $favicon_dir = $this->get_favicon_path($blog_id, $stylesheet_dir, 'dir'); // Check if the user has manually added a site icon in WP (since WP 4.3). $site_icon_id = (int) get_blog_option($blog_id, 'site_icon'); if (0 !== $site_icon_id) { switch_to_blog($blog_id); $url_data = wp_get_attachment_image_src($site_icon_id, array(32, 32)); $custom_icon = esc_url($url_data[0]); restore_current_blog(); } else { if (file_exists($favicon_dir)) { $custom_icon = $favicon_dir_uri; } } if (FALSE !== $custom_icon) { $output .= '#wpadminbar .quicklinks li#wp-admin-bar-blog-' . $blog['blog_id'] . ' .blavatar { font-size: 0 !important; }'; $output .= '#wp-admin-bar-blog-' . $blog['blog_id'] . ' div.blavatar { background: url( "' . $custom_icon . '" ) left bottom/16px no-repeat !important; background-size: 16px !important; margin: 0 2px 0 -2px; }' . "\n"; } } if ('' !== $output) { /** * Use the filter hook to change style. * * @type string */ echo apply_filters('multisite_enhancements_add_admin_bar_favicon', "\n" . '<style>' . $output . '</style>' . "\n"); } }
/** * Gets an array of blog data including active theme for each blog. * * @since 21/02/2015 * * @return Array */ public function get_blogs_themes() { // See if the data is present in the variable first. if ($this->blogs_themes) { return $this->blogs_themes; // If not, see if we can load data from the transient. } else { if (FALSE === ($this->blogs_themes = get_site_transient(self::$site_transient_blogs_themes))) { // Cannot load data from transient, so load from DB and set transient. $this->blogs_themes = array(); if (function_exists('wp_get_sites')) { // Since 3.7 inside the Core. $blogs = wp_get_sites(array('limit' => $this->sites_limit)); } else { // Use alternative to core function get_blog_list(). $blogs = Multisite_Core::get_blog_list(0, 'all'); } foreach ((array) $blogs as $blog) { $this->blogs_themes[$blog['blog_id']] = $blog; $this->blogs_themes[$blog['blog_id']]['blogpath'] = get_blog_details($blog['blog_id'])->path; $this->blogs_themes[$blog['blog_id']]['blogname'] = get_blog_details($blog['blog_id'])->blogname; $this->blogs_themes[$blog['blog_id']]['template'] = get_blog_option($blog['blog_id'], 'template'); $this->blogs_themes[$blog['blog_id']]['stylesheet'] = get_blog_option($blog['blog_id'], 'stylesheet'); } set_site_transient(self::$site_transient_blogs_themes, $this->blogs_themes); } } // Data should be here, if loaded from transient or DB. return $this->blogs_themes; }
/** * Gets an array of blog data including active theme for each blog. * * @since 21/02/2015 * * @return array */ public function get_blogs_themes() { // See if the data is present in the variable first. if ($this->blogs_themes) { return $this->blogs_themes; // If not, see if we can load data from the transient. } elseif (FALSE === ($this->blogs_themes = get_site_transient(self::$site_transient_blogs_themes))) { // Cannot load data from transient, so load from DB and set transient. $this->blogs_themes = array(); $blogs = (array) Multisite_Core::get_blog_list(0, $this->sites_limit); /** * Data to each site of the network, blogs. * * @var array $blog */ foreach ($blogs as $blog) { // Convert object to array. $blog = (array) $blog; $this->blogs_themes[$blog['blog_id']] = $blog; $this->blogs_themes[$blog['blog_id']]['blogpath'] = get_blog_details($blog['blog_id'])->path; $this->blogs_themes[$blog['blog_id']]['blogname'] = get_blog_details($blog['blog_id'])->blogname; $this->blogs_themes[$blog['blog_id']]['template'] = get_blog_option($blog['blog_id'], 'template'); $this->blogs_themes[$blog['blog_id']]['stylesheet'] = get_blog_option($blog['blog_id'], 'stylesheet'); } if (!$this->development_helper()) { set_site_transient(self::$site_transient_blogs_themes, $this->blogs_themes); } } // Data should be here, if loaded from transient or DB. return $this->blogs_themes; }