public function list_( $args, $assoc_args ) {

		global $wpdb;
		$pattern    = '%';
		$fields     = [ 'meta_key', 'meta_value' ];
		$size_query = ',LENGTH(meta_value) AS `size_bytes`';

		if ( isset( $assoc_args['search'] ) ) {
			$pattern = self::esc_like( $assoc_args['search'] );
			// substitute wildcards
			$pattern = str_replace( '*', '%', $pattern );
			$pattern = str_replace( '?', '_', $pattern );
		}

		if ( isset( $assoc_args['fields'] ) ) {
			$fields = explode( ',', $assoc_args['fields'] );
		}

		if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
			$fields     = [ 'size_bytes' ];
			$size_query = ',SUM(LENGTH(meta_value)) AS `size_bytes`';
		}

		$query = $wpdb->prepare(
			'SELECT `meta_id`, `site_id`, `meta_key`,`meta_value`'
				. $size_query // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Hard-coded partial query without user input.
				. " FROM `$wpdb->sitemeta` WHERE `meta_key` LIKE %s",
			$pattern
		);

		$site_id = Utils\get_flag_value( $assoc_args, 'site_id' );
		if ( $site_id ) {
			$query .= $wpdb->prepare( ' AND site_id=%d', $site_id );
		}
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $query is already prepared above.
		$results = $wpdb->get_results( $query );

		if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
			WP_CLI::line( $results[0]->size_bytes );
		} else {
			$formatter = new Formatter(
				$assoc_args,
				$fields
			);
			$formatter->display_items( $results );
		}
	}
public function list_( $args, $assoc_args ) {

		global $wpdb;
		$pattern    = '%';
		$fields     = [ 'meta_key', 'meta_value' ];
		$size_query = ',LENGTH(meta_value) AS `size_bytes`';

		if ( isset( $assoc_args['search'] ) ) {
			$pattern = self::esc_like( $assoc_args['search'] );
			// substitute wildcards
			$pattern = str_replace( '*', '%', $pattern );
			$pattern = str_replace( '?', '_', $pattern );
		}

		if ( isset( $assoc_args['fields'] ) ) {
			$fields = explode( ',', $assoc_args['fields'] );
		}

		if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
			$fields     = [ 'size_bytes' ];
			$size_query = ',SUM(LENGTH(meta_value)) AS `size_bytes`';
		}

		$query = $wpdb->prepare(
			'SELECT `meta_id`, `site_id`, `meta_key`,`meta_value`'
				. $size_query // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Hard-coded partial query without user input.
				. " FROM `$wpdb->sitemeta` WHERE `meta_key` LIKE %s",
			$pattern
		);

		$site_id = Utils\get_flag_value( $assoc_args, 'site_id' );
		if ( $site_id ) {
			$query .= $wpdb->prepare( ' AND site_id=%d', $site_id );
		}
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $query is already prepared above.
		$results = $wpdb->get_results( $query );

		if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
			WP_CLI::line( $results[0]->size_bytes );
		} else {
			$formatter = new Formatter(
				$assoc_args,
				$fields
			);
			$formatter->display_items( $results );
		}
	}
public function list_ ( $ args , $ assoc_args ) { global $ wpdb ; $ pattern = '%' ; $ fields = [ 'meta_key' , 'meta_value' ] ; $ size_query = ',LENGTH(meta_value) AS `size_bytes`' ; if ( isset ( $ assoc_args [ 'search' ] ) ) { $ pattern = self :: esc_like ( $ assoc_args [ 'search' ] ) ; // substitute wildcards $ pattern = str_replace ( '*' , '%' , $ pattern ) ; $ pattern = str_replace ( '?' , '_' , $ pattern ) ; } if ( isset ( $ assoc_args [ 'fields' ] ) ) { $ fields = explode ( ',' , $ assoc_args [ 'fields' ] ) ; } if ( Utils \ get_flag_value ( $ assoc_args , 'format' ) === 'total_bytes' ) { $ fields = [ 'size_bytes' ] ; $ size_query = ',SUM(LENGTH(meta_value)) AS `size_bytes`' ; } $ query = $ wpdb -> prepare ( 'SELECT `meta_id`, `site_id`, `meta_key`,`meta_value`' . $ size_query // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Hard-coded partial query without user input. . " FROM `$wpdb->sitemeta` WHERE `meta_key` LIKE %s" , $ pattern ) ; $ site_id = Utils \ get_flag_value ( $ assoc_args , 'site_id' ) ; if ( $ site_id ) { $ query .= $ wpdb -> prepare ( ' AND site_id=%d' , $ site_id ) ; } // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $query is already prepared above. $ results = $ wpdb -> get_results ( $ query ) ; if ( Utils \ get_flag_value ( $ assoc_args , 'format' ) === 'total_bytes' ) { WP_CLI :: line ( $ results [ 0 ] -> size_bytes ) ; } else { $ formatter = new Formatter ( $ assoc_args , $ fields ) ; $ formatter -> display_items ( $ results ) ; } }
Lists site options.

## OPTIONS

[--search=<pattern>]
: Use wildcards ( * and ? ) to match option name.

[--site_id=<id>]
: Limit options to those of a particular site id.

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

[--fields=<fields>]
: Limit the output to specific object fields.

[--format=<format>]
: The serialization format for the value. total_bytes displays the total size of matching options in bytes.
---
default: table
options:
- table
- json
- csv
- count
- yaml
- total_bytes
---

## AVAILABLE FIELDS

This field will be displayed by default for each matching option:

* meta_key
* meta_value

These fields are optionally available:

* meta_id
* site_id
* size_bytes

## EXAMPLES

# List all site options begining with "i2f_"
$ wp site option list --search="i2f_*"
+-------------+--------------+
| meta_key    | meta_value   |
+-------------+--------------+
| i2f_version | 0.1.0        |
+-------------+--------------+

@subcommand list
Lists site options .