Menu
DocumentationDevelopers / WP-CLI

Developers

WP-CLI

Export and import bundles from the command line with wp eizport export and wp eizport import, keep a delivery in a folder to compare, and run the abilities with wp eval.

wp eizport export

Exports as the Export screen does, to a copy kept on the site, and prints its path. Each run is a process of its own, so a script can make as many exports as it needs.

wp eizport export --types=page:43,product --options=basics,page_on_front
wp eizport export --types=page:43+44 --as-plugin --update-existing --filename=delivery
Argument
--types=<types> Content types, comma-separated: type:ID+ID for some items, the type alone for all of it. None: all content
--options=<options> Option groups (like basics) and option names, comma-separated
--[no-]media Media files inside; default: yes
--zip A .zip bundle instead of .wxrz
--as-plugin A plugin .zip that imports its bundle
--update-existing Ask the import to update the items that already exist
--filename=<name> File name, without extension
--dir=<folder> Also write the bundle’s files to a folder (see below)

A delivery in a folder

--dir writes the bundle’s files to a folder: manifest.json, the WXR formatted line by line, post_content/*.html, uploads/… and options.json. The bundle files a previous export wrote there are replaced; other files (.git, notes) stay. Keep the folder under version control and git diff shows what changed since the last delivery — a title, a price — besides the export’s dates.

wp eizport export --types=page:43,product --filename=delivery --dir=deliveries/site
git -C deliveries diff

The WXR in the folder keeps one name from one delivery to the next — <--filename>.xml, else <site>.WordPress.xml, without the date — so git diff shows what changed in it. The folder imports back with wp eizport import <folder>.

wp eizport import

Imports a .wxrz or .zip bundle, a bundle folder (from --dir), a gzipped WXR (.xml.gz) or a plain .xml with the WordPress Importer — media from the bundle, post_content/ files back in, options set at the end.

wp eizport import site.wxrz --user=admin
Argument
<file> The file or bundle folder to import
--user=<login> Who the posts go to; default: the first administrator
--[no-]update-existing Update the items that already exist (same type and slug) instead of adding copies; default: what the bundle asks

It needs the WordPress Importer plugin installed (it doesn’t have to be active).

Exporting with the ability

wp eizport export runs the eizport/export ability; to pass what it has no flag for (filters, reviews), run the ability itself:

wp eval '
wp_set_current_user( 1 );
$copy = wp_get_ability( "eizport/export" )->execute( array(
	"types"   => array( "page" => array( "ids" => array( 43 ) ) ),
	"options" => array( "groups" => array( "basics" ) ),
) );
echo is_wp_error( $copy ) ? $copy->get_error_message() : $copy["download_url"];
'

The copy is in wp-content/uploads/eizport/tmp/; one export per wp process.

Other abilities

Any ability works the same way: wp_get_ability( 'eizport/get-copies' )->execute(), wp_get_ability( 'eizport/delete-copies' )->execute( array( 'all' => true ) )…