Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created April 13, 2016 10:54
Show Gist options
  • Select an option

  • Save danielbachhuber/cc8be5468d4a28a477f6d59620aeb405 to your computer and use it in GitHub Desktop.

Select an option

Save danielbachhuber/cc8be5468d4a28a477f6d59620aeb405 to your computer and use it in GitHub Desktop.
Example for how you might install a plugin after a theme is activated
<?php
/**
* Run with wp --require=install-required-plugins.php theme activate p2
*/
WP_CLI::add_hook( 'after_wp_load', function() {
add_action( 'switch_theme', function( $_, $theme ){
if ( 'p2' !== $theme->get_stylesheet() ) {
return;
}
$ret = WP_CLI::launch_self( 'plugin install', array( 'jetpack' ), array( 'activate' => true ), false, true );
WP_CLI::log( $ret->stdout );
}, 10, 2 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment