Field.php
725 Bytes
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
<?php
namespace ACP\Editing\Storage\Comment;
use ACP\Editing\Storage;
use RuntimeException;
class Field implements Storage {
/**
* @var string
*/
private $field;
public function __construct( $field ) {
$this->field = (string) $field;
}
public function get( int $id ) {
$comment = get_comment( $id );
return property_exists( $comment, $this->field )
? $comment->{$this->field}
: null;
}
public function update( int $id, $data ): bool {
$args = [
'comment_ID' => $id,
$this->field => $data,
];
$result = wp_update_comment( $args );
if ( is_wp_error( $result ) ) {
throw new RuntimeException( $result->get_error_message() );
}
return is_int( $result ) && $result > 0;
}
}