Skip to content

wp-cli subcommands on Windows Powershell #5679

@timotheemoulin

Description

@timotheemoulin

Looking at the official WP documentation here, the wp post delete command should be able to take a subcommand to list all the IDs to delete.

This works well on a Linux like system, but doesn't on Windows Powershell.

I know that it is more a Windows+Powershell issue, but that would be nice if we could find a workaround solution for this.

Expectations

# Delete all pages
$ wp post delete $(wp post list --post_type='page' --format=ids)
Success: Trashed post 1164.
Success: Trashed post 1186.

Reality

# Delete all pages
$ wp post delete $(wp post list --post_type='page' --format=ids)
Success: Trashed post 1164 1186.

In that case, post id 1186 has not been deleted because the subcommand result is interpreted as a single string parameter given to the delete command.
The \WP_CLI\CommandWithDBObject::_delete function that should receive $args as an array of IDs receive in reality one string param with the value 1164 1186 which evaluates as 1164 when casted to integer.

Function parameters type hint
Moreover, the wp_delete_post() function that is called underneath, should receive an integer value as first parameter.

/**
 * @param int  $postid       Optional. Post ID. Default 0.
 * @param bool $force_delete Optional. Whether to bypass Trash and force deletion.
 *                           Default false.
 * @return WP_Post|false|null Post data on success, false or null on failure.
 */
function wp_delete_post( $postid = 0, $force_delete = false ) {}
/**
 * Filters whether a post deletion should take place.
 *
 * @since 4.4.0
 *
 * @param WP_Post|false|null $delete       Whether to go forward with deletion. @TODO description
 * @param WP_Post            $post         Post object.
 * @param bool               $force_delete Whether to bypass the Trash.
 */
$check = apply_filters( 'pre_delete_post', null, $post, $force_delete );

I don't know if parameters hints will be enforced later, but there might be an issue there too as this function and the hooks triggered are all expecting an integer value.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions