/
add-bulk-comments.php
65 lines (56 loc) · 1.51 KB
/
add-bulk-comments.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
60
61
62
63
64
65
<?php
/**
* Plugin Name: Add Bulk Comments
* Plugin URI: http://scootah.com/
* Description: Add bulk anonymous comments to posts.
* Version: 1.0
* Author: Scott Grant
* Author URI: http://scootah.com/
*/
class WP_AddBulkComments {
public function __construct() {
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_action( 'save_post', array( $this, 'save_post_meta' ) );
}
/**
* Initialize meta box.
*/
public function add_meta_boxes() {
add_meta_box(
'add-bulk-comments',
'Add Bulk Comments',
array( $this, 'generate_meta_box' ),
'',
'normal'
);
}
/**
* Show HTML for the zone details stored in post meta.
*/
public function generate_meta_box( $post ) {
$post_id = intval( $post->ID );
$post_url = get_post_meta( $post_id, 'add-bulk-comments', true );
echo '<p>Number of bulk comments to add to post: ' .
'<input type="text" name="add-bulk-comments" value="' .
$post_url . '"></p>';
}
/**
* Extract the updates from $_POST and save in post meta.
*/
public function save_post_meta( $post_id ) {
if ( isset( $_POST[ 'add-bulk-comments' ] ) ) {
$n = intval( $_POST[ 'add-bulk-comments' ] );
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => 'Bulk Comment',
'comment_content' => 'Content',
'comment_approved' => 1,
);
for ( $i = 0; $i < $n; $i += 1 ) {
$data['comment_content'] = wp_generate_password( 12, false );
wp_insert_comment( $data );
}
}
}
}
$wp_addbulkcomments = new WP_AddBulkComments();