/** * 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)); }
/** * Adds any sites from the given ids to the cache that do not already exist in cache. * * @since 4.6.0 * @access private * * @see update_site_cache() * * @global wpdb $wpdb WordPress database abstraction object. * * @param array $ids ID list. */ function _prime_site_caches($ids) { global $wpdb; $non_cached_ids = _get_non_cached_ids($ids, 'sites'); if (!empty($non_cached_ids)) { $fresh_sites = $wpdb->get_results(sprintf("SELECT * FROM {$wpdb->blogs} WHERE blog_id IN (%s)", join(",", array_map('intval', $non_cached_ids)))); update_site_cache($fresh_sites); } }