mirror of
https://ghproxy.net/https://github.com/0aveRyan/learn-wp-cli.git
synced 2025-08-17 19:01:25 +08:00
updates
This commit is contained in:
parent
574282593f
commit
2898237fe1
4 changed files with 26 additions and 12 deletions
|
@ -18,6 +18,9 @@ This guide is meant for Linux/Unix based systems (which includes MacOS, ChromeOS
|
|||
|
||||
If you're a Windows user, this guide is likely still useful to you! Often when you're running WP-CLI, you'll be remotely-connected to an internet server or local, virtual server on your Windows machine that's running one of these Unix-like operating systems. Windows 10 also offers a system called Bash on Ubuntu on Windows (yes, a mouthful) which lets you use native Linux commands on your Windows machine.
|
||||
|
||||
### Why Learn The Command Line
|
||||
* More flexibility
|
||||
|
||||
### Under The Hood: `STDIN`, `STDOUT` & `STDERR`
|
||||
|
||||
Most modern programming languages like PHP, JavaScript and Python can be used to create a CLI application -- just as these languages can be used to generate HTML documents for a web browser.
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
> Any sufficiently advanced technology is indistinguishable from magic. - Arthur C. Clarke
|
||||
|
||||
For a long time, I used WP-CLI and thought "the core commands are _so powerful_, they must be _so challenging_ to create."
|
||||
For a long time, I used WP-CLI and thought "the core commands are _so powerful_, they must be _so challenging_ to create.
|
||||
|
||||
In reality, working on WP-CLI commands is more like creating a basic electrical circuit than a rocket engine. Which isn't to say it's always "quick" or "easy," but if you think it's magic you may be surprised... and it could very well be quicker and easier than you expect.
|
||||
In reality, working on WP-CLI commands is more like creating an electrical circuit than a rocket engine. Which isn't to say it's always "quick" or "easy," but if you think it's magic you may be surprised... and it could very well be quicker and easier than you expect.
|
||||
|
||||
That said, even with the knowledge that building commands isn't rocket science, it's easy to psyche yourself out: _I don't have a genius idea for a custom command to change the world or even my workflow..._
|
||||
However, even with the knowledge that building commands isn't rocket science, it's easy to psyche yourself out: _I don't have a genius idea for a custom command to change the world, my products or even my workflow..._
|
||||
|
||||
### Some benefits of creating Custom WP-CLI Commands:
|
||||
* A set of tools accessible from anywhere and easily shared with others.
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# Using WP-CLI's Internal API & Utility Functions
|
||||
|
||||
## Introduction
|
||||
|
||||
WP-CLI isn't just a robust tool, it has robust and reusable internal utilities that greatly expedite building WP-CLI commands just as powerful as the Core commands.
|
||||
|
||||
The official documentation is fantastic and extensive, but if it has one shortcoming it's that it's organized alphabetically and similar tools aren't grouped together.
|
||||
The official documentation is fantastic and extensive, but if it has one shortcoming it's that it's organized alphabetically instead of assigning a hiearchy of importance or grouping like items.
|
||||
|
||||
This chapter aims to surface some of the most commonly-used functions and utilities.
|
||||
|
||||
## Introduction
|
||||
|
||||
## Key API Functions
|
||||
|
||||
### `WP_CLI::log()` and `WP_CLI::line()`
|
||||
|
@ -94,10 +94,25 @@ _Work-in-progress..._
|
|||
|
||||
### `WP_CLI\Utils\format_items()`
|
||||
|
||||
_Work-in-progress..._
|
||||
This method is incredibly useful for outputting data in a variety of formats, including a CLI table, CSV, YAML and JSON.
|
||||
|
||||
### `WP_CLI\Utils\get_flag_value()`
|
||||
|
||||
Instead of accessing `$assoc_args` directly, use this method because flags can be negated with `--no-queit` or `--quiet`.
|
||||
|
||||
```php
|
||||
// bad
|
||||
function( $args, $assoc_args ) {
|
||||
$value = ! empty( $assoc_args['my-flag'] ) ? $assoc_args['my-value'] : 'default-value';
|
||||
}
|
||||
// good
|
||||
function( $args, $assoc_args ) {
|
||||
$value = WP_CLI\Utils\get_flag_value( $assoc_args, 'my-value', 'default-value' );
|
||||
}
|
||||
```
|
||||
|
||||
### `WP_CLI\Utils\trailingslashit()`
|
||||
|
||||
_Work-in-progress..._
|
||||
|
||||
### `WP_CLI\Utils\get_temp_dir()`
|
||||
|
@ -108,10 +123,6 @@ _Work-in-progress..._
|
|||
|
||||
_Work-in-progress..._
|
||||
|
||||
### `WP_CLI\Utils\trailingslashit()`
|
||||
|
||||
_Work-in-progress..._
|
||||
|
||||
### `WP_CLI\Utils\report_batch_operation_results()`
|
||||
|
||||
_Work-in-progress..._
|
||||
|
|
|
@ -10,7 +10,7 @@ Base commands for building WP-CLI Code Generators.
|
|||
|
||||
### [CLImate](https://climate.thephpleague.com/) - Advanced Formatting, Interactivity and Animation
|
||||
|
||||
WP-CLI comes with particularly useful helper functions and utilities, but I find I often need an abstract class with lots of my own helpers for formatting and interactivity that my custom command classes extend.
|
||||
WP-CLI comes with particularly useful helper functions and utilities, but I find I often need an abstract class with my own helpers for formatting and interactivity that my custom command classes extend.
|
||||
|
||||
Enter [CLImate](https://climate.thephpleague.com/), a terrific PHP package from The League of Extraordinary Packages. CLImate does overlap some functionality provided in WP-CLI helpers and utilties, but it can be used in-lieu or alongside without issue. It also brings more advanced formatting, animation and interactive tools like CLI checkboxes and multiselects that are common in JavaScript-based CLIs.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue