Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@
'Site_Meta_Command',
array(
'before_invoke' => function () {
/**
* @var \wpdb $wpdb
*/
global $wpdb;
if ( ! is_multisite() ) {
WP_CLI::error( 'This is not a multisite installation.' );
}
if ( ! function_exists( 'is_site_meta_supported' ) || ! is_site_meta_supported() ) {
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $GLOBALS['wpdb']->blogmeta ) );
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $wpdb->blogmeta ) );
}
},
)
Expand Down
22 changes: 19 additions & 3 deletions features/post-block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ Feature: Manage blocks in post content
Then save STDOUT as {POST_ID}

When I run `wp post block render {POST_ID}`
# In WordPress 7.0+ paragraph blocks are rendered with a class name.
# See https://github.com/WordPress/gutenberg/pull/71207.
Then STDOUT should contain:
"""
<p>Hello World</p>
<p
"""
And STDOUT should contain:
"""
>Hello World</p>
"""
And STDOUT should contain:
"""
Expand All @@ -143,7 +149,11 @@ Feature: Manage blocks in post content
When I run `wp post block render {POST_ID} --block=core/paragraph`
Then STDOUT should contain:
"""
<p>Hello World</p>
<p
"""
And STDOUT should contain:
"""
>Hello World</p>
"""
And STDOUT should not contain:
"""
Expand Down Expand Up @@ -773,9 +783,15 @@ Feature: Manage blocks in post content
Then save STDOUT as {POST_ID}

When I run `wp post block export {POST_ID} --format=html`
# In WordPress 7.0+ paragraph blocks are rendered with a class name.
# See https://github.com/WordPress/gutenberg/pull/71207.
Then STDOUT should contain:
"""
<p>Hello World</p>
<p
"""
And STDOUT should contain:
"""
>Hello World</p>
"""

@require-wp-5.0
Expand Down
11 changes: 8 additions & 3 deletions src/Comment_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct() {
*
* # Create a note (WordPress 6.9+).
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
* Success: Created comment 933. *
* Success: Created comment 933. *
* @param string[] $args Positional arguments. Unused.
* @param array<string, mixed> $assoc_args Associative arguments.
*/
Expand Down Expand Up @@ -279,6 +279,7 @@ public function get( $args, $assoc_args ) {
WP_CLI::error( 'Invalid comment ID.' );
}

// @phpstan-ignore property.notFound
if ( ! isset( $comment->url ) ) {
// @phpstan-ignore property.notFound
$comment->url = get_comment_link( $comment );
Expand Down Expand Up @@ -447,8 +448,12 @@ public function list_( $args, $assoc_args ) {
} elseif ( is_array( $comments ) ) {
$comments = array_map(
function ( $comment ) {
$comment->url = get_comment_link( $comment->comment_ID );
return $comment;
/**
* @var \WP_Comment $comment
*/
// @phpstan-ignore property.notFound
$comment->url = get_comment_link( (int) $comment->comment_ID );
return $comment;
},
$comments
);
Expand Down
11 changes: 11 additions & 0 deletions src/Post_Block_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* $ wp post block insert 123 core/paragraph --content="Hello World"
*
* @package wp-cli
*
* @phpstan-type ParsedBlock array{blockName?: string, attrs: array<string, mixed>, innerBlocks: array<array<mixed>>, innerHTML: string, innerContent: list<mixed>}
* @phpstan-type ParsedBlockWithBlockName array{blockName: string, attrs: array<string, mixed>, innerBlocks: array<array<mixed>>, innerHTML: string, innerContent: list<mixed>}
*/
class Post_Block_Command extends WP_CLI_Command {

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

/**
* @phpstan-var array<int|string, ParsedBlock> $import_blocks
*/

// Validate block structure.
foreach ( $import_blocks as $idx => $block ) {
if ( ! isset( $block['blockName'] ) ) {
WP_CLI::error( "Invalid block structure at index {$idx}: missing blockName." );
}
}

/**
* @phpstan-var array<int|string, ParsedBlockWithBlockName> $import_blocks
*/

$imported_count = count( $import_blocks );

if ( $replace ) {
Expand Down
1 change: 0 additions & 1 deletion src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,6 @@ private function get_sites_ids( $args, $assoc_args ) {
* @param array $assoc_args Passed-in parameters.
*
* @return bool
* @throws ExitException If neither site ids nor site slug using --slug were provided.
*/
private function check_site_ids_and_slug( $args, $assoc_args ) {
if ( ( empty( $args ) && empty( $assoc_args['slug'] ) )
Expand Down
28 changes: 20 additions & 8 deletions src/Term_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ public function list_( $args, $assoc_args ) {
$term = get_term_by( 'id', $assoc_args['term_id'], $args[0] );
$terms = [ $term ];
} else {
/**
* @var \WP_Term[] $terms
*/
$terms = get_terms(
array_merge(
$assoc_args,
Expand All @@ -151,6 +148,15 @@ public function list_( $args, $assoc_args ) {
]
)
);

// This should never happen because of the taxonomy_exists check above.
if ( is_wp_error( $terms ) ) {
WP_CLI::error( $terms );
}

/**
* @var \WP_Term[] $terms
*/
}

$terms = array_map(
Expand Down Expand Up @@ -295,6 +301,7 @@ public function get( $args, $assoc_args ) {
WP_CLI::error( "Term doesn't exist." );
}

// @phpstan-ignore property.notFound
if ( ! isset( $term->url ) ) {
// @phpstan-ignore property.notFound
$term->url = get_term_link( $term );
Expand Down Expand Up @@ -649,18 +656,23 @@ public function recount( $args ) {
if ( ! taxonomy_exists( $taxonomy ) ) {
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
} else {

/**
* @var \WP_Term[] $terms
*/

$terms = get_terms(
[
'taxonomy' => $taxonomy,
'hide_empty' => false,
]
);

// This should never happen because of the taxonomy_exists check above.
if ( is_wp_error( $terms ) ) {
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
continue;
}

/**
* @var \WP_Term[] $terms
*/

$term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' );

wp_update_term_count( $term_taxonomy_ids, $taxonomy );
Expand Down
3 changes: 3 additions & 0 deletions src/User_Meta_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) {
private function replace_login_with_user_id( $args ) {
$user = $this->fetcher->get_check( $args[0] );
$args[0] = $user->ID;
// TODO: Improve method type eventually.
// Related: https://github.com/phpstan/phpstan/issues/8438.
// @phpstan-ignore return.type
return $args;
}
}
2 changes: 2 additions & 0 deletions src/User_Session_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ protected function get_all_sessions( WP_Session_Tokens $manager ) {
// Make the private session data accessible to WP-CLI
$get_sessions = new ReflectionMethod( $manager, 'get_sessions' );
if ( PHP_VERSION_ID < 80100 ) {
// @phpstan-ignore method.deprecated
$get_sessions->setAccessible( true );
}

Expand All @@ -197,6 +198,7 @@ function ( &$session, $token ) {
protected function destroy_session( WP_Session_Tokens $manager, $token ) {
$update_session = new ReflectionMethod( $manager, 'update_session' );
if ( PHP_VERSION_ID < 80100 ) {
// @phpstan-ignore method.deprecated
$update_session->setAccessible( true );
}
return $update_session->invoke( $manager, $token, null );
Expand Down
8 changes: 7 additions & 1 deletion src/WP_CLI/CommandWithTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ public function list_( $args, $assoc_args ) {
$taxonomy_args['fields'] = 'ids';
}

$items = wp_get_object_terms( $object_id, $taxonomy_names, $taxonomy_args );

// This should never happen because of the taxonomy_exists check above.
if ( is_wp_error( $items ) ) {
WP_CLI::error( $items );
}

/**
* @var \WP_Term[] $items
*/
$items = wp_get_object_terms( $object_id, $taxonomy_names, $taxonomy_args );

$formatter = $this->get_formatter( $assoc_args );
$formatter->display_items( $items );
Expand Down