Skip to content

Commit cccd002

Browse files
BhargavBhandari90buntybuddybossdanielbachhuber
authored
Add '--field=url' support for posts, comments, and terms (#383)
Co-authored-by: Bunty <[email protected]> Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent d43bd18 commit cccd002

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

features/comment.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ Feature: Manage WordPress comments
105105
#comment-1
106106
"""
107107

108+
When I run `wp comment get 1 --field=url`
109+
Then STDOUT should contain:
110+
"""
111+
#comment-1
112+
"""
113+
108114
Scenario: List the URLs of comments
109115
When I run `wp comment create --comment_post_ID=1 --porcelain`
110116
Then save STDOUT as {COMMENT_ID}

features/post.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ Feature: Manage WordPress posts
254254
https://example.com/?p={POST_ID}
255255
"""
256256

257+
When I run `wp post get 1 --field=url`
258+
Then STDOUT should be:
259+
"""
260+
https://example.com/?p=1
261+
"""
262+
257263
Scenario: Update a post from file or STDIN
258264
Given a content.html file:
259265
"""

features/term.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ Feature: Manage WordPress terms
148148
https://example.com/?cat=2
149149
"""
150150

151+
When I run `wp term get category 1 --field=url`
152+
Then STDOUT should be:
153+
"""
154+
https://example.com/?cat=1
155+
"""
156+
151157
Scenario: Make sure WordPress receives the slashed data it expects
152158
When I run `wp term create category 'My\Term' --description='My\Term\Description' --porcelain`
153159
Then save STDOUT as {TERM_ID}

src/Comment_Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ public function get( $args, $assoc_args ) {
241241
WP_CLI::error( 'Invalid comment ID.' );
242242
}
243243

244+
if ( ! isset( $comment->url ) ) {
245+
$comment->url = get_comment_link( $comment );
246+
}
247+
244248
if ( empty( $assoc_args['fields'] ) ) {
245249
$comment_array = get_object_vars( $comment );
246250
$assoc_args['fields'] = array_keys( $comment_array );

src/Post_Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ public function get( $args, $assoc_args ) {
437437
$post_arr = get_object_vars( $post );
438438
unset( $post_arr['filter'] );
439439

440+
if ( ! isset( $post_arr['url'] ) ) {
441+
$post_arr['url'] = get_permalink( $post->ID );
442+
}
443+
440444
if ( empty( $assoc_args['fields'] ) ) {
441445
$assoc_args['fields'] = array_keys( $post_arr );
442446
}

src/Term_Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ public function get( $args, $assoc_args ) {
291291
WP_CLI::error( "Term doesn't exist." );
292292
}
293293

294+
if ( ! isset( $term->url ) ) {
295+
$term->url = get_term_link( $term );
296+
}
297+
294298
if ( empty( $assoc_args['fields'] ) ) {
295299
$term_array = get_object_vars( $term );
296300
$assoc_args['fields'] = array_keys( $term_array );

0 commit comments

Comments
 (0)