Introducing Dictator

Dictator controls the State of WordPress, and is now available for you to use.

Strongly influenced by Salt provisioning and installable as a WP-CLI package, Dictator now allows you to:

  • Export WordPress’ configuration to a human-readable YAML state file.
  • Commit the state file to version control to share between environments, or with another developer.
  • Compare the state of WordPress to the declared state file, with a colorized diff.
  • Impose a state file onto WordPress.

Dictator understands WordPress in terms of states. States are collections of regions. Each state file has the state declaration along with tracked configuration details for each region. Regions have a defined schema which produces the translation between the human-readable YAML file and how WordPress stores state in the database.

One key idea Dictator adopted from provisioning systems: environments are ephemeral. WordPress no longer doing what you want it to? You should be able to destroy it and provision a brand new version.

For 0.1, Dictator packages two states: network and site. The network state comprises regions for network settings, users, and sites. The site state comprises regions for site settings, users, and terms. Management of widgets, roles, and more is just waiting for a pull request.

2014-03-31 at 8.15 PM

Think downloading the entirety of a production database is a messy way to get just a few configuration details? Me too — and with Dictator I can provision full WordPress environments without the bad assumptions that come with using production data.

Ever had a site launch that required a frantic amount of widget configuration right after changing DNS? More than I can remember — and I’m automating myself out of the problem.

Think non-posts data portability would be neat? So do I — and I built a tool for it that I’m very excited to share with you: Dictator. Try it out with wp dictator export site site-state.yml

Add post formats to categorized posts

This here site predates post formats in core, so many of my older posts are categorized with a post format but missing an actual post format. Now that I’ve switched to the lovely TwentyThirteen, I decided to fix things up.

Here’s the bit of PHP I wrote:

[sourcecode language=”php”]
global $wpdb;
$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type=’post’ AND post_status=’publish’;" );

$category_to_format = array(
‘asides’ => ‘aside’,
‘galleries’ => ‘gallery’,
‘photos’ => ‘photo’,
‘quotes’ => ‘quote’,
‘statuses’ => ‘status’,
‘videos’ => ‘video’
);

foreach( $post_ids as $post_id ) {
$category = array_shift( get_the_terms( $post_id, ‘category’ ) );
if ( ! get_post_format( $post_id ) && array_key_exists( $category->slug, $category_to_format ) ) {
set_post_format( $post_id, $category_to_format[$category->slug] );
echo "Changed {$post_id} to {$category_to_format[$category->slug]}n";
}
}
[/sourcecode]

wp-cli offers a quick and dirty way to execute the PHP without even creating a file:

[sourcecode language=”bash”]
wp> global $wpdb;
wp> $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type=’publish’ AND post_status=’publish’;" );
wp> $category_to_format = array( ‘asides’ => ‘aside’,’galleries’ => ‘gallery’,’photos’ => ‘photo’,’quotes’ => ‘quote’,’statuses’ => ‘status’,’videos’ => ‘video’ );
wp> foreach( $post_ids as $post_id ) { $category = array_shift( get_the_terms( $post_id, ‘category’ ) ); if ( ! get_post_format( $post_id ) && array_key_exists( $category->slug, $category_to_format ) ) { set_post_format( $post_id, $category_to_format[$category->slug] ); echo "Changed {$post_id} to {$category_to_format[$category->slug]}n"; } }
[/sourcecode]

Et, voila! Because I haven’t used categories for anything more than post formats, I’m also hiding them from the admin and automagically setting based on post format.

Ten points to whomever adds multiline input to wp shell.

#pdxwp: wp-cli is for WP devs on a deadline

As a part of tonight’s “It’s Tool Time: 4 Tools You Cannot Live Without” meetup, I presented on my beloved wp-cli. wp-cli is a command line interface for WordPress, and a tremendously powerful tool for WordPress developers on a deadline. So powerful, in fact, I wrote my slides as a command 15 minutes before my talk.

Continue reading “#pdxwp: wp-cli is for WP devs on a deadline”

#wcsea: WordPress at the Command Line

Today, I’ve been invited to give a talk at WordCamp Seattle titled “WordPress at the Command Line: An Introduction to wpshell and wp-cli”.

It’s exactly this — an introduction, because I hope to inspire further exploration of interacting with WordPress through the command line. Similar to Scribu, I’ve found “the keyboard is faster than the mouse” for many tasks, and that developing proficiency with the command line has dramatically increased my effectiveness as a programmer.

So, I hope you take the time to check out wpshell and wp-cli (and ack, for that matter). Think critically about how they can improve your workflow, and let me know what you script up!