public static function get_by_site($site) { global $wpdb; // Allow passing a site object in if (is_object($site) && isset($site->blog_id)) { $site = $site->blog_id; } if (!is_numeric($site)) { return new \WP_Error('mercator.mapping.invalid_id'); } $site = absint($site); // Check cache first $mappings = wp_cache_get('id:' . $site, 'domain_mapping'); if (!empty($mappings)) { return static::to_instances($mappings); } // Cache missed, fetch from DB // Suppress errors in case the table doesn't exist $suppress = $wpdb->suppress_errors(); $mappings = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->dmtable . ' WHERE blog_id = %d', $site)); $wpdb->suppress_errors($suppress); if (!$mappings) { return null; } wp_cache_set('id:' . $site, $mappings, 'domain_mapping'); return static::to_instances($mappings); }
/** * ## OPTIONS * * [<site>] * : Site ID (defaults to current site, use `--url=...`) * * [--format=<format>] * : Format to display as (table, json, csv, count) * * @subcommand list */ public function list_($args, $assoc_args) { $id = empty($args[0]) ? get_current_blog_id() : absint($args[0]); $mappings = Mapping::get_by_site($id); if (empty($mappings)) { return; } $this->display($mappings, $assoc_args); }