Skip to content

Instantly share code, notes, and snippets.

@Oceas Oceas/wds-hello-world.php
Last active Sep 19, 2019

Embed
What would you like to do?
WP-CLI 101 Function with Arguments
/**
* 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
You can’t perform that action at this time.