PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 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 1 day ago Field.php 1 day ago Group.php 1 day ago Pod.php 1 day ago
Group.php
280 lines
1 <?php
2
3 namespace Pods\Admin\Config;
4
5 /**
6 * Group configuration class.
7 *
8 * @since 2.8.0
9 */
10 class Group extends Base {
11
12 /**
13 * Get list of tabs for the Group object.
14 *
15 * @since 2.8.0
16 *
17 * @param \Pods\Whatsit\Pod $pod The pod object.
18 *
19 * @return array List of tabs for the Group object.
20 */
21 public function get_tabs( \Pods\Whatsit\Pod $pod ) {
22 $core_tabs = [
23 'basic' => __( 'Group Details', 'pods' ),
24 'advanced' => __( 'Advanced', 'pods' ),
25 ];
26
27 // Only include kitchen sink if dev mode on and not running Codecept tests.
28 if ( pods_developer() && ! function_exists( 'codecept_debug' ) ) {
29 $core_tabs['kitchen-sink'] = __( 'Kitchen Sink (temp)', 'pods' );
30 }
31
32 $pod_type = $pod['type'];
33 $pod_name = $pod['name'];
34
35 $tabs = $core_tabs;
36
37 /**
38 * Filter the Pod Group option tabs for a specific pod type and name.
39 *
40 * @since 2.8.0
41 *
42 * @param array $core_tabs Tabs to set.
43 * @param \Pods\Whatsit\Pod $pod Current Pods object.
44 */
45 $tabs = (array) apply_filters( "pods_admin_setup_edit_group_tabs_{$pod_type}_{$pod_name}", $tabs, $pod );
46
47 /**
48 * Filter the Pod Group option tabs for a specific pod type.
49 *
50 * @since 2.8.0
51 *
52 * @param array $tabs Tabs to set.
53 * @param \Pods\Whatsit\Pod $pod Current Pods object.
54 */
55 $tabs = (array) apply_filters( "pods_admin_setup_edit_group_tabs_{$pod_type}", $tabs, $pod );
56
57 /**
58 * Filter the Pod Group option tabs.
59 *
60 * @since 2.8.0
61 *
62 * @param array $tabs Tabs to set.
63 * @param \Pods\Whatsit\Pod $pod Current Pods object.
64 */
65 $tabs = (array) apply_filters( 'pods_admin_setup_edit_group_tabs', $tabs, $pod );
66
67 // Sort and then enforce the core tabs to be in front.
68 uksort( $tabs, 'strnatcmp' );
69
70 $tabs = array_merge( $core_tabs, $tabs );
71
72 return $tabs;
73 }
74
75 /**
76 * Get list of fields for the Group object.
77 *
78 * @since 2.8.0
79 *
80 * @param \Pods\Whatsit\Pod $pod The pod object.
81 * @param array $tabs The list of tabs for the pod object.
82 *
83 * @return array List of fields for the Group object.
84 */
85 public function get_fields( \Pods\Whatsit\Pod $pod, array $tabs ) {
86 $options = [];
87
88 $options['basic'] = [
89 'label' => [
90 'name' => 'label',
91 'label' => __( 'Label', 'pods' ),
92 'help' => __( 'help', 'pods' ),
93 'type' => 'text',
94 'required' => true,
95 'default' => '',
96 ],
97 'name' => [
98 'name' => 'name',
99 'label' => __( 'Name', 'pods' ),
100 'help' => __( 'help', 'pods' ),
101 'type' => 'slug',
102 'required' => true,
103 'default' => '',
104 ],
105 /*'description' => [
106 'name' => 'description',
107 'label' => __( 'Description', 'pods' ),
108 'help' => __( 'help', 'pods' ),
109 'type' => 'text',
110 'default' => '',
111 ],*/
112 /*'type' => [
113 'name' => 'type',
114 'label' => __( 'Type', 'pods' ),
115 'help' => __( 'help', 'pods' ),
116 'type' => 'pick',
117 'default' => '',
118 'data' => [],
119 ],*/
120 ];
121
122 $options['advanced'] = [
123 'visibility' => [
124 'name' => 'visibility',
125 'label' => __( 'Visibility', 'pods' ),
126 'type' => 'heading',
127 ],
128 'restrict_access' => [
129 'type' => 'boolean_group',
130 'name' => 'restrict_access',
131 'label' => __( 'Restrict Access', 'pods' ),
132 'boolean_group' => [
133 'logged_in' => [
134 'name' => 'logged_in',
135 'label' => __( 'Restrict access to Logged In Users', 'pods' ),
136 'default' => 0,
137 'type' => 'boolean',
138 'dependency' => true,
139 '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' ),
140 ],
141 'admin_only' => [
142 'name' => 'admin_only',
143 'label' => __( 'Restrict access to Admins', 'pods' ),
144 'default' => 0,
145 'type' => 'boolean',
146 'dependency' => true,
147 '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' ),
148 ],
149 'restrict_role' => [
150 'name' => 'restrict_role',
151 'label' => __( 'Restrict access by Role', 'pods' ),
152 'default' => 0,
153 'type' => 'boolean',
154 'dependency' => true,
155 ],
156 'restrict_capability' => [
157 'name' => 'restrict_capability',
158 'label' => __( 'Restrict access by Capability', 'pods' ),
159 'default' => 0,
160 'type' => 'boolean',
161 'dependency' => true,
162 ],
163 ],
164 ],
165 'roles_allowed' => [
166 'name' => 'roles_allowed',
167 'label' => __( 'Role(s) Allowed', 'pods' ),
168 'help' => __( 'help', 'pods' ),
169 'type' => 'pick',
170 'pick_object' => 'role',
171 'pick_format_type' => 'multi',
172 'default' => 'administrator',
173 'depends-on' => [
174 'restrict_role' => true,
175 ],
176 'help' => __( 'If none are selected, this option will be ignored.', 'pods' ),
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 'help' => __( 'If none are selected, this option will be ignored.', 'pods' ),
188 ],
189 ];
190
191 $object_type = $pod->get_type();
192
193 $is_post_type = 'post_type' === $object_type;
194 $is_comment_type = 'comment' === $object_type;
195
196 if ( $is_post_type || $is_comment_type ) {
197 $options['basic']['meta_box_context'] = [
198 'name' => 'meta_box_context',
199 'label' => __( 'Meta Box Context', 'pods' ),
200 'help' => [
201 __( 'See add_meta_box() documentation.', 'pods' ),
202 'https://developer.wordpress.org/reference/functions/add_meta_box/#parameters',
203 ],
204 'type' => 'pick',
205 'default' => 'normal',
206 'data' => [
207 'normal' => __( 'Normal', 'pods' ),
208 'side' => __( 'Side', 'pods' ),
209 'advanced' => __( 'Advanced', 'pods' ),
210 ],
211 'pick_show_select_text' => 0,
212 ];
213
214 if ( $is_comment_type ) {
215 unset( $options['basic']['group_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_show_select_text' => 0,
233 ];
234 }
235
236 // Only include kitchen sink if dev mode on and not running Codecept tests.
237 if ( pods_developer() && ! function_exists( 'codecept_debug' ) ) {
238 $options['kitchen-sink'] = json_decode( file_get_contents( PODS_DIR . 'tests/codeception/_data/kitchen-sink-config.json' ), true );
239 }
240
241 $pod_type = $pod['type'];
242 $pod_name = $pod['name'];
243
244 /**
245 * Add admin fields to the Pod Groups editor for a specific Pod.
246 *
247 * @since 2.8.0
248 *
249 * @param array $options The Options fields.
250 * @param \Pods\Whatsit\Pod $pod Current Pods object.
251 * @param array $tabs List of registered tabs.
252 */
253 $options = apply_filters( "pods_admin_setup_edit_group_options_{$pod_type}_{$pod_name}", $options, $pod, $tabs );
254
255 /**
256 * Add admin fields to the Pod Groups editor for any Pod of a specific content type.
257 *
258 * @since 2.8.0
259 *
260 * @param array $options The Options fields.
261 * @param \Pods\Whatsit\Pod $pod Current Pods object.
262 * @param array $tabs List of registered tabs.
263 */
264 $options = apply_filters( "pods_admin_setup_edit_group_options_{$pod_type}", $options, $pod, $tabs );
265
266 /**
267 * Add admin fields to the Pod Groups editor for all Pods.
268 *
269 * @since 2.8.0
270 *
271 * @param array $options The Options fields.
272 * @param \Pods\Whatsit\Pod $pod Current Pods object.
273 * @param array $tabs List of registered tabs.
274 */
275 $options = apply_filters( 'pods_admin_setup_edit_group_options', $options, $pod, $tabs );
276
277 return $options;
278 }
279 }
280