wp site

Создает, удаляет, очищает, модерирует и перечисляет один или несколько сайтов сети.

Список команд Описание
wp site empty Очищает сайт от его содержимого (сообщений, комментариев, терминов и мета-данных).
wp site delete Удаление сайта в мультисайт установке.
wp site create Создает сайт в мультисайт установке.
wp site list Список всех сайтов в мультисайт установке.
wp site archive Архивирует один или несколько сайтов.
wp site unarchive Разархивирует один или несколько сайтов.
wp site activate Активирует один или несколько сайтов.
wp site deactivate Деактивирует один или несколько сайтов.
wp site spam Помечает один или несколько сайтов как спам.
wp site unspam Удаляет один или несколько сайтов из спама.
wp site mature Устанавливает один или несколько сайтов как зрелые (mature).
wp site unmature Устанавливает один или несколько сайтов как незрелые (immature).
wp site set-public Устанавливает один или несколько сайтов как общедоступные.
wp site set-private Устанавливает один или несколько сайтов как частные.
wp site meta list Список всех метаданных, связанных с объектом.
wp site meta get Получает значение мета-поля.
wp site meta delete Удаляет мета-поля.
wp site meta add Добавляет мета-поле.
wp site meta update Обновляет мета-поля.
wp site meta pluck Получает вложенное значение из мета-поля (из сериал-го массива).
wp site meta patch Обновляет вложенные значения мета-поля (сериал-го массива).
wp site option get Возвращает параметр сайта.
wp site option add Добавляет возможность сайта.
wp site option list Список параметров сайта.
wp site option update Обновляет параметр сайта.
wp site option delete Удаляет параметр сайта.
wp site option pluck Возвращает вложенное значение из параметра (из сериал-го массива).
wp site option patch Обновляет вложенное значения в параметре (сериал-го массива).
wp site switch-language Активирует заданный язык.

Примеры

# Create site
$ wp site create --slug=example
Success: Site 3 created: www.example.com/example/

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

# Delete site
$ wp site delete 123
Are you sure you want to delete the 'http://www.example.com/example' site? [y/n] y
Success: The site at 'http://www.example.com/example' was deleted.

Исходный код команд


wp site empty

Очищает сайт от его содержимого (сообщений, комментариев, терминов и мета-данных).

Truncates posts, comments, and terms tables to empty a site of its content. Doesn't affect site configuration (options) or users.

If running a persistent object cache, make sure to flush the cache after emptying the site, as the cache values will be invalid otherwise.

To also empty custom database tables, you'll need to hook into command execution:

WP_CLI::add_hook( 'after_invoke:site empty', function(){
	global $wpdb;
	foreach( array( 'p2p', 'p2pmeta' ) as $table ) {
		$table = $wpdb->$table;
		$wpdb->query( "TRUNCATE $table" );
	}
});

Использование

wp site empty [--uploads] [--yes]

Можно указать Глобальные параметры и следующие:

[--uploads]
Also delete all files in the site's uploads directory.
[--yes]
Proceed to empty the site without a confirmation prompt.

Примеры

$ wp site empty
Are you sure you want to empty the site at http://www.example.com of all posts, comments, and terms? [y/n] y
Success: The site at 'http://www.example.com' was emptied.

wp site delete

Удаление сайта в мультисайт установке.

Использование

wp site delete [{site-id}] [--slug={slug}] [--yes] [--keep-tables]

Можно указать Глобальные параметры и следующие:

[{site-id}]
The id of the site to delete. If not provided, you must set the --slug parameter.
[--slug={slug}]
Path of the blog to be deleted. Subdomain on subdomain installs, directory on subdirectory installs.
[--yes]
Answer yes to the confirmation message.
[--keep-tables]
Delete the blog from the list, but don't drop it's tables.

Примеры

$ wp site delete 123
Are you sure you want to delete the http://www.example.com/example site? [y/n] y
Success: The site at 'http://www.example.com/example' was deleted.

wp site create

Создает сайт в мультисайт установке.

Использование

wp site create --slug={slug} [--title={title}] [--email={email}] [--network_id={network-id}] [--private] [--porcelain]

Можно указать Глобальные параметры и следующие:

--slug={slug}
Path for the new site. Subdomain on subdomain installs, directory on subdirectory installs.
[--title={title}]
Title of the new site. По умолчанию: prettified slug.
[--email={email}]
Email for Admin user. User will be created if none exists. Assignement to Super Admin if not included.
[--network_id={network-id}]
Network to associate new site with. Defaults to current network (typically 1).
[--private]
If set, the new site will be non-public (not indexed)
[--porcelain]
If set, only the site id will be output on success.

Примеры

$ wp site create --slug=example
Success: Site 3 created: http://www.example.com/example/

wp site list

Список всех сайтов в мультисайт установке.

Использование

wp site list [--network={id}] [--{field}={value}] [--site__in={value}] [--field={field}] [--fields={fields}] [--format={format}]

Можно указать Глобальные параметры и следующие:

[--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.
По умолчанию: table
Может быть:

  • table
  • csv
  • count
  • ids
  • json
  • yaml

Доступные поля

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

Примеры

Output a simple list of site URLs:

$ wp site list --field=url
http://www.example.com/
http://www.example.com/subdir/
http://www.example.com/subdir-old/

Output a simple list of site URLs and filter by not-archived blogs:

$ wp site list --field=url  --archived=0 --deleted=0 --spam=0
http://www.example.com/
http://www.example.com/subdir/

wp site archive

Архивирует один или несколько сайтов.

Использование

wp site archive {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to archive.

Примеры

$ wp site archive 123
Success: Site 123 archived.

wp site unarchive

Разархивирует один или несколько сайтов.

Использование

wp site unarchive {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to unarchive.

Примеры

$ wp site unarchive 123
Success: Site 123 unarchived.

wp site activate

Активирует один или несколько сайтов.

Использование

wp site activate {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to activate.

Примеры

$ wp site activate 123
Success: Site 123 activated.

wp site deactivate

Деактивирует один или несколько сайтов.

Использование

wp site deactivate {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to deactivate.

Примеры

$ wp site deactivate 123
Success: Site 123 deactivated.

wp site spam

Помечает один или несколько сайтов как спам.

Использование

wp site spam {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to be marked as spam.

Примеры

$ wp site spam 123
Success: Site 123 marked as spam.

wp site unspam

Удаляет один или несколько сайтов из спама.

Использование

wp site unspam {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to remove from spam.

Примеры

$ wp site unspam 123
Success: Site 123 removed from spam.

wp site mature

Устанавливает один или несколько сайтов как зрелые (mature).

Использование

wp site mature {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to set as mature.

Примеры

$ wp site mature 123
Success: Site 123 marked as mature.

wp site unmature

Устанавливает один или несколько сайтов как незрелые (immature).

Использование

wp site unmature {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to set as unmature.

Примеры

$ wp site general 123
Success: Site 123 marked as unmature.

wp site set-public

Устанавливает один или несколько сайтов как общедоступные.

Использование

wp site set-public {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to set as public.

Примеры

$ wp site public 123
Success: Site 123 marked as public.

wp site set-private

Устанавливает один или несколько сайтов как частные.

Использование

wp site set-private {id}...

Можно указать Глобальные параметры и следующие:

{id}...
One or more IDs of sites to set as private.

Примеры

$ wp site private 123
Success: Site 123 marked as private.

wp site meta list

Список всех метаданных, связанных с объектом.

Использование

wp site meta list {id} [--keys={keys}] [--fields={fields}] [--format={format}] [--orderby={fields}] [--order={order}]

Можно указать Глобальные параметры и следующие:

{id}
ID for the object.
[--keys={keys}]
Limit output to metadata of specific keys.
[--fields={fields}]
Limit the output to specific row fields. Defaults to id,meta_key,meta_value.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • csv
  • json
  • yaml
  • count
[--orderby={fields}]

Set orderby which field.
По умолчанию: id
Может быть:

  • id
  • meta_key
  • meta_value
[--order={order}]

Set ascending or descending order.
По умолчанию: asc
Может быть:

  • asc
  • desc

wp site meta get

Получает значение мета-поля.

Использование

wp site meta get {id} {key} [--format={format}]

Можно указать Глобальные параметры и следующие:

{id}
The ID of the object.
{key}
The name of the meta field to get.
[--format={format}]

Get value in a particular format.
По умолчанию: var_export
Может быть:

  • var_export
  • json
  • yaml

wp site meta delete

Удаляет мета-поля.

Использование

wp site meta delete {id} [{key}] [{value}] [--all]

Можно указать Глобальные параметры и следующие:

{id}
The ID of the object.
[{key}]
The name of the meta field to delete.
[{value}]
The value to delete. If omitted, all rows with key will deleted.
[--all]
Delete all meta for the object.

wp site meta add

Добавляет мета-поле.

Использование

wp site meta add {id} {key} [{value}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{id}
The ID of the object.
{key}
The name of the meta field to create.
[{value}]
The value of the meta field. If omitted, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

wp site meta update

Обновляет мета-поля.

Использование

wp site meta update {id} {key} [{value}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{id}
The ID of the object.
{key}
The name of the meta field to update.
[{value}]
The new value. If omitted, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

wp site meta pluck

Получает вложенное значение из мета-поля (из сериал-го массива).

Использование

wp site meta pluck {id} {key} {key-path}... [--format={format}]

Можно указать Глобальные параметры и следующие:

{id}
The ID of the object.
{key}
The name of the meta field to get.
{key-path}...
The name(s) of the keys within the value to locate the value to pluck.
[--format={format}]
The output format of the value.
--- По умолчанию: plaintext
Может быть:
  • plaintext
  • json
  • yaml

Примеры

Смотрите здесь

wp site meta patch

Обновляет вложенные значения мета-поля (сериал-го массива).

Использование

wp site meta patch {action} {id} {key} {key-path}... [{value}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{action}

Patch action to perform.

Может быть:

  • insert
  • update
  • delete
{id}
The ID of the object.
{key}
The name of the meta field to update.
{key-path}...
The name(s) of the keys within the value to locate the value to patch.
[{value}]
The new value. If omitted, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

Примеры

Смотрите здесь

wp site option get

Возвращает параметр сайта.

Использование

wp site option get {key} [--format={format}]

Можно указать Глобальные параметры и следующие:

{key}
Key for the site option.
[--format={format}]

Get value in a particular format.
По умолчанию: var_export
Может быть:

  • var_export
  • json
  • yaml

Примеры

# Get site upload filetypes
$ wp site option get upload_filetypes
jpg jpeg png gif mov avi mpg

wp site option add

Добавляет возможность сайта.

Использование

wp site option add {key} [{value}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{key}
The name of the site option to add.
[{value}]
The value of the site option to add. If ommited, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

Примеры

# Create a site option by reading a JSON file
$ wp site option add my_option --format=json < config.json
Success: Added 'my_option' site option.

wp site option list

Список параметров сайта.

Использование

wp site option list [--search={pattern}] [--site_id={id}] [--field={field}] [--fields={fields}] [--format={format}]

Можно указать Глобальные параметры и следующие:

[--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.
По умолчанию: table
Может быть:

  • table
  • json
  • csv
  • count
  • yaml
  • total_bytes

Доступные поля

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

Примеры

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

wp site option update

Обновляет параметр сайта.

Использование

wp site option update {key} [{value}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{key}
The name of the site option to update.
[{value}]
The new value. If ommited, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

Примеры

# Update a site option by reading from a file
$ wp site option update my_option < value.txt
Success: Updated 'my_option' site option.

wp site option delete

Удаляет параметр сайта.

Использование

wp site option delete {key}

Можно указать Глобальные параметры и следующие:

{key}
Key for the site option.

Примеры

$ wp site option delete my_option
Success: Deleted 'my_option' site option.

wp site option pluck

Возвращает вложенное значение из параметра (из сериал-го массива).

Использование

wp site option pluck {key} {key-path}... [--format={format}]

Можно указать Глобальные параметры и следующие:

{key}
The option name.
{key-path}...
The name(s) of the keys within the value to locate the value to pluck.
[--format={format}]

The output format of the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json
  • yaml

Примеры

Допустим у нас есть такой сериализованный массив в опции socials_opt:

[
	'location_home' => 'none',
	...
	'icons_order' => [
		[
			'twitter' => 'Twitter',
			'linkedIn' => 'LinkedIn',
			'pinterest' => 'Pinterest',
			'facebook' => 'Facebook',
			'google_plus' => 'Google Plus',
		]
	]
	...
]

Получим данные отдельного элемента сериализованного массива с помощью команды pluck:

$ wp option pluck socials_opt icons_order

[
	'twitter' => 'Twitter',
	'linkedIn' => 'LinkedIn',
	'pinterest' => 'Pinterest',
	'facebook' => 'Facebook',
	'google_plus' => 'Google Plus',
]

Получим значение еще вложенного элемента:

$ wp option pluck socials_opt icons_order twitter

Twitter

wp site option patch

Обновляет вложенное значения в параметре (сериал-го массива).

Использование

wp site option patch {action} {key} {key-path}... [{value}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{action}

Patch action to perform.

Может быть:

  • insert
  • update
  • delete
{key}
The option name.
{key-path}...
The name(s) of the keys within the value to locate the value to patch.
[{value}]
The new value. If omitted, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

Примеры

#1 Допустим у нас есть такой сериализованный массив в опции socials_opt:
[
	'location_home' => 'none',
	...
	'icons_order' => [
		[
			'twitter' => 'Twitter',
			'linkedIn' => 'LinkedIn',
			'pinterest' => 'Pinterest',
			'facebook' => 'Facebook',
			'google_plus' => 'Google Plus',
		]
	]
	...
]

Давайте обновим значение вложенного элемента сериализованного массива с Twitter на TWITTER:

$ wp site option patch update socials_opt icons_order twitter TWITTER
#2 Action параметр

insert и update - это алиасы - они делают одно и тоже.

#3 Action параметр

Если нужно вставить новый элемент в индексный массив, то в параметре {key-path} нужно указать число (индекс) нового элемента массива. Patch сам не добавляет новый элемент, а делает только то что ему сказано.

Например, у нас в опции my_option лежит такой массив:

[
	0 => 'one',
	1 => 'two',
]

Теперь, нам нужно добавить еще один элемент three:

wp site option patch insert my_option 2 three
#4 Еще примеры

https://guides.wp-bullet.com/using-wp-cli-to-batch-update-serialized-wp_options-settings/

wp site switch-language

Активирует заданный язык.

Использование

wp site switch-language {language}

Можно указать Глобальные параметры и следующие:

{language}
Language code to activate.

Примеры

$ wp site switch-language ja
Success: Language activated.