Comment.php
1.23 KB
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
<?php
namespace ACP\Editing\Ajax\EditableRows;
use AC;
use ACP\Editing\Ajax\EditableRows;
use ACP\Editing\Strategy;
use WP_Comment_Query;
final class Comment extends EditableRows {
/**
* @var AC\Ajax\Handler
*/
private $handler;
/**
* @param AC\Request $request
* @param Strategy $strategy
*/
public function __construct( AC\Request $request, Strategy $strategy ) {
$handler = new AC\Ajax\Handler( false );
$handler->set_action( 'pre_get_comments' )
->set_callback( [ $this, 'send_editable_rows' ] )
->set_priority( PHP_INT_MAX - 100 );
$this->handler = $handler;
parent::__construct( $request, $strategy );
}
public function register() {
$this->handler->register();
}
public function send_editable_rows( WP_Comment_Query $query ) {
$this->check_nonce();
$this->handler->deregister();
$query->query_vars['fields'] = '*';
$query->query_vars['number'] = $this->get_editable_rows_per_iteration();
$query->query_vars['offset'] = $this->get_offset();
$editable_rows = [];
foreach ( $query->get_comments() as $comment ) {
if ( $this->strategy->user_has_write_permission( $comment ) ) {
$editable_rows[] = $comment->comment_ID;
}
}
$this->success( $editable_rows );
}
}