PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / trunk
Pods – Custom Content Types and Fields vtrunk
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / Admin / Config / Group.php
pods / src / Pods / Admin / Config Last commit date
Base.php 4 months ago Field.php 4 months ago Group.php 4 months ago Pod.php 4 months ago
Group.php
281 lines
1 <?php
2
3 namespace Pods\Admin\Config;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 die( '-1' );
8 }
9
10 /**
11 * Group configuration class.
12 *
13 * @since 2.8.0
14 */
15 class Group extends Base {
16
17 /**
18 * Get list of tabs for the Group object.
19 *
20 * @since 2.8.0
21 *
22 * @param \Pods\Whatsit\Pod $pod The pod object.
23 *
24 * @return array List of tabs for the Group object.
25 */
26 public function get_tabs( \Pods\Whatsit\Pod $pod ) {
27 $core_tabs = [
28 'basic' => __( 'Group Details', 'pods' ),
29 'advanced' => __( 'Advanced', 'pods' ),
30 ];
31
32 // Only include kitchen sink if dev mode on and not running Codecept tests.
33 if ( pods_developer() && ! function_exists( 'codecept_debug' ) ) {
34 $core_tabs['kitchen-sink'] = __( 'Kitchen Sink (temp)', 'pods' );
35 }
36
37 $pod_type = $pod['type'];
38 $pod_name = $pod['name'];
39
40 $tabs = $core_tabs;
41
42 /**
43 * Filter the Pod Group option tabs for a specific pod type and name.
44 *
45 * @since 2.8.0
46 *
47 * @param array $core_tabs Tabs to set.
48 * @param \Pods\Whatsit\Pod $pod Current Pods object.
49 */
50 $tabs = (array) apply_filters( "pods_admin_setup_edit_group_tabs_{$pod_type}_{$pod_name}", $tabs, $pod );
51
52 /**
53 * Filter the Pod Group option tabs for a specific pod type.
54 *
55 * @since 2.8.0
56 *
57 * @param array $tabs Tabs to set.
58 * @param \Pods\Whatsit\Pod $pod Current Pods object.
59 */
60 $tabs = (array) apply_filters( "pods_admin_setup_edit_group_tabs_{$pod_type}", $tabs, $pod );
61
62 /**
63 * Filter the Pod Group option tabs.
64 *
65 * @since 2.8.0
66 *
67 * @param array $tabs Tabs to set.
68 * @param \Pods\Whatsit\Pod $pod Current Pods object.
69 */
70 $tabs = (array) apply_filters( 'pods_admin_setup_edit_group_tabs', $tabs, $pod );
71
72 // Sort and then enforce the core tabs to be in front.
73 uksort( $tabs, 'strnatcmp' );
74
75 $tabs = array_merge( $core_tabs, $tabs );
76
77 return $tabs;
78 }
79
80 /**
81 * Get list of fields for the Group object.
82 *
83 * @since 2.8.0
84 *
85 * @param \Pods\Whatsit\Pod $pod The pod object.
86 * @param array $tabs The list of tabs for the pod object.
87 *
88 * @return array List of fields for the Group object.
89 */
90 public function get_fields( \Pods\Whatsit\Pod $pod, array $tabs ) {
91 $options = [];
92
93 $options['basic'] = [
94 'label' => [
95 'name' => 'label',
96 'label' => __( 'Label', 'pods' ),
97 'type' => 'text',
98 'required' => true,
99 'default' => '',
100 ],
101 'name' => [
102 'name' => 'name',
103 'label' => __( 'Name', 'pods' ),
104 'type' => 'slug',
105 'required' => true,
106 'default' => '',
107 ],
108 /*'description' => [
109 'name' => 'description',
110 'label' => __( 'Description', 'pods' ),
111 'type' => 'text',
112 'default' => '',
113 ],*/
114 /*'type' => [
115 'name' => 'type',
116 'label' => __( 'Type', 'pods' ),
117 'type' => 'pick',
118 'default' => '',
119 'data' => [],
120 ],*/
121 ];
122
123 $options['advanced'] = [
124 'visibility' => [
125 'name' => 'visibility',
126 'label' => __( 'Visibility', 'pods' ),
127 'type' => 'heading',
128 ],
129 'restrict_access' => [
130 'type' => 'boolean_group',
131 'name' => 'restrict_access',
132 'label' => __( 'Restrict Access', 'pods' ),
133 'boolean_group' => [
134 'logged_in' => [
135 'name' => 'logged_in',
136 'label' => __( 'Restrict access to Logged In Users', 'pods' ),
137 'default' => 0,
138 'type' => 'boolean',
139 'dependency' => true,
140 'help' => __( 'This group of field will only be able to be edited by logged in users. This is not required to be on for the other Restrict Access options to work.', 'pods' ),
141 ],
142 'admin_only' => [
143 'name' => 'admin_only',
144 'label' => __( 'Restrict access to Admins', 'pods' ),
145 'default' => 0,
146 'type' => 'boolean',
147 'dependency' => true,
148 'help' => __( 'This group of fields will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' ),
149 ],
150 'restrict_role' => [
151 'name' => 'restrict_role',
152 'label' => __( 'Restrict access by Role', 'pods' ),
153 'default' => 0,
154 'type' => 'boolean',
155 'dependency' => true,
156 ],
157 'restrict_capability' => [
158 'name' => 'restrict_capability',
159 'label' => __( 'Restrict access by Capability', 'pods' ),
160 'default' => 0,
161 'type' => 'boolean',
162 'dependency' => true,
163 ],
164 ],
165 ],
166 'roles_allowed' => [
167 'name' => 'roles_allowed',
168 'label' => __( 'Role(s) Allowed', 'pods' ),
169 'help' => __( 'If none are selected, this option will be ignored.', 'pods' ),
170 'type' => 'pick',
171 'pick_object' => 'role',
172 'pick_format_type' => 'multi',
173 'default' => 'administrator',
174 'depends-on' => [
175 'restrict_role' => true,
176 ],
177 ],
178 'capability_allowed' => [
179 'name' => 'capability_allowed',
180 'label' => __( 'Capability Allowed', 'pods' ),
181 'help' => __( 'Comma-separated list of capabilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
182 'type' => 'text',
183 'default' => '',
184 'depends-on' => [
185 'restrict_capability' => true,
186 ],
187 ],
188 ];
189
190 $object_type = $pod->get_type();
191
192 $is_post_type = 'post_type' === $object_type;
193 $is_comment_type = 'comment' === $object_type;
194
195 if ( $is_post_type || $is_comment_type ) {
196 $options['basic']['meta_box_context'] = [
197 'name' => 'meta_box_context',
198 'label' => __( 'Meta Box Context', 'pods' ),
199 'help' => [
200 __( 'See add_meta_box() documentation.', 'pods' ),
201 'https://developer.wordpress.org/reference/functions/add_meta_box/#parameters',
202 ],
203 'type' => 'pick',
204 'default' => 'normal',
205 'data' => [
206 'normal' => __( 'Normal', 'pods' ),
207 'side' => __( 'Side', 'pods' ),
208 'advanced' => __( 'Advanced', 'pods' ),
209 ],
210 'pick_format_single' => 'dropdown',
211 'pick_show_select_text' => 0,
212 ];
213
214 if ( $is_comment_type ) {
215 unset( $options['basic']['meta_box_context']['data']['advanced'] );
216 }
217
218 $options['basic']['meta_box_priority'] = [
219 'name' => 'meta_box_priority',
220 'label' => __( 'Meta Box Priority', 'pods' ),
221 'help' => [
222 __( 'See add_meta_box() documentation.', 'pods' ),
223 'https://developer.wordpress.org/reference/functions/add_meta_box/#parameters',
224 ],
225 'type' => 'pick',
226 'default' => 'default',
227 'data' => [
228 'high' => __( 'High', 'pods' ),
229 'default' => __( 'Default', 'pods' ),
230 'low' => __( 'Low', 'pods' ),
231 ],
232 'pick_format_single' => 'dropdown',
233 'pick_show_select_text' => 0,
234 ];
235 }
236
237 // Only include kitchen sink if dev mode on and not running Codecept tests.
238 if ( pods_developer() && ! function_exists( 'codecept_debug' ) ) {
239 $options['kitchen-sink'] = json_decode( file_get_contents( PODS_DIR . 'tests/codeception/_data/kitchen-sink-config.json' ), true );
240 }
241
242 $pod_type = $pod['type'];
243 $pod_name = $pod['name'];
244
245 /**
246 * Add admin fields to the Pod Groups editor for a specific Pod.
247 *
248 * @since 2.8.0
249 *
250 * @param array $options The Options fields.
251 * @param \Pods\Whatsit\Pod $pod Current Pods object.
252 * @param array $tabs List of registered tabs.
253 */
254 $options = apply_filters( "pods_admin_setup_edit_group_options_{$pod_type}_{$pod_name}", $options, $pod, $tabs );
255
256 /**
257 * Add admin fields to the Pod Groups editor for any Pod of a specific content type.
258 *
259 * @since 2.8.0
260 *
261 * @param array $options The Options fields.
262 * @param \Pods\Whatsit\Pod $pod Current Pods object.
263 * @param array $tabs List of registered tabs.
264 */
265 $options = apply_filters( "pods_admin_setup_edit_group_options_{$pod_type}", $options, $pod, $tabs );
266
267 /**
268 * Add admin fields to the Pod Groups editor for all Pods.
269 *
270 * @since 2.8.0
271 *
272 * @param array $options The Options fields.
273 * @param \Pods\Whatsit\Pod $pod Current Pods object.
274 * @param array $tabs List of registered tabs.
275 */
276 $options = apply_filters( 'pods_admin_setup_edit_group_options', $options, $pod, $tabs );
277
278 return $options;
279 }
280 }
281