Last active
November 16, 2016 07:53
-
-
Save ScreamingDev/70514f0f2dfe5c8109c13e2b355e832b to your computer and use it in GitHub Desktop.
Deployer: WordPress recipe using wp-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// some might like this as 'deploy:clean', most have 'cleanup' | |
$clean_hook = 'cleanup'; | |
// assume wp cli is in the repo via composer | |
// change this to the path of your wp executable | |
set( 'wpcli_command', 'vendor/bin/wp' ); | |
function deployer_wp_cli( $command ) { | |
$wp_command = get( 'wpcli_command' ); | |
run( 'cd {{deploy_path}}/current && ' . $wp_command . ' ' . $command ); | |
} | |
function deployer_wp_cache_flush() { | |
deployer_wp_cli( 'cache flush' ); | |
} | |
task( 'wp:cache:flush', | |
function () { | |
deployer_wp_cache_flush(); | |
} )->desc( 'Fetch the WordPress database and install it locally.' ); | |
before( $clean_hook, 'wp:cache:flush' ); | |
function deployer_wp_db_fetch() { | |
// dump via wp-cli | |
deployer_wp_cli( 'db dump sync.sql' ); | |
// download the dump | |
download( 'sync.sql', '{{deploy_path}}/current/sync.sql' ); | |
// remove dump from server | |
run( 'rm {{deploy_path}}/current/sync.sql' ); | |
} | |
task( 'wp:db:fetch', | |
function () { | |
deployer_wp_db_fetch(); | |
} )->desc( 'Fetch the WordPress database and install it locally.' ); | |
function deployer_wp_db_pull() { | |
deployer_wp_db_fetch(); | |
runLocally( 'bin/wp db import sync.sql' ); | |
// maybe you like to delete it afterwards ;-) | |
} | |
task( 'wp:db:pull', | |
function () { | |
deployer_wp_db_pull(); | |
} )->desc( 'Fetch remote DB and import it locally.' ); | |
function deployer_wp_transient_delete_all() { | |
deployer_wp_cli( 'transient delete-all' ); | |
} | |
task( 'wp:transient:delete-all', | |
function () { | |
deployer_wp_transient_delete_all(); | |
} )->desc( 'Remove all transients from the site.' ); | |
before( $clean_hook, 'wp:transient:delete-all' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment