Commit 4b42e580 authored by Peter J. Herrel's avatar Peter J. Herrel Committed by GitHub
Browse files

Merge pull request #103 from diggy/wp-pll-term-list

add `wp pll term list` subcommand
parents a2deb30e 11915a1f
......@@ -1345,32 +1345,27 @@ wp pll term
### wp pll term generate
### wp pll term get
Generate some taxonomy terms and their translations.
Get details about a translated term.
~~~
wp pll term generate <taxonomy> [--count=<number>] [--max_depth=<number>] [--format=<format>]
wp pll term get <taxonomy> <term-id> [--field=<field>] [--fields=<fields>] [--format=<format>] [--api]
~~~
Creates a specified number of sets of new terms and their translations with dummy data.
**OPTIONS**
<taxonomy>
The taxonomy for the generated terms.
Taxonomy of the term to get
[--count=<number>]
How many sets of terms to generate?
---
default: 5
---
<term-id>
ID of the term to get
[--max_depth=<number>]
Generate child terms down to a certain depth.
---
default: 1
---
[--field=<field>]
Instead of returning the whole term, returns the value of a single field.
[--fields=<fields>]
Limit the output to specific fields. Defaults to all fields.
[--format=<format>]
Render output in a particular format.
......@@ -1381,38 +1376,71 @@ Creates a specified number of sets of new terms and their translations with dumm
- csv
- json
- yaml
- ids
---
[--api]
Use the Polylang API function pll_get_term_translations()
**EXAMPLES**
# Generate some post categories, and translations.
$ wp pll term generate category --count=3 --format=ids
115 116 117 118 119 120
# Get details about a category with term ID 18.
$ wp pll term get category 18
### wp pll term get
### wp pll term delete
Get details about a translated term.
Delete an existing taxonomy term and its translations.
~~~
wp pll term get <taxonomy> <term-id> [--field=<field>] [--fields=<fields>] [--format=<format>] [--api]
wp pll term delete <taxonomy> <term-id>...
~~~
Errors if the term doesn't exist, or there was a problem in deleting it.
**OPTIONS**
<taxonomy>
Taxonomy of the term to get
Taxonomy of the term to delete.
<term-id>
ID of the term to get
<term-id>...
One or more IDs of terms to delete.
**EXAMPLES**
# Delete a term (English) and its translations (Spanish, French)
$ wp pll term delete post_tag 56
Deleted post_tag 56.
Deleted post_tag 57.
Deleted post_tag 58.
Success: Deleted 3 of 3 terms.
### wp pll term list
Get a list of taxonomy terms for a language.
~~~
wp pll term list <taxonomy> <language-code> [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
~~~
**OPTIONS**
<taxonomy>
List terms of one or more taxonomies. Required.
<language-code>
The language code (slug) to get the taxonomy terms for. Required.
[--<field>=<value>]
Filter by one or more fields (see get_terms() $args parameter for a list of fields).
[--field=<field>]
Instead of returning the whole term, returns the value of a single field.
Prints the value of a single field for each term.
[--fields=<fields>]
Limit the output to specific fields. Defaults to all fields.
Limit the output to specific object fields.
[--format=<format>]
Render output in a particular format.
......@@ -1421,46 +1449,91 @@ wp pll term get <taxonomy> <term-id> [--field=<field>] [--fields=<fields>] [--fo
options:
- table
- csv
- ids
- json
- count
- yaml
---
[--api]
Use the Polylang API function pll_get_term_translations()
**AVAILABLE FIELDS**
These fields will be displayed by default for each term:
* term_id
* term_taxonomy_id
* name
* slug
* description
* parent
* count
These fields are optionally available:
* url
**EXAMPLES**
# Get details about a category with term ID 18.
$ wp pll term get category 18
# List post categories
$ wp pll term list color nl --format=csv
term_id,term_taxonomy_id,name,slug,description,parent,count
2,2,Rood,rood,,0,1
3,3,Blauw,blauw,,0,1
# List post tags
$ wp pll term list post_tag en --fields=name,slug
+-----------+-------------+
| name | slug |
+-----------+-------------+
| Articles | articles |
| aside | aside |
+-----------+-------------+
### wp pll term delete
Delete an existing taxonomy term and its translations.
### wp pll term generate
Generate some taxonomy terms and their translations.
~~~
wp pll term delete <taxonomy> <term-id>...
wp pll term generate <taxonomy> [--count=<number>] [--max_depth=<number>] [--format=<format>]
~~~
Errors if the term doesn't exist, or there was a problem in deleting it.
Creates a specified number of sets of new terms and their translations with dummy data.
**OPTIONS**
<taxonomy>
Taxonomy of the term to delete.
The taxonomy for the generated terms.
<term-id>...
One or more IDs of terms to delete.
[--count=<number>]
How many sets of terms to generate?
---
default: 5
---
[--max_depth=<number>]
Generate child terms down to a certain depth.
---
default: 1
---
[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- yaml
- ids
---
**EXAMPLES**
# Delete a term (English) and its translations (Spanish, French)
$ wp pll term delete post_tag 56
Deleted post_tag 56.
Deleted post_tag 57.
Deleted post_tag 58.
Success: Deleted 3 of 3 terms.
# Generate some post categories, and translations.
$ wp pll term generate category --count=3 --format=ids
115 116 117 118 119 120
## Contributing
......
......@@ -76,9 +76,10 @@
"pll taxonomy enable",
"pll taxonomy list",
"pll term",
"pll term generate",
"pll term get",
"pll term delete"
"pll term delete",
"pll term list",
"pll term generate"
],
"readme": {
"sections": [
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "2f3168050b1633c32fba2601c4f5fd20",
"content-hash": "fbae85af3479e4a030ef3864025b94be",
"packages": [
{
"name": "composer/ca-bundle",
......
......@@ -46,3 +46,23 @@ Feature: Manage WordPress taxonomy terms and their translations.
Success: Deleted 2 of 2 terms.
"""
And the return code should be 0
@pll-term-list
Scenario: List taxonomy terms for a language
When I run `wp pll lang create de de de_DE && wp pll term generate post_tag --count=3 --format=ids`
Then STDOUT should not be empty
When I run `wp pll term list post_tag nl --format=ids`
Then STDOUT should contain:
"""
11 13 9
"""
And the return code should be 0
When I run `wp pll term list post_tag de --format=ids`
Then STDOUT should contain:
"""
12 14 10
"""
And the return code should be 0
......@@ -155,6 +155,86 @@ class TermCommand extends BaseCommand {
);
}
/**
* Get a list of taxonomy terms for a language.
*
* ## OPTIONS
*
* <taxonomy>
* : List terms of one or more taxonomies. Required.
*
* <language-code>
* : The language code (slug) to get the taxonomy terms for. Required.
*
* [--<field>=<value>]
* : Filter by one or more fields (see get_terms() $args parameter for a list of fields).
*
* [--field=<field>]
* : Prints the value of a single field for each term.
*
* [--fields=<fields>]
* : Limit the output to specific object fields.
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - csv
* - ids
* - json
* - count
* - yaml
* ---
*
* ## AVAILABLE FIELDS
*
* These fields will be displayed by default for each term:
*
* * term_id
* * term_taxonomy_id
* * name
* * slug
* * description
* * parent
* * count
*
* These fields are optionally available:
*
* * url
*
* ## EXAMPLES
*
* # List post categories
* $ wp pll term list color nl --format=csv
* term_id,term_taxonomy_id,name,slug,description,parent,count
* 2,2,Rood,rood,,0,1
* 3,3,Blauw,blauw,,0,1
*
* # List post tags
* $ wp pll term list post_tag en --fields=name,slug
* +-----------+-------------+
* | name | slug |
* +-----------+-------------+
* | Articles | articles |
* | aside | aside |
* +-----------+-------------+
*
* @subcommand list
*/
public function list_( $args, $assoc_args )
{
list ( $taxonomy, $language ) = $args;
new \PLL_Frontend_Filters( $this->pll );
$this->cli->command(
array( 'term', 'list', $taxonomy ),
array_merge( array( 'lang' => $language ), $assoc_args )
);
}
/**
* Generate some taxonomy terms and their translations.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment