-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-cli.php
executable file
·59 lines (48 loc) · 1.69 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Implements Nonsentences WP-CLI command
*/
class Nonsentences_Command extends WP_CLI_Command
{
private $nonsentences;
private $args;
private function get_nonsentences($args, $assoc_args)
{
$defaults = array(
'min_sentences' => 3,
'max_sentences' => 20,
'min_paragraphs' => 2,
'max_paragraphs' => 10,
'post_type' => 'post',
'number_of_posts' => 10,
);
$args = array_merge($defaults, $assoc_args);
return new Nonsentences($args);
}
/**
* Prints a greeting.
*/
public function generate_posts($args, $assoc_args)
{
$this->nonsentences = $this->get_nonsentences($args, $assoc_args);
$s = '';
if ($this->nonsentences->number_of_posts > 1) {
$s = 's';
}
for ($x = 0; $x < $this->nonsentences->number_of_posts; $x++) {
$insert_id = wp_insert_post(
array(
'post_title' => $this->nonsentences->title(),
'post_content' => $this->nonsentences->paragraphs(),
'post_status' => 'publish',
'post_type' => $this->nonsentences->post_type,
)
);
if (is_numeric($insert_id) && $this->nonsentences->taxonomy && $this->nonsentences->taxonomy_term) {
wp_set_post_terms($insert_id, $this->nonsentences->taxonomy_term, $this->nonsentences->taxonomy);
}
}
WP_CLI::line('Inserted ' . $this->nonsentences->number_of_posts . ' ' . $this->nonsentences->post_type . $s . '.');
}
}
WP_CLI::add_command('nonsentences', 'Nonsentences_Command');