WP-CLI

administration
in the shell

Gregor Grešak / @gresakg

Slideshow url: skrci.me/wpclie

med.over.net

med.over.net

avto.over.net

avto.over.net

styling.over.net

styling.over.net

Zavod.over.net

zavod.over.net

brezalkohola.si

brezalkohola.si

Dan Sonca

dan-sonca.si

... and many others ...

WordPress 4.0.1

Yessss!!!!

(upgraded yet?)

Hurrraaaa!!

(sigh) ... 30+ wordpess instalations to upgrade ...

Depressed In Paris....

Possible solution: Wordpress Multisite?

Nooo ... !!!

  • painfull migration
  • user management problems
  • bugs no one seems to cate about
  • one big database
  • ...
suicide gun

Wordpress Multisite is a problem not a solution!

Autoupdate?

Do you trust?

Technically, a random user makes the upgrade.

stupid rental car keys.. they give you TWO, but the keychain doesn't come apart, so, um, what's the point?

Note: Autoupdate is still better than no-update!

WP-CLI

Finally :)

champagne
  • Upgrades from 2 days to 2 hours
  • No more logging in
  • Technically no need for superadmin
  • Real chronjobs!

But ...

You need shell access ...

lizzie@aragorn:~$

Installation

Easy: just copy-paste from http://wp-cli.org


curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

php wp-cli.phar --info

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Admin rights needed for the last step.

To be done once for one server.

So, how do I upgrade


cd /path/to/wordpress

wp core update
wp core update-db

Less than a minute (depends on download time).

Downloaded file is cached, so all other sites are upgraded even faster.

How about plugins and themes?


wp plugin update --all

wp theme update --all

Here the downloaded files are also cached.

Is that all?

No,it's just a beginning.

Everything is possible. Example: new wordpress installation:


wp core download
wp core config --dbname=wp --dbuser=mojuser --dbpass=supergeslo123 --locale=sl_SI
wp core install --url=example.com --title="Moj 382ti blog" --admin_user=janez --admin_password=supergeslo [email protected]

Wordpress is ready! You can start writing!

Moj 382ti blog

Install a new theme or plugin


wp plugin install wordfence
wp plugin activate wordfence
wp theme install suevafree
wp theme activate suevafree

# list of all installed plugins (works for themes too)

wp plugin list
+-----------+----------+-----------+---------+
| name      | status   | update    | version |
+-----------+----------+-----------+---------+
| akismet   | inactive | available | 3.0.2   |
| hello     | inactive | none      | 1.6     |
| wordfence | active   | none      | 5.3.3   |
+-----------+----------+-----------+---------+

Beware! New theme installation is so cool, this can happen:

Themes 39

User management


wp user create test [email protected] --role=editor --send-email

Success: Created user 2.
Password: LEAOY4OqouQ@

# user list

wp user list
+----+------------+--------------+-------------------+---------------------+---------------+
| ID | user_login | display_name | user_email        | user_registered     | roles         |
+----+------------+--------------+-------------------+---------------------+---------------+
| 1  | janez      | janez        | [email protected] | 2014-11-22 11:17:22 | administrator |
| 2  | test       | test         | [email protected]  | 2014-11-22 12:01:29 | editor        |
+----+------------+--------------+-------------------+---------------------+---------------+

Swiss Army Knife

Almost anything is possible

Very handy for operations that tend to time out.

  • Import/Export
  • Search/Replace, in database, that takes into account serialized arrays!
  • Thums regeneration, media files import!
  • Categories, posts, comments, navigation management ...
  • ... and ... developper candy ...
Xbox game controller, black

WP console

A php console with Wordpress preloaded!


wp shell
wp> wp_title();
Moj 382ti blogNULL
wp> get_the_title(1);
string(12) "Hello world!"
wp> $post = get_post(1);
wp> setup_postdata($post);
wp> get_excerpt();
string(54) "Welcome to WordPress. This is your first post. Edit or"

In short

Still repetitive but faster and less painfull.

Great start for writting shell scripts, and make ite even better.

Like EasyEngine. If you liked WP-CLI you will love EasyEngine.

https://rtcamp.com/easyengine/

Thanks!

@gresakg

gresak.net

Github/gresakg

Contact me for managed wordpress hosting or hire me!



Slideshow URL: skrci.me/wpclie