From 08a91b7570cb245e03e450d5d6629135e18823aa Mon Sep 17 00:00:00 2001 From: Bunty Date: Sat, 12 Nov 2022 23:11:48 +0530 Subject: [PATCH 1/7] Issue #120: Add post perma link in get comand --- src/Post_Command.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Post_Command.php b/src/Post_Command.php index f7b6c803d..6da7c99f0 100644 --- a/src/Post_Command.php +++ b/src/Post_Command.php @@ -437,6 +437,10 @@ public function get( $args, $assoc_args ) { $post_arr = get_object_vars( $post ); unset( $post_arr['filter'] ); + if ( ! isset( $post_arr['url'] ) ) { + $post_arr['url'] = get_permalink( $post->ID ); + } + if ( empty( $assoc_args['fields'] ) ) { $assoc_args['fields'] = array_keys( $post_arr ); } From 523d46509828e93aacb2672703a8f358330102cb Mon Sep 17 00:00:00 2001 From: Bunty Date: Mon, 14 Nov 2022 22:46:21 +0530 Subject: [PATCH 2/7] Issue #120: Behat test for post url --- features/post.feature | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/features/post.feature b/features/post.feature index 489f6af69..e9a626ec7 100644 --- a/features/post.feature +++ b/features/post.feature @@ -432,3 +432,25 @@ Feature: Manage WordPress posts """ 0 """ + + Scenario: Get Post URL + + When I try `composer require --dev "wp-cli/rewrite-command":"^2"` + Then the return code should be 0 + + When I run `wp post create --post_title='Test post' --post_type="test" --porcelain` + Then STDOUT should be a number + And save STDOUT as {CUSTOM_POST_ID} + + When I run `wp post exists {CUSTOM_POST_ID}` + Then STDOUT should be: + """ + Success: Post with ID {CUSTOM_POST_ID} exists. + """ + And the return code should be 0 + + When I run `wp post get {CUSTOM_POST_ID} --field=url` + Then STDOUT should be: + """ + https://example.com/?p={CUSTOM_POST_ID} + """ \ No newline at end of file From a2f06236e107b41ddb354b6823575039d0742631 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 14 Nov 2022 14:24:49 -0800 Subject: [PATCH 3/7] Remove unnecessary `composer require` statement --- features/post.feature | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/features/post.feature b/features/post.feature index e9a626ec7..380186d59 100644 --- a/features/post.feature +++ b/features/post.feature @@ -435,9 +435,6 @@ Feature: Manage WordPress posts Scenario: Get Post URL - When I try `composer require --dev "wp-cli/rewrite-command":"^2"` - Then the return code should be 0 - When I run `wp post create --post_title='Test post' --post_type="test" --porcelain` Then STDOUT should be a number And save STDOUT as {CUSTOM_POST_ID} @@ -453,4 +450,4 @@ Feature: Manage WordPress posts Then STDOUT should be: """ https://example.com/?p={CUSTOM_POST_ID} - """ \ No newline at end of file + """ From c3ec677276936be25ca5d31cb0200dad55f1f3f0 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 14 Nov 2022 14:25:21 -0800 Subject: [PATCH 4/7] Better scenario title --- features/post.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/post.feature b/features/post.feature index 380186d59..52a3b1366 100644 --- a/features/post.feature +++ b/features/post.feature @@ -433,7 +433,7 @@ Feature: Manage WordPress posts 0 """ - Scenario: Get Post URL + Scenario: Get the URL of a post When I run `wp post create --post_title='Test post' --post_type="test" --porcelain` Then STDOUT should be a number From a5583d91c875989feaed77e51fe63fd0cdd675b1 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 14 Nov 2022 14:29:17 -0800 Subject: [PATCH 5/7] Better to reuse the existing scenario --- features/post.feature | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/features/post.feature b/features/post.feature index 52a3b1366..4980ec320 100644 --- a/features/post.feature +++ b/features/post.feature @@ -254,6 +254,12 @@ Feature: Manage WordPress posts https://example.com/?p={POST_ID} """ + When I run `wp post get 1 --field=url` + Then STDOUT should be: + """ + https://example.com/?p=1 + """ + Scenario: Update a post from file or STDIN Given a content.html file: """ @@ -432,22 +438,3 @@ Feature: Manage WordPress posts """ 0 """ - - Scenario: Get the URL of a post - - When I run `wp post create --post_title='Test post' --post_type="test" --porcelain` - Then STDOUT should be a number - And save STDOUT as {CUSTOM_POST_ID} - - When I run `wp post exists {CUSTOM_POST_ID}` - Then STDOUT should be: - """ - Success: Post with ID {CUSTOM_POST_ID} exists. - """ - And the return code should be 0 - - When I run `wp post get {CUSTOM_POST_ID} --field=url` - Then STDOUT should be: - """ - https://example.com/?p={CUSTOM_POST_ID} - """ From 718fc319d712a2f9332cbaa5f075c880d8a478aa Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 14 Nov 2022 14:32:16 -0800 Subject: [PATCH 6/7] Add `url` support for terms --- features/term.feature | 6 ++++++ src/Term_Command.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/features/term.feature b/features/term.feature index a4e764afc..7a9675710 100644 --- a/features/term.feature +++ b/features/term.feature @@ -148,6 +148,12 @@ Feature: Manage WordPress terms https://example.com/?cat=2 """ + When I run `wp term get category 1 --field=url` + Then STDOUT should be: + """ + https://example.com/?cat=1 + """ + Scenario: Make sure WordPress receives the slashed data it expects When I run `wp term create category 'My\Term' --description='My\Term\Description' --porcelain` Then save STDOUT as {TERM_ID} diff --git a/src/Term_Command.php b/src/Term_Command.php index 2fc5c04a5..8769801aa 100644 --- a/src/Term_Command.php +++ b/src/Term_Command.php @@ -291,6 +291,10 @@ public function get( $args, $assoc_args ) { WP_CLI::error( "Term doesn't exist." ); } + if ( ! isset( $term->url ) ) { + $term->url = get_term_link( $term ); + } + if ( empty( $assoc_args['fields'] ) ) { $term_array = get_object_vars( $term ); $assoc_args['fields'] = array_keys( $term_array ); From bc9e16a17a3c3a4449ddf7897248b0fd35aafbe9 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 14 Nov 2022 14:36:33 -0800 Subject: [PATCH 7/7] Add support for `--field=url` to `wp comment get` --- features/comment.feature | 6 ++++++ src/Comment_Command.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/features/comment.feature b/features/comment.feature index 4d3330f5f..02b7b4e7e 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -105,6 +105,12 @@ Feature: Manage WordPress comments #comment-1 """ + When I run `wp comment get 1 --field=url` + Then STDOUT should contain: + """ + #comment-1 + """ + Scenario: List the URLs of comments When I run `wp comment create --comment_post_ID=1 --porcelain` Then save STDOUT as {COMMENT_ID} diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 841cfa8e8..ff021730a 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -241,6 +241,10 @@ public function get( $args, $assoc_args ) { WP_CLI::error( 'Invalid comment ID.' ); } + if ( ! isset( $comment->url ) ) { + $comment->url = get_comment_link( $comment ); + } + if ( empty( $assoc_args['fields'] ) ) { $comment_array = get_object_vars( $comment ); $assoc_args['fields'] = array_keys( $comment_array );