WP-CLI (original) (raw)

A new release of WP-CLI WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is http://wp-cli.org/ https://make.wordpress.org/cli/, WP-CLI v2.12.0, is now available. For this release, we had 68 contributors collaborate to get 382 pull requests merged.

As always, big thanks to the WP-CLI sponsors that make the continued maintenance possible.

This release includes numerous bug fixes and compatibility improvements, but we still could teach WP-CLI a few new tricks which I’ll highlight below. As always, you can also skip directly to the detailed changelog if you prefer.

If you already use WP-CLI, updating is as simple as wp cli update. Else, check out our website for recommended installation methods.

Pluck & patch commands for caches and transients

The cache and transient commands have now also learned the subtle art of plucking and patching. This means that you can directly manipulate individual entries in an array of values that these commands let you manage.

Here’s an example of how such an operation can look and how it compare to the regular cache/transient operations:

# Transient structure
# 'some_key' => ['foo' => ['bar' => 'baz']]

# Retrieve the transient value
$ wp transient get some_key --format=json
{'foo':{'bar':'baz'}}

# Retrieve the value of the foo => bar subkey
$ wp transient pluck some_key foo bar
baz

# Replace baz with bazzer
$ wp transient patch update some_key foo bar bazzer
Success: Updated transient 'some_key'.

Post lists can now handle complex query flags

When using post list, you can now use JSON JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. notation to provide complex query arguments to the --tax_query, --meta_query and --post_date fields.

$ wp post list --field=post_title --date_query='{"before":{"year":"2024"}}
+--------------------------+
| post_title               |
+--------------------------+
| My year in review - 2021 |
| My year in review - 2022 |
| My year in review - 2023 |
+--------------------------+

$ wp post list --field=post_title --tax_query='[{"taxonomy":"category","field":"slug","terms":"first-category"}]'
...

$ wp post list --field=post_title --meta_query='[{"key":"key2","value":"value2b"}]'
...

Post meta Meta is a term that refers to the inside workings of a group. For us, this is the team that works on internal WordPress sites like WordCamp Central and Make WordPress. can be forced to only return a single value

The post meta get command now has a --single flag defaulting to true which can be negated with --no-single. This flag tells WordPress whether to only return a single value or all existing values for a given key.

# Create a post meta key for post with ID 123 that has multiple values
$ wp post meta add 123 my_meta_key value_1
$ wp post meta add 123 my_meta_key value_2
$ wp post meta add 123 my_meta_key value_4

# Retrieve a single value
$ wp post meta get 123 my_meta_key --single
value_1

# Retrieve all values
$ wp post meta get 123 my_meta_key --no-single --format=json
["value_1","value_2","value_3"]

Exclude files on core checksum verification

When running a core checksum verification, you can exclude one or more files from the checksum verification with the new --exclude=<files> flag, which takes a comma-separated list of filepaths relative to the current root.

# Make a change to the README file in the WordPress core root folder
$ echo "nonsense" > readme.html

# Run the core checksum verification
$ wp core verify-checksums --exclude='readme.html'
Success: WordPress installation verifies against checksums.

Respect requires and requires_php tags for plugins and themes

The plugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party and theme commands now understand and respect the requires and requires_php header The header of your site is typically the first thing people will experience. The masthead or header art located across the top of your page is part of the look and feel of your website. It can influence a visitor’s opinion about your content and you/ your organization’s brand. It may also look different on different screen sizes. tags when trying ot install or update extensions. A new state unavailable has been introduced to denote the updates that are newer that your current installation but for which your site does not fulfill the requirements.

This also adds new fields requires and requires_php which are displayed if they contain relevant information and otherwise hidden by default.

$ wp plugin list
+----------------+----------+-------------+---------+----------------+-------------+----------+--------------+
| name           | status   | update      | version | update_version | auto_update | requires | requires_php |
+----------------+----------+-------------+---------+----------------+-------------+----------+--------------+
| akismet        | inactive | available   | 5.1     | 5.3.5          | off         | 5.8      | 5.6.20       |
| edit-flow      | inactive | none        | 0.9.9   |                | off         | 6.0      | 8.0          |
| wp-super-cache | inactive | unavailable | 1.9.4   | 1.12.4         | off         | 6.5      | 7.0          |
+----------------+----------+-------------+---------+----------------+-------------+----------+--------------+

$ wp plugin update wp-super-cache
Warning: wp-super-cache: This update requires WordPress version 6.5, but the version installed is 6.2.
Error: No plugins updated.

More control over make-json generation

The make-json command was made more powerful again. You can not only set a custom text domain to be used, you can also define the file extension to parse.

# Use a custom text domain
$ wp i18n make-json foo-theme --domain=my-custom-domain
Success: Created 1 file.

# Include typescript files
$ wp i18n make-json foo-theme --extensions=".ts, .tsx"
Success: Created 2 files.

Force update checks on plugin|theme list

When displaying the list of plugins or themes, WP-CLI now always ensures you get fresh data. No need to manually clear transients anymore! The existing --skip-update-check flag can be used to prevent this behavior.

# Clears any update transients to trigger an update check and display results
$ wp plugin list --fields=name,status,update --force-check
+-------------+----------+--------+
| name        | status   | update |
+-------------+----------+--------+
| hello-dolly | inactive | none   |
+-------------+----------+--------+

PHP PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. https://www.php.net/manual/en/preface.php. 8.4 Compatiblity

WP-CLI is now fully compatible with PHP 8.4. This has required quite a bit of trickery and hacks to maintain compatibility with our current minimum of PHP 5.6+ at the same time. With the next release, we’ll bump the minimum PHP version to 7.2.24+, which will allow us to get rid of all these workarounds again.

Detailed Change Log

wp-cli/wp-cli-bundle

wp-cli/wp-cli

wp-cli/handbook

wp-cli/cache-command

wp-cli/checksum-command

wp-cli/config-command

wp-cli/core-command

wp-cli/cron-command

wp-cli/db-command

wp-cli/entity-command

wp-cli/export-command

wp-cli/extension-command

wp-cli/i18n-command

wp-cli/language-command

wp-cli/php-cli-tools

wp-cli/rewrite-command

wp-cli/scaffold-command

wp-cli/shell-command

wp-cli/wp-config-transformer

Contributors

@9ete, @amirhmoradi, @baizmandesign, @benjaminprojas, @BhargavBhandari90, @cliffordp, @daalderp, @dac514, @danielbachhuber, @dd32, @dkoston, @dlind1, @drzraf, @elenachavdarova, @ernilambar, @gedex, @gitlost, @greatislander, @herregroen, @i-am-chitti, @iDschepe, @imrraaj, @itsmekopila, @janw-me, @jenkoian, @jkrrv, @jrfnl, @karthick-murugan, @l3ku, @localheinz, @marksabbath, @matiasbenedetto, @matzeeable, @meszarosrob, @michaelw85, @michaelzangl, @mostafasoufi, @mrsdizzie, @oandregal, @ocean90, @ouikhuan, @PARTHVATALIYA, @pbiron, @peterwilsoncc, @petitphp, @pfefferle, @pmbaldha, @ponsfrilus, @pwtyler, @ramonjd, @rodrigoprimo, @Roy-Orbison, @saas786, @sabithahmd, @sdnunca, @shendy-a8c, @shreya0204, @siliconforks, @strarsis, @swissspidy, @todeveni, @Tug, @tyrann0us, @wojsmol, @wpeople-dev, @WPprodigy, @yousan

#release, #v2-12-0