k. A clone of wp_count_sites. We use this because * we don't yet support WordPress 5.3. Once we do, we can revert to wp_count_sites. * * @since 4.4.5 * * @return array An array of aliases. */ private function countSites() { $networkId = get_current_network_id(); $counts = []; $args = [ 'network_id' => $networkId, 'number' => 1, 'fields' => 'ids', 'no_found_rows' => false, ]; $q = new \WP_Site_Query( $args ); $counts['all'] = $q->found_sites; $_args = $args; $statuses = [ 'public', 'archived', 'mature', 'spam', 'deleted' ]; foreach ( $statuses as $status ) { $_args = $args; $_args[ $status ] = 1; $q = new \WP_Site_Query( $_args ); $counts[ $status ] = $q->found_sites; } return $counts; } /** * Filter sites based on a passed in filter. Options include 'all', 'activated' or 'deactivated'. * * @since 4.2.5 * * @param Object $site The site object. * @param string $filter The filter to use. * @return bool The site if allowed or null if not. */ private function includeSite( $site, $filter ) { if ( 'all' === $filter ) { return true; } $siteIsActive = aioseo()->networkLicense->isSiteActive( $site ); if ( ( 'deactivated' === $filter && ! $siteIsActive ) || ( 'activated' === $filter && $siteIsActive ) ) { return true; } return false; } /** * Get an array of aliases for a WP_Site. * * @since 4.2.5 * * @param \WP_Site $site The Site. * @return array An array of aliases. */ public function getSiteAliases( $site ) { // We need to look up aliases for Mercator, this checks to see if it's even enabled. if ( ! class_exists( '\Mercator\Mapping' ) ) { return []; } $aliases = \Mercator\Mapping::get_by_site( $site->blog_id ); if ( empty( $aliases ) ) { return []; } $aliasData = []; foreach ( $aliases as $alias ) { $aliasData[] = [ 'alias_id' => $alias->get_id(), 'domain' => $alias->get_domain(), 'active' => $alias->is_active() ]; } return $aliasData; } /** * Wrapper for switch_to_blog especially for non-multisite setups. * * @since 4.2.5 * * @param int $blogId The blog ID to switch to. * @return bool Whether the blog was switched to or not. */ public function switchToBlog( $blogId ) { if ( ! is_multisite() ) { return false; } switch_to_blog( $blogId ); aioseo()->core->db->init(); return true; } /** * Wrapper for restore_current_blog especially for non-multisite setups. * * @since 4.2.5 * * @return bool Whether the blog was restored or not. */ public function restoreCurrentBlog() { if ( ! is_multisite() ) { return false; } restore_current_blog(); aioseo()->core->db->init(); return true; } /** * Checks if the current plugin is network activated. * * @since 4.2.8 * * @param string|null $plugin The plugin to check for network activation. * @return bool True if network activated, false if not. */ public function isPluginNetworkActivated( $plugin = null ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; if ( ! is_multisite() ) { return false; } $plugin = $plugin ? $plugin : plugin_basename( AIOSEO_FILE ); // If the plugin is not network activated, then no it's not network licensed. if ( ! is_plugin_active_for_network( $plugin ) ) { return false; } return true; } }