PHP code example of underpin / wp-cli-loader

1. Go to this page and download the library: Download underpin/wp-cli-loader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

underpin / wp-cli-loader example snippets


\Underpin\underpin()->cli()->add( 'test', [
	'command'             => 'test',                           // Command name.
	'name'                => 'Test Command',                   // Human-readable name. Used by Underpin logging tools.
	'description'         => 'Runs a test command in the CLI', // Human-readable description. Used by Underpin logging tools.
	'action_callback'     => function ( $args ) {              // The command to run when this command is invoked in the CLI
		\WP_CLI::success( "The script has run, $args[0]!" );
	},
	'command_description' => [                                 // Optional. The description of the command. See WP CLI cookbook.
		'shortdesc' => 'Prints a test message.',
		'synopsis'  => [
			[
				'type'        => 'positional',
				'name'        => 'name',
				'description' => 'The name of the person to greet.',
				'optional'    => false,
				'repeating'   => false,
			],
		],
		'longdesc'  => '## EXAMPLES' . "\n\n" . 'Success: The script has run, Alex!',
	],
] );

class Say_Hello extends Underpin_Commands\Abstracts\Command{

	protected $command = 'say';
	/**
	 * 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!" );
	}

}

\Underpin\underpin()->cli()->add('say','Say_Hello');