Skip to content

Commit 3ffdd41

Browse files
authored
Merge pull request #552 from wp-cli/copilot/add-notes-support
2 parents a159471 + f3524ee commit 3ffdd41

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

features/comment-notes.feature

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
Feature: Manage WordPress notes
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-6.9
7+
Scenario: Create and list notes
8+
When I run `wp comment create --comment_post_ID=1 --comment_content='This is a note about the block' --comment_author='Editor' --comment_type='note' --porcelain`
9+
Then STDOUT should be a number
10+
And save STDOUT as {NOTE_ID}
11+
12+
When I run `wp comment get {NOTE_ID} --field=comment_type`
13+
Then STDOUT should be:
14+
"""
15+
note
16+
"""
17+
18+
When I run `wp comment list --type=note --post_id=1 --format=ids`
19+
Then STDOUT should be:
20+
"""
21+
{NOTE_ID}
22+
"""
23+
24+
When I run `wp comment list --type=note --post_id=1 --fields=comment_ID,comment_type,comment_content`
25+
Then STDOUT should be a table containing rows:
26+
| comment_ID | comment_type | comment_content |
27+
| {NOTE_ID} | note | This is a note about the block |
28+
29+
@require-wp-6.9
30+
Scenario: Notes are not shown by default in comment list
31+
When I run `wp comment create --comment_post_ID=1 --comment_content='Regular comment' --comment_author='User' --porcelain`
32+
Then save STDOUT as {COMMENT_ID}
33+
34+
When I run `wp comment create --comment_post_ID=1 --comment_content='This is a note' --comment_author='Editor' --comment_type='note' --porcelain`
35+
Then save STDOUT as {NOTE_ID}
36+
37+
When I run `wp comment list --post_id=1 --format=ids`
38+
Then STDOUT should contain:
39+
"""
40+
{COMMENT_ID}
41+
"""
42+
And STDOUT should not contain:
43+
"""
44+
{NOTE_ID}
45+
"""
46+
47+
When I run `wp comment list --type=note --post_id=1 --format=ids`
48+
Then STDOUT should be:
49+
"""
50+
{NOTE_ID}
51+
"""
52+
53+
@require-wp-6.9
54+
Scenario: Reply to a note
55+
When I run `wp comment create --comment_post_ID=1 --comment_content='Initial note' --comment_author='Editor1' --comment_type='note' --porcelain`
56+
Then save STDOUT as {PARENT_NOTE_ID}
57+
58+
When I run `wp comment create --comment_post_ID=1 --comment_content='Reply to note' --comment_author='Editor2' --comment_type='note' --comment_parent={PARENT_NOTE_ID} --porcelain`
59+
Then save STDOUT as {REPLY_NOTE_ID}
60+
61+
When I run `wp comment get {REPLY_NOTE_ID} --field=comment_parent`
62+
Then STDOUT should be:
63+
"""
64+
{PARENT_NOTE_ID}
65+
"""
66+
67+
When I run `wp comment list --type=note --post_id=1 --format=count`
68+
Then STDOUT should be:
69+
"""
70+
2
71+
"""
72+
73+
@require-wp-6.9
74+
Scenario: Resolve a note
75+
When I run `wp comment create --comment_post_ID=1 --comment_content='Note to be resolved' --comment_author='Editor' --comment_type='note' --porcelain`
76+
Then save STDOUT as {NOTE_ID}
77+
78+
When I run `wp comment create --comment_post_ID=1 --comment_content='Resolving' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE_ID} --porcelain`
79+
Then save STDOUT as {RESOLVE_NOTE_ID}
80+
81+
When I run `wp comment meta add {RESOLVE_NOTE_ID} _wp_note_status resolved`
82+
Then STDOUT should contain:
83+
"""
84+
Success: Added custom field.
85+
"""
86+
87+
When I run `wp comment meta get {RESOLVE_NOTE_ID} _wp_note_status`
88+
Then STDOUT should be:
89+
"""
90+
resolved
91+
"""
92+
93+
@require-wp-6.9
94+
Scenario: Reopen a resolved note
95+
When I run `wp comment create --comment_post_ID=1 --comment_content='Note to resolve and reopen' --comment_author='Editor' --comment_type='note' --porcelain`
96+
Then save STDOUT as {NOTE_ID}
97+
98+
When I run `wp comment create --comment_post_ID=1 --comment_content='Resolving' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE_ID} --porcelain`
99+
Then save STDOUT as {RESOLVE_NOTE_ID}
100+
101+
When I run `wp comment meta add {RESOLVE_NOTE_ID} _wp_note_status resolved`
102+
Then STDOUT should contain:
103+
"""
104+
Success: Added custom field.
105+
"""
106+
107+
When I run `wp comment create --comment_post_ID=1 --comment_content='Reopening' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE_ID} --porcelain`
108+
Then save STDOUT as {REOPEN_NOTE_ID}
109+
110+
When I run `wp comment meta add {REOPEN_NOTE_ID} _wp_note_status reopen`
111+
Then STDOUT should contain:
112+
"""
113+
Success: Added custom field.
114+
"""
115+
116+
When I run `wp comment meta get {REOPEN_NOTE_ID} _wp_note_status`
117+
Then STDOUT should be:
118+
"""
119+
reopen
120+
"""
121+
122+
@require-wp-6.9
123+
Scenario: List notes with comment meta
124+
When I run `wp comment create --comment_post_ID=1 --comment_content='First note' --comment_author='Editor' --comment_type='note' --porcelain`
125+
Then save STDOUT as {NOTE1_ID}
126+
127+
When I run `wp comment create --comment_post_ID=1 --comment_content='Resolved note' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE1_ID} --porcelain`
128+
Then save STDOUT as {NOTE2_ID}
129+
130+
When I run `wp comment meta add {NOTE2_ID} _wp_note_status resolved`
131+
Then STDOUT should contain:
132+
"""
133+
Success: Added custom field.
134+
"""
135+
136+
When I run `wp comment meta list {NOTE2_ID} --keys=_wp_note_status`
137+
Then STDOUT should be a table containing rows:
138+
| comment_id | meta_key | meta_value |
139+
| {NOTE2_ID} | _wp_note_status | resolved |
140+
141+
@require-wp-6.9
142+
Scenario: Get notes for multiple posts
143+
When I run `wp post create --post_title='Post 2' --porcelain`
144+
Then save STDOUT as {POST2_ID}
145+
146+
When I run `wp comment create --comment_post_ID=1 --comment_content='Note on post 1' --comment_author='Editor' --comment_type='note' --porcelain`
147+
Then save STDOUT as {NOTE1_ID}
148+
149+
When I run `wp comment create --comment_post_ID={POST2_ID} --comment_content='Note on post 2' --comment_author='Editor' --comment_type='note' --porcelain`
150+
Then save STDOUT as {NOTE2_ID}
151+
152+
When I run `wp comment list --type=note --post_id=1 --format=ids`
153+
Then STDOUT should be:
154+
"""
155+
{NOTE1_ID}
156+
"""
157+
158+
When I run `wp comment list --type=note --post_id={POST2_ID} --format=ids`
159+
Then STDOUT should be:
160+
"""
161+
{NOTE2_ID}
162+
"""

src/Comment_Command.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@
2626
* Success: Trashed comment 264.
2727
* Success: Trashed comment 262.
2828
*
29+
* # Create a note for a block (WordPress 6.9+).
30+
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
31+
* Success: Created comment 945.
32+
*
33+
* # List notes for a specific post (WordPress 6.9+).
34+
* $ wp comment list --type=note --post_id=15
35+
* +------------+---------------------+----------------------------------+
36+
* | comment_ID | comment_date | comment_content |
37+
* +------------+---------------------+----------------------------------+
38+
* | 945 | 2024-11-10 14:30:00 | This block needs revision |
39+
* +------------+---------------------+----------------------------------+
40+
*
41+
* # Reply to a note (WordPress 6.9+).
42+
* $ wp comment create --comment_post_ID=15 --comment_content="Updated per feedback" --comment_author="editor" --comment_type="note" --comment_parent=945
43+
* Success: Created comment 946.
44+
*
45+
* # Resolve a note by adding a comment with status meta (WordPress 6.9+).
46+
* $ wp comment create --comment_post_ID=15 --comment_content="Resolving" --comment_author="editor" --comment_type="note" --comment_parent=945 --porcelain
47+
* 947
48+
* $ wp comment meta add 947 _wp_note_status resolved
49+
* Success: Added custom field.
50+
*
51+
* # Reopen a resolved note (WordPress 6.9+).
52+
* $ wp comment create --comment_post_ID=15 --comment_content="Reopening for further review" --comment_author="editor" --comment_type="note" --comment_parent=945 --porcelain
53+
* 948
54+
* $ wp comment meta add 948 _wp_note_status reopen
55+
* Success: Added custom field.
56+
*
2957
* @package wp-cli
3058
*/
3159
class Comment_Command extends CommandWithDBObject {
@@ -64,6 +92,9 @@ public function __construct() {
6492
* $ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli"
6593
* Success: Created comment 932.
6694
*
95+
* # Create a note (WordPress 6.9+).
96+
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
97+
* Success: Created comment 933.
 *
6798
* @param string[] $args Positional arguments. Unused.
6899
* @param array<string, mixed> $assoc_args Associative arguments.
69100
*/
@@ -368,6 +399,15 @@ public function get( $args, $assoc_args ) {
368399
* | 3 | 2023-11-10 11:22:31 | John Doe |
369400
* +------------+---------------------+----------------+
370401
*
402+
* # List notes for a specific post (WordPress 6.9+).
403+
* $ wp comment list --type=note --post_id=15 --fields=ID,comment_date,comment_content
404+
* +------------+---------------------+----------------------------------+
405+
* | comment_ID | comment_date | comment_content |
406+
* +------------+---------------------+----------------------------------+
407+
* | 10 | 2024-11-10 14:30:00 | This block needs revision |
408+
* | 11 | 2024-11-10 15:45:00 | Updated per feedback |
409+
* +------------+---------------------+----------------------------------+
410+
*
371411
* @subcommand list
372412
*/
373413
public function list_( $args, $assoc_args ) {

0 commit comments

Comments
 (0)