File tree Expand file tree Collapse file tree 4 files changed +73
-0
lines changed Expand file tree Collapse file tree 4 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -2177,6 +2177,36 @@ wp post edit <id>
21772177
21782178
21792179
2180+ ### wp post exists
2181+
2182+ Verifies whether a post exists.
2183+
2184+ ~~~
2185+ wp post exists <id>
2186+ ~~~
2187+
2188+ Displays a success message if the post does exist.
2189+
2190+ ** OPTIONS**
2191+
2192+ <id>
2193+ The ID of the post to check.
2194+
2195+ ** EXAMPLES**
2196+
2197+ # The post exists.
2198+ $ wp post exists 1
2199+ Success: Post with ID 1337 exists.
2200+ $ echo $?
2201+ 0
2202+
2203+ # The post does not exist.
2204+ $ wp post exists 10000
2205+ $ echo $?
2206+ 1
2207+
2208+
2209+
21802210### wp post generate
21812211
21822212Generates some posts.
Original file line number Diff line number Diff line change 9191 " post create" ,
9292 " post delete" ,
9393 " post edit" ,
94+ " post exists" ,
9495 " post generate" ,
9596 " post get" ,
9697 " post list" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,17 @@ Feature: Manage WordPress posts
88 Then STDOUT should be a number
99 And save STDOUT as {POST_ID}
1010
11+ When I run `wp post exists {POST_ID}`
12+ Then STDOUT should be:
13+ """
14+ Success: Post with ID {POST_ID} exists.
15+ """
16+ And the return code should be 0
17+
18+ When I try `wp post exists 1000`
19+ And STDOUT should be empty
20+ And the return code should be 1
21+
1122 When I run `wp post update {POST_ID} --post_title='Updated post' `
1223 Then STDOUT should be:
1324 """
Original file line number Diff line number Diff line change @@ -899,4 +899,35 @@ private function get_tags( $post_id ) {
899899
900900 return $ tag_arr ;
901901 }
902+
903+ /**
904+ * Verifies whether a post exists.
905+ *
906+ * Displays a success message if the post does exist.
907+ *
908+ * ## OPTIONS
909+ *
910+ * <id>
911+ * : The ID of the post to check.
912+ *
913+ * ## EXAMPLES
914+ *
915+ * # The post exists.
916+ * $ wp post exists 1
917+ * Success: Post with ID 1337 exists.
918+ * $ echo $?
919+ * 0
920+ *
921+ * # The post does not exist.
922+ * $ wp post exists 10000
923+ * $ echo $?
924+ * 1
925+ */
926+ public function exists ( $ args ) {
927+ if ( $ this ->fetcher ->get ( $ args [0 ] ) ) {
928+ WP_CLI ::success ( "Post with ID {$ args [0 ]} exists. " );
929+ } else {
930+ WP_CLI ::halt ( 1 );
931+ }
932+ }
902933}
You can’t perform that action at this time.
0 commit comments