Repository navigation
Expand file tree
/
Copy pathclass-content-model.php
More file actions
74 lines (71 loc) · 1.74 KB
/
Copy pathclass-content-model.php
File metadata and controls
74 lines (71 loc) · 1.74 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace PTR;
class Content_Model {
/**
* Create custom post type to store the directories we need to process.
*
* @since 1.0.0
* @return null
*/
public static function action_init_register_post_type() {
register_post_type(
'result',
array(
'labels' => array(
'name' => __( 'Test Results', 'ptr' ),
'singular_name' => __( 'Test Result', 'ptr' ),
),
'public' => true,
'has_archive' => false,
'show_in_rest' => true,
'hierarchical' => true,
'rewrite' => array(
'slug' => 'test-results',
),
'supports' => array(
'title',
'editor',
'author',
'custom-fields',
'page-attributes',
),
'map_meta_cap' => true,
'capabilities' => array(
'edit_post' => 'edit_result',
'edit_posts' => 'edit_results',
'edit_others_posts' => 'edit_others_results',
'publish_posts' => 'publish_results',
'read_post' => 'read_result',
'read_private_posts' => 'read_private_results',
'delete_post' => 'delete_result',
),
)
);
}
/**
* Create a custom role to manage ability to create results
*/
public static function action_init_register_role() {
if ( ! get_role( 'test-reporter' ) ) {
add_role(
'test-reporter',
__( 'Test Reporter', 'ptr' ),
array(
'read' => true,
)
);
}
$role = get_role( 'test-reporter' );
if ( $role ) {
$role->add_cap( 'edit_results' );
$role->add_cap( 'publish_results' );
}
$role = get_role( 'administrator' );
if ( $role ) {
$role->add_cap( 'edit_results' );
$role->add_cap( 'edit_others_results' );
$role->add_cap( 'publish_results' );
$role->add_cap( 'read_private_results' );
}
}
}