Skip to content

Instantly share code, notes, and snippets.

@MakarandMane
Created December 4, 2023 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MakarandMane/02b37bfa0ad39a71690a32236e0f5016 to your computer and use it in GitHub Desktop.
Save MakarandMane/02b37bfa0ad39a71690a32236e0f5016 to your computer and use it in GitHub Desktop.
Custom WP-CLI command
<?php
/**
* Implements example command.
*/
class Hello_WPGenius_Command {
/**
* Prints a greeting.
*
* ## OPTIONS
*
* <name>
* : The name of the person to greet.
*
* [--type=<type>]
* : Whether or not to greet the person with success or error.
* ---
* default: success
* options:
* - success
* - error
* ---
*
* ## EXAMPLES
*
* wp example hello Newman
*
* @when after_wp_load
*/
function hello( $args, $assoc_args ) {
list( $name ) = $args;
// Print the message with type
$type = $assoc_args['type'];
WP_CLI::$type( "Hello, $name!" );
}
}
WP_CLI::add_command( 'example', 'Hello_WPGenius_Command' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment