Wp cli-wcbalt
-
Upload
aaron-brazell -
Category
Technology
-
view
236 -
download
0
Transcript of Wp cli-wcbalt
![Page 1: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/1.jpg)
LazyPressDeveloping for WordPress
on the Command Line
![Page 2: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/2.jpg)
Why CLI?
•All Keyboard Commands
•Efficient
•Fast
•Does Not Require the Web Server resources
![Page 3: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/3.jpg)
Installing WP-CLI
> curl http://wp-cli.org/installer.sh | bash
> PATH=$HOME/.composer/bin:$PATH
> source $HOME/.composer/vendor/wp-cli/wp-cli/utils/wp-completion.bash
![Page 4: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/4.jpg)
Using the wp command
•wp core (config|download|install|update)
•wp comment (approve|count|spam|trash)
•wp export
•wp option (add|update|delete|get)
•wp plugin (install|activate|list|update)
•Etc
![Page 5: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/5.jpg)
Extending WP-CLI
•if( defined( ‘WP_CLI’ ) && WP_CLI )
•Extend WP_CLI_Command
•Public methods become commands
•Methods take $args and $assoc_args
![Page 6: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/6.jpg)
Extending WP-CLI
•$args is an array of positional elements
•e.g. wp command Hello World
•$args[0] == ‘Hello’
•$args[1] == ‘World’
![Page 7: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/7.jpg)
Extending WP-CLI
•$assoc_args is an array of flags
•e.g. wp command --foo=Hello --bar=World
•$assoc_args[‘foo’] == ‘Hello’
•$assoc_args[‘bar’] == ‘World’
![Page 8: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/8.jpg)
Declaring Syntax
•Methods should have a Docblock using @synopsis
•Square brackets designate optional
•@synopsis cmd <foo> --bar=<bar> [--baz=<baz>]
![Page 9: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/9.jpg)
Printing to the CLI
•Use the line() method from the WP_CLI class
•WP_CLI::line(‘Hello World is a Success!’);
![Page 10: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/10.jpg)
Defining the Command
•Use the add_command() method from the WP_CLI class
•Argument 1 is the command name
•Argument 2 is the Class name
•WP_CLI::add_command( ‘hello’, ‘world’);
•Running wp hello instantiates the world class
![Page 11: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/11.jpg)
Resources
•WP-CLI - http://wp-cli.org
•WP-CLI on Github - http://github.com/wp-cli
•Sample Code - https://github.com/technosailor/baltimorephp-wpcli
•BreweryDB - http://brewerydb.com
![Page 12: Wp cli-wcbalt](https://reader035.fdocuments.us/reader035/viewer/2022062513/554f5101b4c905b9508b4da1/html5/thumbnails/12.jpg)
Credits•“Boh” photo by Sidewalk Flying on
Flickr
•“Crab” and “Aquarium” photos by WallyG on Flickr
•“Oriole Bird” photo by Keith Allison on Flickr
•All photos used under the Creative Commons License