Completed
Pull Request — dev/6.1.0 (#678)
by Sudar
18:41 queued 14:12
created

DeletePostsCommand::by_status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\CLI\Commands;
4
5
use BulkWP\BulkDelete\Core\Base\BaseCommand;
6
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByStatusModule;
7
8
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
9
10
/**
11
 * Delete Posts CLI Command.
12
 *
13
 * @since 6.1.0
14
 */
15
class DeletePostsCommand extends BaseCommand {
16
	/**
17
	 * Get the command.
18
	 *
19
	 * @return string Command name.
20
	 */
21
	public static function get_command() {
22
		return 'posts';
23
	}
24
25
	/**
26
	 * Delete post by status.
27
	 *
28
	 * ## OPTIONS
29
	 *
30
	 * [--post_status=<post_status>]
31
	 * : Comma seperated list of post status from which posts should be deleted. You can also use any custom post status.
32
	 * ---
33
	 * default: publish
34
	 * ---
35
	 *
36
	 * [--limit_to=<limit_to>]
37
	 * : Limits the number of posts to be deleted.
38
	 * ---
39
	 * default: -1
40
	 * ---
41
	 *
42
	 * [--restrict=<restrict>]
43
	 * : Restricts posts deletion with post date filter.
44
	 * ---
45
	 * default: false
46
	 * ---
47
	 *
48
	 * [--force_delete=<force_delete>]
49
	 * : Should posts be permanently deleted. Set to false to move them to trash.
50
	 * ---
51
	 * default: false
52
	 * ---
53
	 *
54
	 * [--<field>=<value>]
55
	 * : Additional associative args for the deletion.
56
	 *
57
	 *  ## EXAMPLES
58
	 *
59
	 *     # Delete all published posts.
60
	 *     $ wp bulk-delete posts by-status
61
	 *     Success: Deleted 1 post from the selected post status
62
	 *
63
	 *     # Delete all draft posts.
64
	 *     $ wp bulk-delete posts by-status --post_status=draft
65
	 *     Success: Deleted 1 post from the selected post status
66
	 *
67
	 *     # Delete all published and draft posts.
68
	 *     $ wp bulk-delete posts by-status --post_status=draft,publish
69
	 *     Success: Deleted 1 post from the selected post status
70
	 *
71
	 * @subcommand by-status
72
	 *
73
	 * @param array $args       Arguments to be supplied.
74
	 * @param array $assoc_args Associative arguments to be supplied.
75
	 *
76
	 * @return void
77
	 */
78
	public function by_status( $args, $assoc_args ) {
79
		error_log(var_export($assoc_args, true));
80
		$module = new DeletePostsByStatusModule();
81
82
		$message = $module->process_cli_request( $assoc_args );
83
84
		\WP_CLI::success( $message );
0 ignored issues
show
Bug introduced by
The type WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
85
	}
86
}
87