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/features/post.feature b/features/post.feature index 489f6af69..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: """ 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/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 ); 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 ); } 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 );