WP-CLI 101 Function with Arguments
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
/** | |
* Returns all arguments passed into command to demonstrate how to access them. | |
* | |
* @param Array $args Arguments in array format. | |
* @param Array $assoc_args Key value arguments stored in associated array format. | |
* @since 1.0.0 | |
* @author Scott Anderson | |
*/ | |
public function display_arguments( $args, $assoc_args ) { | |
// Run command wp wds display_arguments John Doe 'Jane Doe' 32 --title='Moby Dick' --author='Herman Melville' --published=1851 --publish --no-archive | |
// Examples of Arguments. | |
WP_CLI::line( var_export($args[0]) ); // John | |
WP_CLI::line( var_export($args[1]) ); // Doe | |
WP_CLI::line( var_export($args[2]) ); // Jane Doe | |
WP_CLI::line( var_export($args[3]) ); // 32 | |
// Example of Associated Arguments | |
WP_CLI::line( var_export($assoc_args['title']) ); // Moby Dick | |
WP_CLI::line( var_export($assoc_args['author']) ); // Herman Melville | |
WP_CLI::line( var_export($assoc_args['published']) ); // 1851 | |
// Example of Associated Arguments as flag | |
WP_CLI::line( var_export($assoc_args['publish']) ); // True | |
WP_CLI::line( var_export($assoc_args['archive']) ); // False | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment