Last active
June 29, 2016 19:09
-
-
Save thaicloud/8c12950f9ab64fb64a18 to your computer and use it in GitHub Desktop.
Create a dummy WP-CLI command, passing 1 parameter
This file contains hidden or 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 | |
/** | |
* | |
* Plugin Name: Demo - MJ WP-CLI Command | |
* Description: Create WP CLI Command | |
* Author: MJ | |
* Version: 1.0 | |
*/ | |
namespace MJ\Migration; | |
/** | |
* Class Migration | |
* @package MJ\Migration | |
*/ | |
class Migration { | |
/** | |
* Registers all the hooks bla bla | |
*/ | |
function __construct() { | |
} | |
/** | |
* @param $param | |
*/ | |
function run_import( $param ) { | |
if ( empty( $param ) ) { | |
$param = 'nothing set'; | |
} | |
\WP_CLI::line( esc_html( "param is $param " ) ); | |
} | |
} | |
/** | |
* Class Example_Command | |
* @package MJ\Migration | |
* | |
* Generate our command object and give it a sub-command 'import' | |
* Usage: wp example-command import --param=bob | |
*/ | |
class Example_Command extends \WP_CLI_Command { | |
/** | |
* @param $args | |
* @param $assoc_args | |
*/ | |
public function import( $args, $assoc_args ) { | |
$demoObject = new Migration(); | |
$demoObject->run_import( $assoc_args['param'] ); | |
\WP_CLI::success( "All done!" ); | |
} | |
} | |
// Make sure WP-CLI exists | |
if ( defined( 'WP_CLI' ) && \WP_CLI ) { | |
// Our new command will be 'example-command' | |
\WP_CLI::add_command( 'example-command', __NAMESPACE__ . '\\Example_Command' ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment