Skip to content

Commit 698da34

Browse files
authored
Merge branch 'main' into copilot/add-post-revision-commands
2 parents 8503d88 + 93cf0dd commit 698da34

13 files changed

+99
-19
lines changed

.github/workflows/code-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches:
77
- main
88
- master
9+
schedule:
10+
- cron: '17 2 * * *' # Run every day on a seemly random time.
911

1012
jobs:
1113
code-quality:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ wp comment create [--<field>=<value>] [--porcelain]
150150

151151
# Create a note (WordPress 6.9+).
152152
$ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
153-
Success: Created comment 933.
 *
153+
Success: Created comment 933.
154154

155155

156156

@@ -5612,6 +5612,7 @@ These fields will be displayed by default for each term:
56125612

56135613
These fields are optionally available:
56145614

5615+
* term_group
56155616
* url
56165617

56175618
**EXAMPLES**

entity-command.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@
5555
'Site_Meta_Command',
5656
array(
5757
'before_invoke' => function () {
58+
/**
59+
* @var \wpdb $wpdb
60+
*/
61+
global $wpdb;
5862
if ( ! is_multisite() ) {
5963
WP_CLI::error( 'This is not a multisite installation.' );
6064
}
6165
if ( ! function_exists( 'is_site_meta_supported' ) || ! is_site_meta_supported() ) {
62-
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $GLOBALS['wpdb']->blogmeta ) );
66+
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $wpdb->blogmeta ) );
6367
}
6468
},
6569
)

features/post-block.feature

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@ Feature: Manage blocks in post content
127127
Then save STDOUT as {POST_ID}
128128

129129
When I run `wp post block render {POST_ID}`
130+
# In WordPress 7.0+ paragraph blocks are rendered with a class name.
131+
# See https://github.com/WordPress/gutenberg/pull/71207.
130132
Then STDOUT should contain:
131133
"""
132-
<p>Hello World</p>
134+
<p
135+
"""
136+
And STDOUT should contain:
137+
"""
138+
>Hello World</p>
133139
"""
134140
And STDOUT should contain:
135141
"""
@@ -143,7 +149,11 @@ Feature: Manage blocks in post content
143149
When I run `wp post block render {POST_ID} --block=core/paragraph`
144150
Then STDOUT should contain:
145151
"""
146-
<p>Hello World</p>
152+
<p
153+
"""
154+
And STDOUT should contain:
155+
"""
156+
>Hello World</p>
147157
"""
148158
And STDOUT should not contain:
149159
"""
@@ -773,9 +783,15 @@ Feature: Manage blocks in post content
773783
Then save STDOUT as {POST_ID}
774784

775785
When I run `wp post block export {POST_ID} --format=html`
786+
# In WordPress 7.0+ paragraph blocks are rendered with a class name.
787+
# See https://github.com/WordPress/gutenberg/pull/71207.
776788
Then STDOUT should contain:
777789
"""
778-
<p>Hello World</p>
790+
<p
791+
"""
792+
And STDOUT should contain:
793+
"""
794+
>Hello World</p>
779795
"""
780796

781797
@require-wp-5.0

features/term.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,21 @@ Feature: Manage WordPress terms
280280
"""
281281
Success: Term updated.
282282
"""
283+
284+
Scenario: Term list includes term_group as optional field
285+
When I run `wp term create category 'Group Test' --slug=group-test --description='Test term_group field'`
286+
Then STDOUT should not be empty
287+
288+
When I run `wp term list category --format=csv --fields=name,term_group`
289+
Then STDOUT should contain:
290+
"""
291+
term_group
292+
"""
293+
294+
When I run `wp term list category --format=json --fields=term_id,name,term_group`
295+
Then STDOUT should be JSON containing:
296+
"""
297+
[{
298+
"term_group":0
299+
}]
300+
"""

src/Comment_Command.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public function __construct() {
9494
*
9595
* # Create a note (WordPress 6.9+).
9696
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
97-
* Success: Created comment 933.
 *
97+
* Success: Created comment 933.
98+
*
9899
* @param string[] $args Positional arguments. Unused.
99100
* @param array<string, mixed> $assoc_args Associative arguments.
100101
*/
@@ -279,6 +280,7 @@ public function get( $args, $assoc_args ) {
279280
WP_CLI::error( 'Invalid comment ID.' );
280281
}
281282

283+
// @phpstan-ignore property.notFound
282284
if ( ! isset( $comment->url ) ) {
283285
// @phpstan-ignore property.notFound
284286
$comment->url = get_comment_link( $comment );
@@ -447,8 +449,12 @@ public function list_( $args, $assoc_args ) {
447449
} elseif ( is_array( $comments ) ) {
448450
$comments = array_map(
449451
function ( $comment ) {
450-
$comment->url = get_comment_link( $comment->comment_ID );
451-
return $comment;
452+
/**
453+
* @var \WP_Comment $comment
454+
*/
455+
// @phpstan-ignore property.notFound
456+
$comment->url = get_comment_link( (int) $comment->comment_ID );
457+
return $comment;
452458
},
453459
$comments
454460
);

src/Post_Block_Command.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* $ wp post block insert 123 core/paragraph --content="Hello World"
3232
*
3333
* @package wp-cli
34+
*
35+
* @phpstan-type ParsedBlock array{blockName?: string, attrs: array<string, mixed>, innerBlocks: array<array<mixed>>, innerHTML: string, innerContent: list<mixed>}
36+
* @phpstan-type ParsedBlockWithBlockName array{blockName: string, attrs: array<string, mixed>, innerBlocks: array<array<mixed>>, innerHTML: string, innerContent: list<mixed>}
3437
*/
3538
class Post_Block_Command extends WP_CLI_Command {
3639

@@ -641,13 +644,21 @@ public function import( $args, $assoc_args ) {
641644
WP_CLI::error( 'No blocks found in import data.' );
642645
}
643646

647+
/**
648+
* @phpstan-var array<int|string, ParsedBlock> $import_blocks
649+
*/
650+
644651
// Validate block structure.
645652
foreach ( $import_blocks as $idx => $block ) {
646653
if ( ! isset( $block['blockName'] ) ) {
647654
WP_CLI::error( "Invalid block structure at index {$idx}: missing blockName." );
648655
}
649656
}
650657

658+
/**
659+
* @phpstan-var array<int|string, ParsedBlockWithBlockName> $import_blocks
660+
*/
661+
651662
$imported_count = count( $import_blocks );
652663

653664
if ( $replace ) {

src/Post_Command.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,6 @@ public function generate( $args, $assoc_args ) {
779779

780780
// Add time if the string is a valid date without time.
781781
$date = DateTime::createFromFormat( 'Y-m-d', $post_data['post_date'] );
782-
$date = DateTime::createFromFormat( 'Y-m-d', $post_data['post_date'] );
783782
if ( $date && $date->format( 'Y-m-d' ) === $post_data['post_date'] ) {
784783
$post_data['post_date'] .= ' 00:00:00';
785784
}

src/Site_Command.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ private function get_sites_ids( $args, $assoc_args ) {
12441244
* @param array $assoc_args Passed-in parameters.
12451245
*
12461246
* @return bool
1247-
* @throws ExitException If neither site ids nor site slug using --slug were provided.
12481247
*/
12491248
private function check_site_ids_and_slug( $args, $assoc_args ) {
12501249
if ( ( empty( $args ) && empty( $assoc_args['slug'] ) )

src/Term_Command.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class Term_Command extends WP_CLI_Command {
9393
*
9494
* These fields are optionally available:
9595
*
96+
* * term_group
9697
* * url
9798
*
9899
* ## EXAMPLES
@@ -139,9 +140,6 @@ public function list_( $args, $assoc_args ) {
139140
$term = get_term_by( 'id', $assoc_args['term_id'], $args[0] );
140141
$terms = [ $term ];
141142
} else {
142-
/**
143-
* @var \WP_Term[] $terms
144-
*/
145143
$terms = get_terms(
146144
array_merge(
147145
$assoc_args,
@@ -150,6 +148,15 @@ public function list_( $args, $assoc_args ) {
150148
]
151149
)
152150
);
151+
152+
// This should never happen because of the taxonomy_exists check above.
153+
if ( is_wp_error( $terms ) ) {
154+
WP_CLI::error( $terms );
155+
}
156+
157+
/**
158+
* @var \WP_Term[] $terms
159+
*/
153160
}
154161

155162
$terms = array_map(
@@ -294,6 +301,7 @@ public function get( $args, $assoc_args ) {
294301
WP_CLI::error( "Term doesn't exist." );
295302
}
296303

304+
// @phpstan-ignore property.notFound
297305
if ( ! isset( $term->url ) ) {
298306
// @phpstan-ignore property.notFound
299307
$term->url = get_term_link( $term );
@@ -648,18 +656,23 @@ public function recount( $args ) {
648656
if ( ! taxonomy_exists( $taxonomy ) ) {
649657
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
650658
} else {
651-
652-
/**
653-
* @var \WP_Term[] $terms
654-
*/
655-
656659
$terms = get_terms(
657660
[
658661
'taxonomy' => $taxonomy,
659662
'hide_empty' => false,
660663
]
661664
);
662665

666+
// This should never happen because of the taxonomy_exists check above.
667+
if ( is_wp_error( $terms ) ) {
668+
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
669+
continue;
670+
}
671+
672+
/**
673+
* @var \WP_Term[] $terms
674+
*/
675+
663676
$term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' );
664677

665678
wp_update_term_count( $term_taxonomy_ids, $taxonomy );

0 commit comments

Comments
 (0)