WP-CLI (commando's)

Uit De Vliegende Brigade
Ga naar: navigatie, zoeken

Zie ook WP-CLI (algemeen).

Inhoud

wp

wp is het hoofdcommando.

  • Als je dit commando (zonder argmenten) geeft terwijl de werkmap geen WP-installatie betreft, krijg je een overzicht van de 'generieke' wp-commando's
  • Als je dit commando (zonder argumenten) geeft terwijl de werkmap een WP-installatie betreft, krijg je tevens plugin-specifieke commando's te zien.

Voorbeeld deel van de output binnen een WP-installatie waar WooCommerce is geïnstalleer ('wp wc'):

NAME

  wp

DESCRIPTION

  Manage WordPress through the command-line.

SYNOPSIS

  wp <command>

SUBCOMMANDS

  cache               Manage the object cache.
  cap                 Manage user capabilities.
  checksum            Verify WordPress core checksums.
  cli                 Review current WP-CLI info, check for updates, or see
                      defined aliases.
  comment             Manage comments.
  config              Manage the wp-config.php file
  core                Download, install, update and manage a WordPress
                      install.
  cron                Manage WP-Cron events and schedules.
  db                  Perform basic database operations using credentials
                      stored in wp-config.php
  eval                Execute arbitrary PHP code.
  eval-file           Load and execute a PHP file.
  export              Export WordPress content to a WXR file.
  help                Get help on WP-CLI, or on a specific command.
  import              Import content from a WXR file.
  language            
  media               Import new attachments or regenerate existing ones.
  menu                List, create, assign, and delete menus.
  network             
  option              Manage options.
  package             Manage WP-CLI packages.
  plugin              Manage plugins.
  post                Manage posts.
  post-type           Manage post types.
  rewrite             Manage rewrite rules.
  role                Manage user roles.
  scaffold            Generate code for post types, taxonomies, plugins,
                      child themes, etc.
  search-replace      Search/replace strings in the database.
  server              Launch PHP's built-in web server for this specific
                      WordPress installation.
  shell               Interactive PHP console.
  sidebar             Manage sidebars.
  site                Perform site-wide operations.
  super-admin         Manage super admins on WordPress multisite.
  taxonomy            Manage taxonomies.
  term                Manage terms.
  theme               Manage themes.
  transient           Manage transients.
  user                Manage users.
  wc                  
  widget              Manage sidebar widgets.

wp cli update

Je kunt WP-CLI updaten middels

wp cli update

of door 'm opnieuw te installeren.

wp comment <subcommando>

https://developer.wordpress.org/cli/commands/comment/:

wp comment approve 	Approve a comment.
wp comment count 	Count comments, on whole blog or on a given post.
wp comment create 	Create a new comment.
wp comment delete 	Delete a comment.
wp comment exists 	Verify whether a comment exists.
wp comment generate 	Generate some number of new dummy comments.
wp comment get 	        Get data of a single comment.
wp comment list 	Get a list of comments.
wp comment meta 	Manage comment custom fields.
wp comment recount 	Recalculate the comment_count value for one or more posts.
wp comment spam 	Mark a comment as spam.
wp comment status 	Get status of a comment.
wp comment trash 	Trash a comment.
wp comment unapprove 	Unapprove a comment.
wp comment unspam 	Unmark a comment as spam.
wp comment untrash 	Untrash a comment.
wp comment update 	Update one or more comments.

wp comment delete

Bv.:

> wp comment list
+------------+-----------------+--------------------+------------------+--------------------+-----------------------+
| comment_ID | comment_post_ID | comment_date       | comment_approved | comment_author     | comment_author_email  |
+------------+-----------------+--------------------+------------------+--------------------+-----------------------+
| 1          | 1               | 2017-10-13 13:02:3 | 1                | A WordPress Commen | wapuu@wordpress.examp |
|            |                 | 7                  |                  | ter                | le                    |
+------------+-----------------+--------------------+------------------+--------------------+-----------------------+

> wp comment delete 1
Success: Trashed comment 1.

wp comment list

Bv.:

> wp comment list
+------------+-----------------+--------------------+------------------+--------------------+-----------------------+
| comment_ID | comment_post_ID | comment_date       | comment_approved | comment_author     | comment_author_email  |
+------------+-----------------+--------------------+------------------+--------------------+-----------------------+
| 1          | 1               | 2017-10-13 13:02:3 | 1                | A WordPress Commen | wapuu@wordpress.examp |
|            |                 | 7                  |                  | ter                | le                    |
+------------+-----------------+--------------------+------------------+--------------------+-----------------------+

wp config <subcommando>

* wp config create
* wp config get
* wp config path

wp core <subcommando>

Download, install, update and manage a WordPress install. Subcommando's:

* wp core check-update 	      Check for WordPress updates via Version Check API.
* wp core config              Creëer een config-bestand, voorafgaand aan installatie van een site
* wp core download 	      Download core WordPress files.
* wp core install 	      Runs the standard WordPress installation process.
* wp core is-installed 	      Check if WordPress is installed.
* wp core multisite-convert   Transform a single-site install into a WordPress multisite install.
* wp core multisite-install   Install WordPress multisite from scratch.
* wp core update 	      Update WordPress to a newer version.
* wp core update-db           Run the WordPress database update procedure.
* wp core version 	      Display the WordPress version.

wp core config

Creëer een nieuw wp-config.php-bestand. Dit commando wordt niet genoemd op de site. Daar heb je het vergelijkbare commando wp config create.

wp config create

   --dbname=<dbname>            Set the database name.
   --dbuser=<dbuser>            Set the database user.
   [--dbpass=<dbpass>]          Set the database user password.
   [--dbhost=<dbhost>]          Set the database host.
                                default: localhost
   [--dbprefix=<dbprefix>]      Set the database table prefix.
                                default: wp_
   [--dbcharset=<dbcharset>]    Set the database charset.
                                default: utf8
   [--dbcollate=<dbcollate>]    Set the database collation.
                                default:
   [--locale=<locale>]          Set the WPLANG constant. 
                                Defaults to $wp_local_package variable.
   [--extra-php]                If set, the command copies additional PHP code 
                                into wp-config.php from STDIN.
   [--skip-salts]               If set, keys and salts won’t be generated, 
                                but should instead be passed via --extra-php.
   [--skip-check]               If set, the database connection is not checked.
   [--force]                    Overwrites existing files, if present. 

wp core download

Voorbeeld van gedownloade WordPress-instanties als zip-bestanden

download een actuele WordPress-instantie en plaats die uitgepakt en MD5-geverifiëerd in de werkmap, of in de map die wordt meegegeven.

wp core download

   [--path=<path>]         Specify the path in which to install WordPress. Defaults to current directory.
   [--locale=<locale>]     Select which language you want to download.
   [--version=<version>]   Select which version you want to download. Accepts a version number, ‘latest’ or ‘nightly’
   [--force]               Overwrites existing files, if present. 

Wat-ie precies doet:

  • De WordPress-instantie wordt gedownload als gezipped phar-archief naar /tmp. Zie afbeelding hiernaast
  • md5-hash van dit archiefbestand wordt geverifiëerd
  • Het archiefbestand wordt uitgepakt naar een tijdelijke locatie

Foutmelding: Couldn't decompress

Het probleem:

wp core download
Downloading WordPress 4.8.2 (en_US)...
md5 hash verified: 2e8744a702a3d9527782d9135a4c9544
Error: Couldn't extract WordPress archive. unable to decompress gzipped phar archive "/tmp/wp_59c276fb45c4b.tar.gz" to temporary file

Aanvullende gegevens:

  • sudo chmod o+w /tmp - Hielp niet
  • sudo /usr/local/bin/wp core download --allow-root - Hielp niet
  • wp cli ge-update - Hielp niet

wp core install

Installeer een gedownloade WordPress-instantie:

wp core install 

   --url=<url> 
   --title=<site-title> 
   --admin_user=<username>
   [--admin_password=<password>]   # Defaults to randomly generated string
   [--admin_email=<email>]
   [--skip-email]                  # Don't send email notification
  • Dit commando moet uitgevoerd worden in de working map waar de installatiebestanden staan, en waar de site geïnstalleerd moet worden
  • Op mijn ontwikkelcomputer kreeg ik een foutmelding dat Sendmail niet gevonden kon worden. Ik weet niet of dat door het script komt, of een configuratiefout ergen op m'n computer.

wp core update

Simpel:

wp core update

Plugins worden hierbij niet bijgewerkt.

wp core update-db

Geen idee waarom er een apart commando is om de db bij te werken. Eén keer gedaan na update van een site die al een tijdje niet was bijgewerkt: Geen verschil.

wp help

Bv.:

wp help post
wp help post get

wp plugin <subcommando>

* wp plugin activate 	   Activate a plugin.
* wp plugin deactivate 	   Deactivate a plugin.
* wp plugin delete 	   Delete plugin files without deactivating or uninstalling.
* wp plugin get 	   Get details about an installed plugin.
* wp plugin install 	   Install a plugin.
* wp plugin is-installed   Check if the plugin is installed.
* wp plugin list 	   Get a list of plugins.
* wp plugin path 	   Get the path to a plugin or to the plugin directory.
* wp plugin search 	   Search the WordPress.org plugin directory.
* wp plugin status 	   See the status of one or all plugins.
* wp plugin toggle 	   Toggle a plugin’s activation state.
* wp plugin uninstall 	   Uninstall a plugin.
* wp plugin update 	   Update one or more plugins.

wp plugin activate

Bv.

wp plugin activate hello

wp plugin deactivate

Bv.

wp plugin deactivate hello

wp plugin delete

Bv.

wp plugin delete hello

WP-CLI kan schrijven en bestanden verwijderen - Handig!

wp plugin install

Installeer een WP-plugin op een site:

wp plugin install

   <plugin-naam|zip|url>   # A plugin slug, the path to a local zip file, or URL to a remote zip file.

   [--version=<version>]   # If set, get that particular version from wordpress.org, 
                           # instead of the stable version

   [--force]               # If set, the command will overwrite any installed version of the plugin, 
                           # without prompting for confirmation.

   [--activate]            # If set, the plugin will be activated immediately after install.

   [--activate-network]    # If set, the plugin will be network activated immediately after install

Voorbeeld

wp plugin install duplicate-page --activate

wp plugin search

Zoek in de online plugin-bibliotheek:

wp plugin search

   <search>                  The string to search for.

   [--page=<page>]           Optional page to display.
                             default: 1

   [--per-page=<per-page>]   Optional number of results to display.
                             default: 10
   [--field=<field>]         Prints the value of a single field for each plugin.
   [--fields=<fields>]       Ask for specific fields from the API. Defaults to name,slug,author_profile,rating. Acceptable values:

    name: Plugin Name
    slug: Plugin Slug
    version: Current Version Number
    author: Plugin Author
    author_profile: Plugin Author Profile
    contributors: Plugin Contributors
    requires: Plugin Minimum Requirements
    tested: Plugin Tested Up To
    compatibility: Plugin Compatible With
    rating: Plugin Rating
    num_ratings: Number of Plugin Ratings
    homepage: Plugin Author’s Homepage
    description: Plugin’s Description
    short_description: Plugin’s Short Description 

[--format=<format>]          Render output in a particular format.

    default: table
    options:
    – table
    – csv
    – count
    – json
    – yaml

wp plugin status

Bv.:

wp plugin status

 installed plugins:
 UI akismet 3.3.3
  A hello   1.6

Legend: I = Inactive, A = Active, U = Update Available

wp plugin update

wp plugin update

   [<plugin>…]              One or more plugins to update.
   [--all]                  If set, all plugins that have updates will be updated.
   [--exclude=<name>]       Comma separated list of plugin names that should be excluded from updating.
   [--minor]                Only perform updates for minor releases (e.g. from 1.3 to 1.4 instead of 2.0)
   [--patch]                Only perform updates for patch releases (e.g. from 1.3 to 1.3.3 instead of 1.4)
   [--format=<format>]      Render output in a particular format.
    ---
    default: table
    options:
    – table
    – csv
    – json
    – summary
    ---
   [--version=<version>]   If set, the plugin will be updated to the specified version.
   [--dry-run]             Preview which plugins would be updated. 

Bv.:

wp plugin update --all

wp post <subcommando>

  • Manages posts, content (pages), and meta. Especially also pages'. Er is geen commando zoals wp page
  • Help: wp help post

Bronnen

wp post create

Voorbeelden

# * Zonder post_status wordt de status "draft"
# * Als je dit commando herhaalt, krijg je een nieuwe pagina met dezelfde titel
#   Er wordt dus geen bestaande pagina aangepast
#
wp post create \
               \
	--post_type=page \
	--post_title='test (3)' \
	--post_content="Jantje zag eens pruimen hangen" \
	--post_status="publish"
##############################################################
# Creeer een pagina + get id
##############################################################
#
i2=$( \
	wp post create \
	               \
		--post_type=page \
		--post_title='test (3)' \
		--post_content="Jantje zag eens pruimen hangen" \
		--post_status="publish" \
| sed "s/^Success: Created post //" | sed "s/\.//"	
)

echo "Gevonden: $i2"

Bronnen

wp post delete

Let op: Dit commando verwijdert zowel posts als pages. Dat kan soms verwarring geven.

Voorbeeld:

##############################################################
# Verwijder sample pagina
##############################################################
#
wp post list
wp post delete 1

Output:

+----+--------------+-------------+---------------------+-------------+
| ID | post_title   | post_name   | post_date           | post_status |
+----+--------------+-------------+---------------------+-------------+
| 1  | Hello world! | hello-world | 2017-12-02 11:37:28 | publish     |
+----+--------------+-------------+---------------------+-------------+
Success: Trashed post 1.

Nog een keer, maar nu echt:

##############################################################
# Verwijder sample pagina
##############################################################
#
wp post list --post_type="page"
wp post delete 2

Output:

+----+-------------+-------------+---------------------+-------------+
| ID | post_title  | post_name   | post_date           | post_status |
+----+-------------+-------------+---------------------+-------------+
| 2  | Sample Page | sample-page | 2017-12-02 11:37:28 | publish     |
+----+-------------+-------------+---------------------+-------------+
Success: Trashed post 2.

wp post edit

wp post generate

wp post get

wp post list

Retrieve a list of posts/pages/etc. E.g.:

> wp post list

+----+--------------+-------------+---------------------+-------------+
| ID | post_title   | post_name   | post_date           | post_status |
+----+--------------+-------------+---------------------+-------------+
| 1  | Hello world! | hello-world | 2017-11-26 11:11:28 | publish     |
+----+--------------+-------------+---------------------+-------------+
> wp post list --post_type="page"

+----+---------------+---------------+---------------------+-------------+
| ID | post_title    | post_name     | post_date           | post_status |
+----+---------------+---------------+---------------------+-------------+
| 7  | test (3)      |               | 2017-11-26 12:26:42 | draft       |
| 6  | test (2)      | test-2        | 2017-11-26 12:23:05 | publish     |
| 2  | Sample Page   | sample-page   | 2017-11-26 11:11:28 | publish     |
+----+---------------+---------------+---------------------+-------------+
# Je kunt filteren op post_name, maar niet op post_title
#
> wp post list --post_type=page --name="test-3" --field=ID

8
# Redirect output naar een variable: Gebruik i=$(...)
#
i=$(wp post list --post_type=page --name="test-3" --field=ID)
echo "gevonden id: $i"

Bronnen

wp post meta

wp post term

wp post update

wp theme <subcommando>

Subcommando's:

wp theme activate 	Activate a theme.
wp theme delete 	Delete a theme.
wp theme disable 	Disable a theme on a WordPress multisite install.
wp theme enable 	Enable a theme on a WordPress multisite install.
wp theme get 		Get details about a theme.
wp theme install 	Install a theme.
wp theme is-installed 	Check if the theme is installed.
wp theme list 		Get a list of themes.
wp theme mod 		Manage theme mods.
wp theme path 		Get the path to a theme or to the theme directory.
wp theme search 	Search the WordPress.org theme directory.
wp theme status 	See the status of one or all themes.
wp theme update 	Update one or more themes.

wp theme delete

Bv.

$ wp theme status
4 installed themes:
  I divi            3.0.7
  I twentyfifteen   1.8
  A twentyseventeen 1.3
  I twentysixteen   1.3

Legend: I = Inactive, A = Active

$ wp theme delete divi
Deleted 'divi' theme.
Success: Deleted 1 of 1 themes.

$ wp theme status
3 installed themes:
  I twentyfifteen   1.8
  A twentyseventeen 1.3
  I twentysixteen   1.3

Legend: I = Inactive, A = Active 

wp theme status

Bv.

wp theme status

4 installed themes:
  I divi            3.0.7
  I twentyfifteen   1.8
  A twentyseventeen 1.3
  I twentysixteen   1.3

Legend: I = Inactive, A = Active

wp user <subcommando>

wp user add-cap

wp user add-role

wp user create

wp user delete

wp user generate

wp user get

wp user import-csv

wp user list

wp user list-caps

wp user meta

wp user remove-cap

wp user remove-role

wp user session

wp user set-role

wp user spam

wp user term

wp user unspam

wp user update

Syntaxis:

wp user update <user-id> <argument + waarde>

Admin-wachtwoord aanpassen:

wp user update 1 --user_pass=12345

wp wc <subcommando>

wp wc betreft WooCommerce-commando's deze set commando's wordt meegeïnstalleerd met WooCommerce. Voorbeeld:

$ wp wc
usage: wp wc customer <command>
   or: wp wc customer_download <command>
   or: wp wc order_note <command>
   or: wp wc payment_gateway <command>
   or: wp wc product <command>
   or: wp wc product_attribute <command>
   or: wp wc product_attribute_term <command>
   or: wp wc product_cat <command>
   or: wp wc product_review <command>
   or: wp wc product_shipping_class <command>
   or: wp wc product_tag <command>
   or: wp wc product_variation <command>
   or: wp wc shipping_method <command>
   or: wp wc shipping_zone <command>
   or: wp wc shipping_zone_location <command>
   or: wp wc shipping_zone_method <command>
   or: wp wc shop_coupon <command>
   or: wp wc shop_order <command>
   or: wp wc shop_order_refund <command>
   or: wp wc tax <command>
   or: wp wc tax_class <command>
   or: wp wc tool <command>
   or: wp wc webhook <command>
   or: wp wc webhook_delivery <command>

See 'wp help wc <command>' for more information on a specific command.

wp wc customer <command>

wp wc customer_download <command>

wp wc order_note <command>

wp wc payment_gateway <command>

wp wc product <command>

wp wc product_attribute <command>

wp wc product_attribute_term <command>

wp wc product_cat <command>

wp wc product_review <command>

wp wc product_shipping_class <command>

wp wc product_tag <command>

wp wc product_variation <command>

wp wc shipping_method <command>

wp wc shipping_zone <command>

wp wc shipping_zone_location <command>

wp wc shipping_zone_method <command>

wp wc shop_coupon <command>

wp wc shop_order <command>

wp wc shop_order_refund <command>

wp wc tax <command>

wp wc tax_class <command>

wp wc tool <command>

wp wc webhook <command>

wp wc webhook_delivery <command>

Bronnen