-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-wp-cli.php
45 lines (38 loc) · 1.36 KB
/
simple-wp-cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Plugin Name: Simple WP CLI
* Plugin URI: https://github.com/codetot/simple-wp-cli
* Description: A simple extra WP CLI
* Version: 0.0.1
* Author: Code Tot JSC
* Author URI: https://codetot.com
* License: GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*/
if ( defined('WP_CLI') && class_exists( 'WP_CLI' ) ) {
WP_CLI::add_command( 'tag', function($args, $assoc_args) {
if (!empty( $args[0] ) && 'delete' === $args[0]) {
$count = isset($assoc_args['count']) ? intval($assoc_args['count']) : 1;
$number = isset($assoc_args['number']) ? intval($assoc_args['number']) : 100;
$success = 0;
$failure = 0;
$terms = get_terms([
'taxonomy' => 'post_tag',
'count' => $count,
'fields' => 'ids',
'number' => $number
]);
foreach ($terms as $term_id) {
$result = wp_delete_term($term_id, 'post_tag');
if ($result) {
$success++;
} else {
$failure++;
WP_CLI::error( $result );
}
}
WP_CLI::success( 'Result: ' . $success . ' success, ' . $failure . ' failure' );
} else {
WP_CLI::error( 'Incorrect param.' );
}
});
}