Type and run, automate
Jaime Martínez | @jmslbam | #wpm030 | 9 oct 2014
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
And move it to your ~/bin
Full instructions: wp-cli.org
Or
Add ~/.wp-cli/bin/ to your $PATH
Why WP-CLI?
wp core update
wp core update-db
wp db import
wp search-replace http://nu.nl http://nu.dev
wp user update 1 --user_pass=test
wp rewrite flush
wp option set blogname
wp media regenerate
wp transient delete-expired
Output just the new post id.
wp media import ~/Pictures/jaimemartinez.png --post_id=$(wp post create --post_name=wpmeetup --post_title='Profile picture of Jaime' --porcelain)
wp post update $(wp post list --post_type='zombie' --format=ids) --post_status=publish
wp post list --post_type='zombie' --format=ids
wp post update 33 45 68 --post_status=publish
wp media regenerate $(wp post list --post_type=attachment --format=ids --posts_per_page=50)
#!/bin/bash #
for url in $(wp site list --fields=url --format=csv | tail -n +2)
do
wp --url=$url core update-db
done
wp option update page_on_front $( wp post list --post_type=page --posts_per_page=1 --format=ids --s=homepage --procelain)
cat plugins.txt | xargs wp plugin install
advanced-custom-fields
https://github.com/Jeradin/acf-website-field/archive/master.zip
wordpress-seo
wp core multisite-install --url="http://www.hbo.com" --base="http://www.hbo.com" --title="HBO network" --admin_user=gaya --admin_password=wadup --admin_email="yo@dawg.com"
# For each line add a new site within the multisite installation
while read show ;
# Creating multisite {$show}.the-world.com
wp site create --slug=$show --title=$show --email=yo@dawg.com
done < shows.txt
wp plugin deactivate my-broken-plugin --skip-plugins=my-broken-plugin
wp custom-command --skip-plugins
path: wp
require:
- ../wp-cli/dictator/dictator.php
- ../wp-cli/importer/wordpress-importer-wp-cli.php
skip_plugins:
- wp-elasticsearch
url: http://www.hbo.com
user: admin
color: false
disabled_commands:
- db drop
- plugin install
wp config pull active-plugins
wp dictator impose settings.yml
wp wpmdb migrate
wp total-cache flush db
wp acf export
<?php
// Plugin Name: Sweet Plugin
if ( defined('WP_CLI') && WP_CLI ) {
include __DIR__ . '/my-command.php';
}
require:
- ../wp-cli/dictator/dictator.php
- ../bin/importer/wordpress-importer-wp-cli.php
wp post create --help
optional => false,
type => positional,
repeating => true,
name => object-id
/**
* @synopsis --handshake[=<secret>] [--a=<b>]
*/
[--handshake[=<secret>]]
wp post delete 1 3 4 5 66 798
/**
* Description of what the command does
*
* ## OPTIONS
*
* <id>...
* : The first one it the positional variable $args
*
* [--flag]
* : You can descripe what a flag or an associated arguments does right beneath it
*
* [--<field>=<value>]
* : This is an associated argument. So if --posts_per_page=5 is used, you can check for $assoc_args['posts_per_page']
* --yo=<value>
* : So know $assoc_args['yo'] is available
*
* ## EXAMPLES
*
* wp command name-with-underscores --flag --post_type=page --post_title='A future post'
*
* @subcommand name-with-underscore
*/
# The @subcommand give you the option to rename the command in situations like
function name_with_underscores( $arg, $assoc_args ){
}