-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.taskrestapi.php
39 lines (32 loc) · 992 Bytes
/
class.taskrestapi.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
<?php
class TaskRestAPI {
public static function registerStatusField() {
register_rest_field(
'task',
'task_status',
[
'get_callback' => [ 'TaskStatus', 'getStatus' ],
'schema' => null
]
);
}
public static function grantAccess( $query ) {
$isRestRequest = defined('REST_REQUEST' ) && REST_REQUEST;
if ( !$isRestRequest ) {
return;
}
$isTaskPostType = isset( $query->query_vars['post_type'] ) &&
$query->query_vars['post_type'] === 'task';
if ( !$isTaskPostType ) {
return;
}
if ( current_user_can( 'administrator' ) ) {
$query->set( 'post_status', 'private' );
return;
}
if ( current_user_can( 'task_logger' ) ) {
$query->set( 'post_status', 'private' );
$query->set( 'author', get_current_user_id() );
}
}
}