Unverified Commit 3cb50cae authored by Peter J. Herrel's avatar Peter J. Herrel
Browse files

add 'wp pll post update' subcommand

closes #100
parent f75be8db
......@@ -951,34 +951,36 @@ wp pll post get <post_id> [<language-code>] [--api]
### wp pll post duplicate
### wp pll post update
Duplicate a post to one or more languages.
Update one or more existing posts and their translations.
~~~
wp pll post duplicate <post_id> [<language-code>]
wp pll post update <id>... [<file>] --<field>=<value> [--defer-term-counting]
~~~
Syncs metadata and taxonomy terms, based on Polylang settings. Run `wp pll option list` to inspect current settings.
**OPTIONS**
<post_id>
Post ID of the post to duplicate. Required.
<id>...
One or more IDs of posts to update.
[<language-code>]
Language code (slug), or comma-separated list of language codes, to duplicate the post to. Omit to duplicate to all languages. Optional.
[<file>]
Read post content from <file>. If this value is present, the
`--post_content` argument will be ignored.
**EXAMPLES**
Passing `-` as the filename will cause post content to
be read from STDIN.
# Duplicate post 23 (Dutch) to German
$ wp pll post duplicate 23 de
Success: Created post 68 (de) < post 23 (nl)
--<field>=<value>
One or more fields to update. See wp_update_post().
# Duplicate post 23 (Dutch) to all languages (Dutch and Spanish)
$ wp pll post duplicate 23
Success: Updated post 68 (de) < post 23 (nl)
Success: Created post 69 (es) < post 23 (nl)
[--defer-term-counting]
Recalculate term count in batch, for a performance boost.
**EXAMPLES**
$ wp pll post update 13 --comment_status=closed
Success: Updated post 13.
......@@ -1007,6 +1009,37 @@ wp pll post delete <post_id> [--force] [--defer-term-counting]
### wp pll post duplicate
Duplicate a post to one or more languages.
~~~
wp pll post duplicate <post_id> [<language-code>]
~~~
Syncs metadata and taxonomy terms, based on Polylang settings. Run `wp pll option list` to inspect current settings.
**OPTIONS**
<post_id>
Post ID of the post to duplicate. Required.
[<language-code>]
Language code (slug), or comma-separated list of language codes, to duplicate the post to. Omit to duplicate to all languages. Optional.
**EXAMPLES**
# Duplicate post 23 (Dutch) to German
$ wp pll post duplicate 23 de
Success: Created post 68 (de) < post 23 (nl)
# Duplicate post 23 (Dutch) to all languages (Dutch and Spanish)
$ wp pll post duplicate 23
Success: Updated post 68 (de) < post 23 (nl)
Success: Created post 69 (es) < post 23 (nl)
### wp pll post list
Get a list of posts in a language.
......
......@@ -61,8 +61,9 @@
"pll post generate",
"pll post create",
"pll post get",
"pll post duplicate",
"pll post update",
"pll post delete",
"pll post duplicate",
"pll post list",
"pll post-type",
"pll post-type disable",
......
......@@ -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": "7b3ab1889747de5d4a03979f524b653f",
"content-hash": "7ccbb9f9bd8cf84d8aaac1997f82ef00",
"packages": [
{
"name": "composer/ca-bundle",
......@@ -2388,16 +2388,16 @@
},
{
"name": "wp-cli/scaffold-command",
"version": "v1.0.6",
"version": "v1.0.7",
"source": {
"type": "git",
"url": "https://github.com/wp-cli/scaffold-command.git",
"reference": "decd72649677fa0f731874fe73f792aa80f09f24"
"reference": "9ed0d96967a84ebe21764aa30b162717bc45c6ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wp-cli/scaffold-command/zipball/decd72649677fa0f731874fe73f792aa80f09f24",
"reference": "decd72649677fa0f731874fe73f792aa80f09f24",
"url": "https://api.github.com/repos/wp-cli/scaffold-command/zipball/9ed0d96967a84ebe21764aa30b162717bc45c6ef",
"reference": "9ed0d96967a84ebe21764aa30b162717bc45c6ef",
"shasum": ""
},
"require-dev": {
......@@ -2442,7 +2442,7 @@
],
"description": "Generate code for post types, taxonomies, plugins, child themes, etc.",
"homepage": "https://github.com/wp-cli/scaffold-command",
"time": "2017-08-22T13:48:33+00:00"
"time": "2017-08-23T13:06:41+00:00"
},
{
"name": "wp-cli/search-replace-command",
......
......@@ -46,6 +46,28 @@ Feature: Manage posts and their translations
Warning: tlh is not a valid language.
"""
@pll-post-update
Scenario: Update posts and their translations
When I run `wp pll option sync comment_status`
And I run `wp pll lang create de de de_DE`
And I run `wp pll post duplicate 1`
And I run `wp pll post update 1 --comment_status="closed"`
And I run `wp post list --fields=ID,comment_status`
Then STDOUT should be a table containing rows:
| ID | comment_status |
| 5 | closed |
| 1 | closed |
And STDERR should be empty
When I run `wp pll post update 5 --comment_status="open"`
And I run `wp post list --fields=ID,comment_status`
Then STDOUT should be a table containing rows:
| ID | comment_status |
| 5 | open |
| 1 | open |
And STDERR should be empty
Scenario: Delete posts and their translations
When I run `wp pll post delete 1`
......
......@@ -161,6 +161,52 @@ class PostCommand extends BaseCommand {
echo implode( ' ', array_map( 'absint', $post_ids ) );
}
/**
* Update one or more existing posts and their translations.
*
* ## OPTIONS
*
* <id>...
* : One or more IDs of posts to update.
*
* [<file>]
* : Read post content from <file>. If this value is present, the
* `--post_content` argument will be ignored.
*
* Passing `-` as the filename will cause post content to
* be read from STDIN.
*
* --<field>=<value>
* : One or more fields to update. See wp_update_post().
*
* [--defer-term-counting]
* : Recalculate term count in batch, for a performance boost.
*
* ## EXAMPLES
*
* $ wp pll post update 13 --comment_status=closed
* Success: Updated post 13.
*/
public function update( $args, $assoc_args ) {
$this->pll->filters_post = new \PLL_Admin_Filters_Post( $this->pll );
$this->pll->sync = new \PLL_Admin_Sync( $this->pll );
$GLOBALS['pagenow'] = 'post.php';
# get around Polylang's capability check
$current_user = wp_get_current_user();
$current_user->allcaps = get_role( 'administrator' )->capabilities;
$_args = implode( ' ', array_merge( array( 'post', 'update' ), $args ) );
$_assoc_args = empty( $assoc_args ) ? '' : implode( ' ', array_map( function ( $v, $k ) { return "--{$k}='{$v}'"; }, $assoc_args, array_keys( $assoc_args ) ) );
$this->cli->runcommand(
sprintf( '%s %s', $_args, $_assoc_args ),
array( 'return' => false, 'launch' => false, 'exit_error' => false )
);
}
/**
* Delete a post and its translations.
*
......@@ -437,7 +483,7 @@ class PostCommand extends BaseCommand {
$this->cli->command( array( 'post', 'list' ), $assoc_args );
}
/**
/**
* Generate some posts and their translations.
*
* Creates a specified number of sets of new posts with dummy data.
......
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