public function list_( $args, $assoc_args ) {
		if ( ! is_multisite() ) {
			WP_CLI::error( 'This is not a multisite installation.' );
		}

		global $wpdb;

		if ( isset( $assoc_args['fields'] ) ) {
			$assoc_args['fields'] = preg_split( '/,[ \t]*/', $assoc_args['fields'] );
		}

		$defaults   = [
			'format' => 'table',
			'fields' => [ 'blog_id', 'url', 'last_updated', 'registered' ],
		];
		$assoc_args = array_merge( $defaults, $assoc_args );

		$where  = [];
		$append = '';

		$site_cols = [ 'blog_id', 'last_updated', 'registered', 'site_id', 'domain', 'path', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ];
		foreach ( $site_cols as $col ) {
			if ( isset( $assoc_args[ $col ] ) ) {
				$where[ $col ] = $assoc_args[ $col ];
			}
		}

		if ( isset( $assoc_args['site__in'] ) ) {
			$where['blog_id'] = explode( ',', $assoc_args['site__in'] );
			$append           = 'ORDER BY FIELD( blog_id, ' . implode( ',', array_map( 'intval', $where['blog_id'] ) ) . ' )';
		}

		if ( isset( $assoc_args['network'] ) ) {
			$where['site_id'] = $assoc_args['network'];
		}

		$iterator_args = [
			'table'  => $wpdb->blogs,
			'where'  => $where,
			'append' => $append,
		];

		$iterator = new TableIterator( $iterator_args );

		$iterator = Utils\iterator_map(
			$iterator,
			function( $blog ) {
				$blog->url = trailingslashit( get_site_url( $blog->blog_id ) );
				return $blog;
			}
		);

		if ( ! empty( $assoc_args['format'] ) && 'ids' === $assoc_args['format'] ) {
			$sites     = iterator_to_array( $iterator );
			$ids       = wp_list_pluck( $sites, 'blog_id' );
			$formatter = new Formatter( $assoc_args, null, 'site' );
			$formatter->display_items( $ids );
		} else {
			$formatter = new Formatter( $assoc_args, null, 'site' );
			$formatter->display_items( $iterator );
		}
	}
public function list_( $args, $assoc_args ) {
		if ( ! is_multisite() ) {
			WP_CLI::error( 'This is not a multisite installation.' );
		}

		global $wpdb;

		if ( isset( $assoc_args['fields'] ) ) {
			$assoc_args['fields'] = preg_split( '/,[ \t]*/', $assoc_args['fields'] );
		}

		$defaults   = [
			'format' => 'table',
			'fields' => [ 'blog_id', 'url', 'last_updated', 'registered' ],
		];
		$assoc_args = array_merge( $defaults, $assoc_args );

		$where  = [];
		$append = '';

		$site_cols = [ 'blog_id', 'last_updated', 'registered', 'site_id', 'domain', 'path', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ];
		foreach ( $site_cols as $col ) {
			if ( isset( $assoc_args[ $col ] ) ) {
				$where[ $col ] = $assoc_args[ $col ];
			}
		}

		if ( isset( $assoc_args['site__in'] ) ) {
			$where['blog_id'] = explode( ',', $assoc_args['site__in'] );
			$append           = 'ORDER BY FIELD( blog_id, ' . implode( ',', array_map( 'intval', $where['blog_id'] ) ) . ' )';
		}

		if ( isset( $assoc_args['network'] ) ) {
			$where['site_id'] = $assoc_args['network'];
		}

		$iterator_args = [
			'table'  => $wpdb->blogs,
			'where'  => $where,
			'append' => $append,
		];

		$iterator = new TableIterator( $iterator_args );

		$iterator = Utils\iterator_map(
			$iterator,
			function( $blog ) {
				$blog->url = trailingslashit( get_site_url( $blog->blog_id ) );
				return $blog;
			}
		);

		if ( ! empty( $assoc_args['format'] ) && 'ids' === $assoc_args['format'] ) {
			$sites     = iterator_to_array( $iterator );
			$ids       = wp_list_pluck( $sites, 'blog_id' );
			$formatter = new Formatter( $assoc_args, null, 'site' );
			$formatter->display_items( $ids );
		} else {
			$formatter = new Formatter( $assoc_args, null, 'site' );
			$formatter->display_items( $iterator );
		}
	}
public function list_ ( $ args , $ assoc_args ) { if ( ! is_multisite ( ) ) { WP_CLI :: error ( 'This is not a multisite installation.' ) ; } global $ wpdb ; if ( isset ( $ assoc_args [ 'fields' ] ) ) { $ assoc_args [ 'fields' ] = preg_split ( '/,[ \t]*/' , $ assoc_args [ 'fields' ] ) ; } $ defaults = [ 'format' => 'table' , 'fields' => [ 'blog_id' , 'url' , 'last_updated' , 'registered' ] , ] ; $ assoc_args = array_merge ( $ defaults , $ assoc_args ) ; $ where = [ ] ; $ append = '' ; $ site_cols = [ 'blog_id' , 'last_updated' , 'registered' , 'site_id' , 'domain' , 'path' , 'public' , 'archived' , 'mature' , 'spam' , 'deleted' , 'lang_id' ] ; foreach ( $ site_cols as $ col ) { if ( isset ( $ assoc_args [ $ col ] ) ) { $ where [ $ col ] = $ assoc_args [ $ col ] ; } } if ( isset ( $ assoc_args [ 'site__in' ] ) ) { $ where [ 'blog_id' ] = explode ( ',' , $ assoc_args [ 'site__in' ] ) ; $ append = 'ORDER BY FIELD( blog_id, ' . implode ( ',' , array_map ( 'intval' , $ where [ 'blog_id' ] ) ) . ' )' ; } if ( isset ( $ assoc_args [ 'network' ] ) ) { $ where [ 'site_id' ] = $ assoc_args [ 'network' ] ; } $ iterator_args = [ 'table' => $ wpdb -> blogs , 'where' => $ where , 'append' => $ append , ] ; $ iterator = new TableIterator ( $ iterator_args ) ; $ iterator = Utils \ iterator_map ( $ iterator , function ( $ blog ) { $ blog -> url = trailingslashit ( get_site_url ( $ blog -> blog_id ) ) ; return $ blog ; } ) ; if ( ! empty ( $ assoc_args [ 'format' ] ) && 'ids' === $ assoc_args [ 'format' ] ) { $ sites = iterator_to_array ( $ iterator ) ; $ ids = wp_list_pluck ( $ sites , 'blog_id' ) ; $ formatter = new Formatter ( $ assoc_args , null , 'site' ) ; $ formatter -> display_items ( $ ids ) ; } else { $ formatter = new Formatter ( $ assoc_args , null , 'site' ) ; $ formatter -> display_items ( $ iterator ) ; } }
Lists all sites in a multisite installation.

## OPTIONS

[--network=<id>]
: The network to which the sites belong.

[--<field>=<value>]
: Filter by one or more fields (see "Available Fields" section). However,
'url' isn't an available filter, because it's created from domain + path.

[--site__in=<value>]
: Only list the sites with these blog_id values (comma-separated).

[--field=<field>]
: Prints the value of a single field for each site.

[--fields=<fields>]
: Comma-separated list of fields to show.

[--format=<format>]
: Render output in a particular format.
---
default: table
options:
- table
- csv
- count
- ids
- json
- yaml
---

## AVAILABLE FIELDS

These fields will be displayed by default for each site:

* blog_id
* url
* last_updated
* registered

These fields are optionally available:

* site_id
* domain
* path
* public
* archived
* mature
* spam
* deleted
* lang_id

## EXAMPLES

# Output a simple list of site URLs
$ wp site list --field=url
http://www.example.com/
http://www.example.com/subdir/

@subcommand list
Lists all sites in a multisite installation .