class-cpt.php
4.08 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace um\common;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\common\CPT' ) ) {
/**
* Class CPT
*
* @package um\common
*
* @since 2.6.8
*/
class CPT {
public function hooks() {
add_action( 'init', array( &$this, 'create_post_types' ), 1 );
}
/**
* Create taxonomies for use for UM
*/
public function create_post_types() {
register_post_type(
'um_form',
array(
'labels' => array(
'name' => __( 'Forms', 'ultimate-member' ),
'singular_name' => __( 'Form', 'ultimate-member' ),
'add_new' => __( 'Add New', 'ultimate-member' ),
'add_new_item' => __( 'Add New Form', 'ultimate-member' ),
'edit_item' => __( 'Edit Form', 'ultimate-member' ),
'not_found' => __( 'You did not create any forms yet', 'ultimate-member' ),
'not_found_in_trash' => __( 'Nothing found in Trash', 'ultimate-member' ),
'search_items' => __( 'Search Forms', 'ultimate-member' ),
),
'capabilities' => array(
'edit_post' => 'manage_options',
'read_post' => 'manage_options',
'delete_post' => 'manage_options',
'edit_posts' => 'manage_options',
'edit_others_posts' => 'manage_options',
'delete_posts' => 'manage_options',
'publish_posts' => 'manage_options',
'read_private_posts' => 'manage_options',
),
'show_ui' => true,
'show_in_menu' => false,
'public' => false,
'show_in_rest' => true,
'supports' => array( 'title' ),
)
);
if ( UM()->options()->get( 'members_page' ) ) {
register_post_type(
'um_directory',
array(
'labels' => array(
'name' => __( 'Member Directories', 'ultimate-member' ),
'singular_name' => __( 'Member Directory', 'ultimate-member' ),
'add_new' => __( 'Add New', 'ultimate-member' ),
'add_new_item' => __( 'Add New Member Directory', 'ultimate-member' ),
'edit_item' => __( 'Edit Member Directory', 'ultimate-member' ),
'not_found' => __( 'You did not create any member directories yet', 'ultimate-member' ),
'not_found_in_trash' => __( 'Nothing found in Trash', 'ultimate-member' ),
'search_items' => __( 'Search Member Directories', 'ultimate-member' ),
),
'capabilities' => array(
'edit_post' => 'manage_options',
'read_post' => 'manage_options',
'delete_post' => 'manage_options',
'edit_posts' => 'manage_options',
'edit_others_posts' => 'manage_options',
'delete_posts' => 'manage_options',
'publish_posts' => 'manage_options',
'read_private_posts' => 'manage_options',
),
'show_ui' => true,
'show_in_menu' => false,
'public' => false,
'show_in_rest' => true,
'supports' => array( 'title' ),
)
);
}
}
/**
* @since 2.8.0
* @return array
*/
public function get_list() {
$cpt_list = array(
'um_form',
);
if ( UM()->options()->get( 'members_page' ) ) {
$cpt_list[] = 'um_directory';
}
/**
* Filters registered CPT in Ultimate Member.
*
* @since 2.0
* @hook um_cpt_list
*
* @param {array} $cpt_list CPT keys.
*
* @return {array} CPT keys.
*
* @example <caption>Add `my_cpt` CPT to UM CPT list.</caption>
* function um_custom_cpt_list( $cpt_list ) {
* $cpt_list[] = '{my_cpt}';
* return $cpt_list;
* }
* add_filter( 'um_cpt_list', 'um_custom_cpt_list' );
*/
return apply_filters( 'um_cpt_list', $cpt_list );
}
/**
* @param null|string $post_type
*
* @since 2.8.0
*
* @return array
*/
public function get_taxonomies_list( $post_type = null ) {
$taxonomies = apply_filters( 'um_cpt_taxonomies_list', array() );
if ( isset( $post_type ) ) {
$taxonomies = array_key_exists( $post_type, $taxonomies ) ? $taxonomies[ $post_type ] : array();
}
return $taxonomies;
}
}
}