Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PodsAdmin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PodsAdmin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class PodsAdmin { |
||
6 | |||
7 | /** |
||
8 | * @var PodsAdmin |
||
9 | */ |
||
10 | static $instance = null; |
||
|
|||
11 | |||
12 | /** |
||
13 | * Singleton handling for a basic pods_admin() request |
||
14 | * |
||
15 | * @return \PodsAdmin |
||
16 | * |
||
17 | * @since 2.3.5 |
||
18 | */ |
||
19 | public static function init () { |
||
20 | if ( !is_object( self::$instance ) ) |
||
21 | self::$instance = new PodsAdmin(); |
||
22 | |||
23 | return self::$instance; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Setup and Handle Admin functionality |
||
28 | * |
||
29 | * @return \PodsAdmin |
||
30 | * |
||
31 | * @license http://www.gnu.org/licenses/gpl-2.0.html |
||
32 | * @since 2.0 |
||
33 | */ |
||
34 | public function __construct () { |
||
35 | // Scripts / Stylesheets |
||
36 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 ); |
||
37 | |||
38 | // AJAX $_POST fix |
||
39 | add_action( 'admin_init', array( $this, 'admin_init' ), 9 ); |
||
40 | |||
41 | // Menus |
||
42 | add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 ); |
||
43 | |||
44 | // AJAX for Admin |
||
45 | add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) ); |
||
46 | add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) ); |
||
47 | |||
48 | // Add Media Bar button for Shortcode |
||
49 | add_action( 'media_buttons', array( $this, 'media_button' ), 12 ); |
||
50 | |||
51 | // Add the Pods capabilities |
||
52 | add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) ); |
||
53 | |||
54 | add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) ); |
||
55 | |||
56 | $this->rest_admin(); |
||
57 | |||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Init the admin area |
||
62 | * |
||
63 | * @since 2.0 |
||
64 | */ |
||
65 | public function admin_init () { |
||
66 | // Fix for plugins that *don't do it right* so we don't cause issues for users |
||
67 | if ( defined( 'DOING_AJAX' ) && !empty( $_POST ) ) { |
||
68 | $pods_admin_ajax_actions = array( |
||
69 | 'pods_admin', |
||
70 | 'pods_relationship', |
||
71 | 'pods_upload', |
||
72 | 'pods_admin_components' |
||
73 | ); |
||
74 | |||
75 | /** |
||
76 | * Admin AJAX Callbacks |
||
77 | * |
||
78 | * @since unknown |
||
79 | * |
||
80 | * @param array $pods_admin_ajax_actions Array of actions to handle |
||
81 | */ |
||
82 | $pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions ); |
||
83 | |||
84 | if ( in_array( pods_var( 'action', 'get' ), $pods_admin_ajax_actions ) || in_array( pods_var( 'action', 'post' ), $pods_admin_ajax_actions ) ) { |
||
85 | foreach ( $_POST as $key => $value ) { |
||
86 | if ( 'action' == $key || 0 === strpos( $key, '_podsfix_' ) ) |
||
87 | continue; |
||
88 | |||
89 | unset( $_POST[ $key ] ); |
||
90 | |||
91 | $_POST[ '_podsfix_' . $key ] = $value; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Attach requirements to admin header |
||
99 | * |
||
100 | * @since 2.0 |
||
101 | */ |
||
102 | public function admin_head () { |
||
103 | wp_register_style( 'pods-admin', PODS_URL . 'ui/css/pods-admin.css', array(), PODS_VERSION ); |
||
104 | |||
105 | wp_register_style( 'pods-font', PODS_URL . 'ui/css/pods-font.css', array(), PODS_VERSION ); |
||
106 | |||
107 | wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION ); |
||
108 | |||
109 | wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION ); |
||
110 | |||
111 | wp_register_style( 'pods-manage', PODS_URL . 'ui/css/pods-manage.css', array(), PODS_VERSION ); |
||
112 | |||
113 | wp_register_style( 'pods-wizard', PODS_URL . 'ui/css/pods-wizard.css', array(), PODS_VERSION ); |
||
114 | |||
115 | wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION ); |
||
116 | |||
117 | wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION ); |
||
118 | |||
119 | if ( isset( $_GET[ 'page' ] ) ) { |
||
120 | $page = $_GET[ 'page' ]; |
||
121 | if ( 'pods' == $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) { |
||
122 | ?> |
||
123 | <script type="text/javascript"> |
||
124 | var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>"; |
||
125 | </script> |
||
126 | <?php |
||
127 | wp_enqueue_script( 'jquery' ); |
||
128 | wp_enqueue_script( 'jquery-ui-core' ); |
||
129 | wp_enqueue_script( 'jquery-ui-sortable' ); |
||
130 | |||
131 | wp_enqueue_style( 'jquery-ui' ); |
||
132 | |||
133 | wp_enqueue_script( 'pods-floatmenu' ); |
||
134 | |||
135 | wp_enqueue_style( 'jquery-qtip2' ); |
||
136 | wp_enqueue_script( 'jquery-qtip2' ); |
||
137 | wp_enqueue_script( 'pods-qtip-init' ); |
||
138 | |||
139 | wp_enqueue_script( 'pods' ); |
||
140 | |||
141 | if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) ) |
||
142 | wp_enqueue_script( 'post' ); |
||
143 | elseif ( 0 === strpos( $page, 'pods-settings-' ) ) { |
||
144 | wp_enqueue_script( 'post' ); |
||
145 | wp_enqueue_style( 'pods-admin' ); |
||
146 | } |
||
147 | else |
||
148 | wp_enqueue_style( 'pods-admin' ); |
||
149 | |||
150 | if ( 'pods-advanced' == $page ) { |
||
151 | wp_register_style( 'pods-advanced', PODS_URL . 'ui/css/pods-advanced.css', array(), '1.0' ); |
||
152 | wp_enqueue_style( 'pods-advanced' ); |
||
153 | |||
154 | wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' ); |
||
155 | wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' ); |
||
156 | wp_enqueue_script( 'jquery-ui-dialog' ); |
||
157 | |||
158 | wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION ); |
||
159 | wp_enqueue_script( 'pods-advanced' ); |
||
160 | } |
||
161 | elseif ( 'pods-packages' == $page ) |
||
162 | wp_enqueue_style( 'pods-wizard' ); |
||
163 | elseif ( 'pods-wizard' == $page || 'pods-upgrade' == $page || ( in_array( $page, array( 'pods', 'pods-add-new' ) ) && in_array( pods_var( 'action', 'get', 'manage' ), array( 'add', 'manage' ) ) ) ) { |
||
164 | wp_enqueue_style( 'pods-wizard' ); |
||
165 | |||
166 | if ( 'pods-upgrade' == $page ) |
||
167 | wp_enqueue_script( 'pods-upgrade' ); |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | |||
172 | // Flexible Relationships |
||
173 | if ( pods_is_modal_window() ) { |
||
174 | wp_enqueue_style( 'pods-modal-relationships', PODS_URL . 'ui/css/pods-modal-relationships.css', array(), '1.0' ); |
||
175 | } |
||
176 | |||
177 | wp_enqueue_style( 'pods-font' ); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Build the admin menus |
||
182 | * |
||
183 | * @since 2.0 |
||
184 | */ |
||
185 | public function admin_menu () { |
||
186 | $advanced_content_types = PodsMeta::$advanced_content_types; |
||
187 | $taxonomies = PodsMeta::$taxonomies; |
||
188 | $settings = PodsMeta::$settings; |
||
189 | |||
190 | $all_pods = pods_api()->load_pods( array( 'count' => true ) ); |
||
191 | |||
192 | if ( !PodsInit::$upgrade_needed || ( pods_is_admin() && 1 == pods_var( 'pods_upgrade_bypass' ) ) ) { |
||
193 | $submenu_items = array(); |
||
194 | |||
195 | if ( !empty( $advanced_content_types ) ) { |
||
196 | $submenu = array(); |
||
197 | |||
198 | $pods_pages = 0; |
||
199 | |||
200 | foreach ( (array) $advanced_content_types as $pod ) { |
||
201 | if ( !isset( $pod[ 'name' ] ) || !isset( $pod[ 'options' ] ) || empty( $pod[ 'fields' ] ) ) |
||
202 | continue; |
||
203 | elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) |
||
204 | continue; |
||
205 | |||
206 | $pod = apply_filters( 'pods_advanced_content_type_pod_data_' . $pod['name'], $pod, $pod['name'] ); |
||
207 | $pod = apply_filters( 'pods_advanced_content_type_pod_data', $pod, $pod['name'] ); |
||
208 | |||
209 | if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) { |
||
210 | $page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), true ); |
||
211 | $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); |
||
212 | |||
213 | $menu_label = pods_v( 'menu_name', $pod[ 'options' ], $page_title, true ); |
||
214 | $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); |
||
215 | |||
216 | $singular_label = pods_v( 'label_singular', $pod[ 'options' ], pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), true ), true ); |
||
217 | $plural_label = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), true ); |
||
218 | |||
219 | $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' ); |
||
220 | $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
||
221 | |||
222 | $menu_position = pods_v( 'menu_position', $pod[ 'options' ], '', true ); |
||
223 | $menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod[ 'options' ], '', true ), true ); |
||
224 | |||
225 | if ( empty( $menu_position ) ) |
||
226 | $menu_position = null; |
||
227 | |||
228 | $parent_page = null; |
||
229 | |||
230 | if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) { |
||
231 | if ( !empty( $menu_location_custom ) ) { |
||
232 | if ( !isset( $submenu_items[ $menu_location_custom ] ) ) |
||
233 | $submenu_items[ $menu_location_custom ] = array(); |
||
234 | |||
235 | $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', 'pods-manage-' . $pod[ 'name' ], array( $this, 'admin_content' ) ); |
||
236 | |||
237 | continue; |
||
238 | } |
||
239 | else { |
||
240 | $pods_pages++; |
||
241 | |||
242 | $parent_page = $page = 'pods-manage-' . $pod[ 'name' ]; |
||
243 | |||
244 | if ( empty( $menu_position ) ) |
||
245 | $menu_position = null; |
||
246 | add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position ); |
||
247 | |||
248 | $all_title = $plural_label; |
||
249 | $all_label = pods_v( 'label_all_items', $pod[ 'options' ], __( 'All', 'pods' ) . ' ' . $plural_label ); |
||
250 | |||
251 | if ( $page == pods_var( 'page', 'get' ) ) { |
||
252 | if ( 'edit' == pods_var( 'action', 'get', 'manage' ) ) |
||
253 | $all_title = pods_v( 'label_edit_item', $pod[ 'options' ], __( 'Edit', 'pods' ) . ' ' . $singular_label ); |
||
254 | elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) ) |
||
255 | $all_title = pods_v( 'label_add_new_item', $pod[ 'options' ], __( 'Add New', 'pods' ) . ' ' . $singular_label ); |
||
256 | } |
||
257 | |||
258 | add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) ); |
||
259 | } |
||
260 | } |
||
261 | |||
262 | if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) ) { |
||
263 | $page = 'pods-add-new-' . $pod[ 'name' ]; |
||
264 | |||
265 | if ( null === $parent_page ) { |
||
266 | $pods_pages++; |
||
267 | |||
268 | $parent_page = $page; |
||
269 | |||
270 | if ( empty( $menu_position ) ) |
||
271 | $menu_position = null; |
||
272 | add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position ); |
||
273 | } |
||
274 | |||
275 | $add_title = pods_v( 'label_add_new_item', $pod[ 'options' ], __( 'Add New', 'pods' ) . ' ' . $singular_label ); |
||
276 | $add_label = pods_v( 'label_add_new', $pod[ 'options' ], __( 'Add New', 'pods' ) ); |
||
277 | |||
278 | add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) ); |
||
279 | } |
||
280 | } |
||
281 | else |
||
282 | $submenu[] = $pod; |
||
283 | } |
||
284 | |||
285 | $submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu ); |
||
286 | |||
287 | if ( !empty( $submenu ) && ( !defined( 'PODS_DISABLE_CONTENT_MENU' ) || !PODS_DISABLE_CONTENT_MENU ) ) { |
||
288 | $parent_page = null; |
||
289 | |||
290 | foreach ( $submenu as $item ) { |
||
291 | $singular_label = pods_var_raw( 'label_singular', $item[ 'options' ], pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ), null, true ); |
||
292 | $plural_label = pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ); |
||
293 | |||
294 | if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $item[ 'name' ], 'pods_delete_' . $item[ 'name' ] ) ) ) { |
||
295 | $page = 'pods-manage-' . $item[ 'name' ]; |
||
296 | |||
297 | if ( null === $parent_page ) { |
||
298 | $parent_page = $page; |
||
299 | |||
300 | add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' ); |
||
301 | } |
||
302 | |||
303 | $all_title = $plural_label; |
||
304 | $all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label; |
||
305 | |||
306 | if ( $page == pods_var( 'page', 'get' ) ) { |
||
307 | if ( 'edit' == pods_var( 'action', 'get', 'manage' ) ) |
||
308 | $all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label; |
||
309 | elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) ) |
||
310 | $all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; |
||
311 | } |
||
312 | |||
313 | add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) ); |
||
314 | } |
||
315 | elseif ( current_user_can( 'pods_add_' . $item[ 'name' ] ) ) { |
||
316 | $page = 'pods-add-new-' . $item[ 'name' ]; |
||
317 | |||
318 | if ( null === $parent_page ) { |
||
319 | $parent_page = $page; |
||
320 | |||
321 | add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' ); |
||
322 | } |
||
323 | |||
324 | $add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; |
||
325 | $add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label; |
||
326 | |||
327 | add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) ); |
||
328 | } |
||
329 | } |
||
330 | } |
||
331 | } |
||
332 | |||
333 | if ( !empty( $taxonomies ) ) { |
||
334 | foreach ( (array) $taxonomies as $pod ) { |
||
335 | // Default taxonomy capability |
||
336 | $capability = 'manage_categories'; |
||
337 | |||
338 | if ( ! empty( $pod[ 'options' ][ 'capability_type' ] ) ) { |
||
339 | if ( 'custom' == $pod[ 'options' ][ 'capability_type' ] && ! empty( $pod[ 'options' ][ 'capability_type_custom' ] ) ) { |
||
340 | $capability = 'manage_' . (string) $pod[ 'options' ][ 'capability_type_custom' ] . '_terms'; |
||
341 | } |
||
342 | } |
||
343 | |||
344 | if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], $capability ) ) ) |
||
345 | continue; |
||
346 | |||
347 | // Check UI settings |
||
348 | if ( 1 != pods_var( 'show_ui', $pod[ 'options' ], 0 ) || 1 != pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) |
||
349 | continue; |
||
350 | |||
351 | $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); |
||
352 | $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); |
||
353 | |||
354 | $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); |
||
355 | $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); |
||
356 | |||
357 | $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); |
||
358 | $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); |
||
359 | |||
360 | if ( empty( $menu_position ) ) |
||
361 | $menu_position = null; |
||
362 | |||
363 | $menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ]; |
||
364 | $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' ); |
||
365 | $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
||
366 | |||
367 | if ( 'default' == $menu_location ) |
||
368 | continue; |
||
369 | |||
370 | $taxonomy_data = get_taxonomy( $pod[ 'name' ] ); |
||
371 | |||
372 | foreach ( (array) $taxonomy_data->object_type as $post_type ) { |
||
373 | if ( 'post' == $post_type ) |
||
374 | remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] ); |
||
375 | elseif ( 'attachment' == $post_type ) |
||
376 | remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type ); |
||
377 | else |
||
378 | remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type ); |
||
379 | } |
||
380 | |||
381 | if ( 'settings' == $menu_location ) |
||
382 | add_options_page( $page_title, $menu_label, 'read', $menu_slug ); |
||
383 | elseif ( 'appearances' == $menu_location ) |
||
384 | add_theme_page( $page_title, $menu_label, 'read', $menu_slug ); |
||
385 | elseif ( 'objects' == $menu_location ) { |
||
386 | if ( empty( $menu_position ) ) |
||
387 | $menu_position = null; |
||
388 | add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position ); |
||
389 | } |
||
390 | elseif ( 'top' == $menu_location ) |
||
391 | add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position ); |
||
392 | elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { |
||
393 | if ( !isset( $submenu_items[ $menu_location_custom ] ) ) |
||
394 | $submenu_items[ $menu_location_custom ] = array(); |
||
395 | |||
396 | $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, '' ); |
||
397 | } |
||
398 | } |
||
399 | } |
||
400 | |||
401 | if ( !empty( $settings ) ) { |
||
402 | foreach ( (array) $settings as $pod ) { |
||
403 | if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) ) |
||
404 | continue; |
||
405 | |||
406 | $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); |
||
407 | $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); |
||
408 | |||
409 | $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); |
||
410 | $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); |
||
411 | |||
412 | $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); |
||
413 | $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); |
||
414 | |||
415 | if ( empty( $menu_position ) ) |
||
416 | $menu_position = null; |
||
417 | |||
418 | $menu_slug = 'pods-settings-' . $pod[ 'name' ]; |
||
419 | $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'settings' ); |
||
420 | $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
||
421 | |||
422 | if ( 'settings' == $menu_location ) |
||
423 | add_options_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); |
||
424 | elseif ( 'appearances' == $menu_location ) |
||
425 | add_theme_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); |
||
426 | elseif ( 'objects' == $menu_location ) { |
||
427 | if ( empty( $menu_position ) ) |
||
428 | $menu_position = null; |
||
429 | add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position ); |
||
430 | } |
||
431 | elseif ( 'top' == $menu_location ) |
||
432 | add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position ); |
||
433 | elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { |
||
434 | if ( !isset( $submenu_items[ $menu_location_custom ] ) ) |
||
435 | $submenu_items[ $menu_location_custom ] = array(); |
||
436 | |||
437 | $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); |
||
438 | } |
||
439 | } |
||
440 | } |
||
441 | |||
442 | foreach ( $submenu_items as $items ) { |
||
443 | foreach ( $items as $item ) { |
||
444 | call_user_func_array( 'add_submenu_page', $item ); |
||
445 | } |
||
446 | } |
||
447 | |||
448 | $admin_menus = array( |
||
449 | 'pods' => array( |
||
450 | 'label' => __( 'Edit Pods', 'pods' ), |
||
451 | 'function' => array( $this, 'admin_setup' ), |
||
452 | 'access' => 'pods' |
||
453 | ), |
||
454 | 'pods-add-new' => array( |
||
455 | 'label' => __( 'Add New', 'pods' ), |
||
456 | 'function' => array( $this, 'admin_setup' ), |
||
457 | 'access' => 'pods' |
||
458 | ), |
||
459 | 'pods-components' => array( |
||
460 | 'label' => __( 'Components', 'pods' ), |
||
461 | 'function' => array( $this, 'admin_components' ), |
||
462 | 'access' => 'pods_components' |
||
463 | ), |
||
464 | 'pods-settings' => array( |
||
465 | 'label' => __( 'Settings', 'pods' ), |
||
466 | 'function' => array( $this, 'admin_settings' ), |
||
467 | 'access' => 'pods_settings' |
||
468 | ), |
||
469 | 'pods-help' => array( |
||
470 | 'label' => __( 'Help', 'pods' ), |
||
471 | 'function' => array( $this, 'admin_help' ) |
||
472 | ) |
||
473 | ); |
||
474 | |||
475 | if ( empty( $all_pods ) ) |
||
476 | unset( $admin_menus[ 'pods' ] ); |
||
477 | |||
478 | add_filter( 'parent_file' , array( $this, 'parent_file' ) ); |
||
479 | } |
||
480 | else { |
||
481 | $admin_menus = array( |
||
482 | 'pods-upgrade' => array( |
||
483 | 'label' => __( 'Upgrade', 'pods' ), |
||
484 | 'function' => array( $this, 'admin_upgrade' ), |
||
485 | 'access' => 'manage_options' |
||
486 | ), |
||
487 | 'pods-settings' => array( |
||
488 | 'label' => __( 'Settings', 'pods' ), |
||
489 | 'function' => array( $this, 'admin_settings' ), |
||
490 | 'access' => 'pods_settings' |
||
491 | ), |
||
492 | 'pods-help' => array( |
||
493 | 'label' => __( 'Help', 'pods' ), |
||
494 | 'function' => array( $this, 'admin_help' ) |
||
495 | ) |
||
496 | ); |
||
497 | |||
498 | add_action( 'admin_notices', array( $this, 'upgrade_notice' ) ); |
||
499 | } |
||
500 | |||
501 | /** |
||
502 | * Add or change Pods Admin menu items |
||
503 | * |
||
504 | * @params array $admin_menus The submenu items in Pods Admin menu. |
||
505 | * |
||
506 | * @since unknown |
||
507 | */ |
||
508 | $admin_menus = apply_filters( 'pods_admin_menu', $admin_menus ); |
||
509 | |||
510 | $parent = false; |
||
511 | |||
512 | // PODS_LIGHT disables all Pods components so remove the components menu |
||
513 | if ( defined( 'PODS_LIGHT' ) && true == PODS_LIGHT ) { |
||
514 | unset( $admin_menus['pods-components'] ); |
||
515 | } |
||
516 | |||
517 | if ( !empty( $admin_menus ) && ( !defined( 'PODS_DISABLE_ADMIN_MENU' ) || !PODS_DISABLE_ADMIN_MENU ) ) { |
||
518 | foreach ( $admin_menus as $page => $menu_item ) { |
||
519 | if ( !pods_is_admin( pods_var_raw( 'access', $menu_item ) ) ) |
||
520 | continue; |
||
521 | |||
522 | // Don't just show the help page |
||
523 | if ( false === $parent && 'pods-help' == $page ) |
||
524 | continue; |
||
525 | |||
526 | if ( !isset( $menu_item[ 'label' ] ) ) |
||
527 | $menu_item[ 'label' ] = $page; |
||
528 | |||
529 | if ( false === $parent ) { |
||
530 | $parent = $page; |
||
531 | |||
532 | $menu = __( 'Pods Admin', 'pods' ); |
||
533 | |||
534 | if ( 'pods-upgrade' == $parent ) |
||
535 | $menu = __( 'Pods Upgrade', 'pods' ); |
||
536 | |||
537 | add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' ); |
||
538 | } |
||
539 | |||
540 | add_submenu_page( $parent, $menu_item[ 'label' ], $menu_item[ 'label' ], 'read', $page, $menu_item[ 'function' ] ); |
||
541 | |||
542 | if ( 'pods-components' == $page && is_object( PodsInit::$components ) ) |
||
543 | PodsInit::$components->menu( $parent ); |
||
544 | } |
||
545 | } |
||
546 | } |
||
547 | |||
548 | /** |
||
549 | * Set the correct parent_file to highlight the correct top level menu |
||
550 | * |
||
551 | * @param $parent_file The parent file |
||
552 | * |
||
553 | * @return mixed|string |
||
554 | * |
||
555 | * @since unknown |
||
556 | */ |
||
557 | public function parent_file ( $parent_file ) { |
||
558 | global $current_screen; |
||
559 | |||
560 | if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) { |
||
561 | $taxonomies = PodsMeta::$taxonomies; |
||
562 | if ( !empty( $taxonomies ) ) { |
||
563 | foreach ( (array) $taxonomies as $pod ) { |
||
564 | if ( $current_screen->taxonomy !== $pod[ 'name' ] ) |
||
565 | continue; |
||
566 | |||
567 | $menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ]; |
||
568 | $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' ); |
||
569 | $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
||
570 | |||
571 | if ( 'settings' == $menu_location ) |
||
572 | $parent_file = 'options-general.php'; |
||
573 | elseif ( 'appearances' == $menu_location ) |
||
574 | $parent_file = 'themes.php'; |
||
575 | elseif ( 'objects' == $menu_location ) |
||
576 | $parent_file = $menu_slug; |
||
577 | elseif ( 'top' == $menu_location ) |
||
578 | $parent_file = $menu_slug; |
||
579 | elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { |
||
580 | $parent_file = $menu_location_custom; |
||
581 | } |
||
582 | |||
583 | break; |
||
584 | } |
||
585 | } |
||
586 | } |
||
587 | |||
588 | if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) && is_object( PodsInit::$components ) ) { |
||
589 | global $submenu_file; |
||
590 | $components = PodsInit::$components->components; |
||
591 | foreach ( $components as $component => $component_data ) { |
||
592 | if ( ! empty( $component_data[ 'MenuPage' ] ) && $parent_file === $component_data[ 'MenuPage' ] ) { |
||
593 | $parent_file = 'pods'; |
||
594 | $submenu_file = $component_data[ 'MenuPage' ]; |
||
595 | } |
||
596 | } |
||
597 | } |
||
598 | |||
599 | return $parent_file; |
||
600 | } |
||
601 | |||
602 | public function upgrade_notice () { |
||
603 | echo '<div class="error fade"><p>'; |
||
604 | echo sprintf( |
||
605 | __( '<strong>NOTICE:</strong> Pods %s requires your action to complete the upgrade. Please run the <a href="%s">Upgrade Wizard</a>.', 'pods' ), |
||
606 | esc_html( PODS_VERSION ), |
||
607 | esc_url( admin_url( 'admin.php?page=pods-upgrade' ) ) |
||
608 | ); |
||
609 | echo '</p></div>'; |
||
610 | } |
||
611 | |||
612 | /** |
||
613 | * Create PodsUI content for the administration pages |
||
614 | */ |
||
615 | public function admin_content () { |
||
616 | $pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET[ 'page' ] ); |
||
617 | |||
618 | $pod = pods( $pod_name, pods_var( 'id', 'get', null, null, true ) ); |
||
619 | |||
620 | if ( false !== strpos( $_GET[ 'page' ], 'pods-add-new-' ) ) |
||
621 | $_GET[ 'action' ] = pods_var( 'action', 'get', 'add' ); |
||
622 | |||
623 | $pod->ui(); |
||
624 | } |
||
625 | |||
626 | /** |
||
627 | * Create PodsUI content for the settings administration pages |
||
628 | */ |
||
629 | public function admin_content_settings () { |
||
630 | $pod_name = str_replace( 'pods-settings-', '', $_GET[ 'page' ] ); |
||
631 | |||
632 | $pod = pods( $pod_name ); |
||
633 | |||
634 | if ( 'custom' != pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ) ) { |
||
635 | $actions_disabled = array( |
||
636 | 'manage' => 'manage', |
||
637 | 'add' => 'add', |
||
638 | 'delete' => 'delete', |
||
639 | 'duplicate' => 'duplicate', |
||
640 | 'view' => 'view', |
||
641 | 'export' => 'export' |
||
642 | ); |
||
643 | |||
644 | $_GET[ 'action' ] = 'edit'; |
||
645 | |||
646 | $page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true ); |
||
647 | $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod->pod_data ); |
||
648 | |||
649 | $ui = array( |
||
650 | 'pod' => $pod, |
||
651 | 'fields' => array( |
||
652 | 'edit' => $pod->pod_data[ 'fields' ] |
||
653 | ), |
||
654 | 'header' => array( |
||
655 | 'edit' => $page_title |
||
656 | ), |
||
657 | 'label' => array( |
||
658 | 'edit' => __( 'Save Changes', 'pods' ) |
||
659 | ), |
||
660 | 'style' => pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ), |
||
661 | 'icon' => pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod->pod_data[ 'options' ] ), true ), |
||
662 | 'actions_disabled' => $actions_disabled |
||
663 | ); |
||
664 | |||
665 | $ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod ); |
||
666 | |||
667 | // Force disabled actions, do not pass go, do not collect $two_hundred |
||
668 | $ui[ 'actions_disabled' ] = $actions_disabled; |
||
669 | |||
670 | pods_ui( $ui ); |
||
671 | } |
||
672 | else { |
||
673 | do_action( 'pods_admin_ui_custom', $pod ); |
||
674 | do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod ); |
||
675 | } |
||
676 | } |
||
677 | |||
678 | /** |
||
679 | * Add media button for Pods shortcode |
||
680 | * |
||
681 | * @param $context |
||
682 | * |
||
683 | * @return string |
||
684 | */ |
||
685 | public function media_button ( $context = null ) { |
||
686 | // If shortcodes are disabled don't show the button |
||
687 | if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) { |
||
688 | return ''; |
||
689 | } |
||
690 | |||
691 | /** |
||
692 | * Filter to remove Pods shortcode button from the post editor. |
||
693 | * |
||
694 | * @param bool. Set to false to block the shortcode button from appearing. |
||
695 | * @param string $context |
||
696 | * |
||
697 | * @since 2.3.19 |
||
698 | */ |
||
699 | if ( !apply_filters( 'pods_admin_media_button', true, $context ) ) { |
||
700 | return ''; |
||
701 | } |
||
702 | |||
703 | $current_page = basename( $_SERVER[ 'PHP_SELF' ] ); |
||
704 | $current_page = explode( '?', $current_page ); |
||
705 | $current_page = explode( '#', $current_page[ 0 ] ); |
||
706 | $current_page = $current_page[ 0 ]; |
||
707 | |||
708 | // Only show the button on post type pages |
||
709 | if ( !in_array( $current_page, array( 'post-new.php', 'post.php' ) ) ) |
||
710 | return ''; |
||
711 | |||
712 | add_action( 'admin_footer', array( $this, 'mce_popup' ) ); |
||
713 | |||
714 | echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox button" id="add_pod_button" title="Pods Shortcode"><img style="padding: 0px 6px 0px 0px; margin: -3px 0px 0px;" src="' . PODS_URL . 'ui/images/icon16.png" alt="' . __('Pods Shortcode' ,'pods') . '" />' . __('Pods Shortcode' ,'pods') . '</a>'; |
||
715 | } |
||
716 | |||
717 | /** |
||
718 | * Enqueue assets for Media Library Popup |
||
719 | */ |
||
720 | public function register_media_assets () { |
||
721 | if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) ) |
||
722 | wp_enqueue_style( 'pods-flex' ); |
||
723 | } |
||
724 | |||
725 | /** |
||
726 | * Output Pods shortcode popup window |
||
727 | */ |
||
728 | public function mce_popup () { |
||
729 | pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) ); |
||
730 | } |
||
731 | |||
732 | /** |
||
733 | * Handle main Pods Setup area for managing Pods and Fields |
||
734 | */ |
||
735 | public function admin_setup () { |
||
736 | $pods = pods_api()->load_pods( array( 'fields' => false ) ); |
||
737 | |||
738 | $view = pods_var( 'view', 'get', 'all', null, true ); |
||
739 | |||
740 | if ( empty( $pods ) && !isset( $_GET[ 'action' ] ) ) |
||
741 | $_GET[ 'action' ] = 'add'; |
||
742 | |||
743 | if ( 'pods-add-new' == $_GET[ 'page' ] ) { |
||
744 | if ( isset( $_GET[ 'action' ] ) && 'add' != $_GET[ 'action' ] ) |
||
745 | pods_redirect( pods_query_arg( array( 'page' => 'pods', 'action' => $_GET[ 'action' ] ) ) ); |
||
746 | else |
||
747 | $_GET[ 'action' ] = 'add'; |
||
748 | } |
||
749 | elseif ( isset( $_GET[ 'action' ] ) && 'add' == $_GET[ 'action' ] ) |
||
750 | pods_redirect( pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '' ) ) ); |
||
751 | |||
752 | $types = array( |
||
753 | 'post_type' => __( 'Post Type (extended)', 'pods' ), |
||
754 | 'taxonomy' => __( 'Taxonomy (extended)', 'pods' ), |
||
755 | 'cpt' => __( 'Custom Post Type', 'pods' ), |
||
756 | 'ct' => __( 'Custom Taxonomy', 'pods' ), |
||
757 | 'user' => __( 'User (extended)', 'pods' ), |
||
758 | 'media' => __( 'Media (extended)', 'pods' ), |
||
759 | 'comment' => __( 'Comments (extended)', 'pods' ), |
||
760 | 'pod' => __( 'Advanced Content Type', 'pods' ), |
||
761 | 'settings' => __( 'Custom Settings Page', 'pods' ) |
||
762 | ); |
||
763 | |||
764 | $row = false; |
||
765 | |||
766 | $pod_types_found = array(); |
||
767 | |||
768 | $fields = array( |
||
769 | 'label' => array( 'label' => __( 'Label', 'pods' ) ), |
||
770 | 'name' => array( 'label' => __( 'Name', 'pods' ) ), |
||
771 | 'type' => array( 'label' => __( 'Type', 'pods' ) ), |
||
772 | 'storage' => array( |
||
773 | 'label' => __( 'Storage Type', 'pods' ), |
||
774 | 'width' => '10%' |
||
775 | ), |
||
776 | 'field_count' => array( |
||
777 | 'label' => __( 'Number of Fields', 'pods' ), |
||
778 | 'width' => '8%' |
||
779 | ) |
||
780 | ); |
||
781 | |||
782 | $total_fields = 0; |
||
783 | |||
784 | foreach ( $pods as $k => $pod ) { |
||
785 | if ( isset( $types[ $pod[ 'type' ] ] ) ) { |
||
786 | if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) { |
||
787 | if ( empty( $pod[ 'object' ] ) ) { |
||
788 | if ( 'post_type' == $pod[ 'type' ] ) |
||
789 | $pod[ 'type' ] = 'cpt'; |
||
790 | else |
||
791 | $pod[ 'type' ] = 'ct'; |
||
792 | } |
||
793 | } |
||
794 | |||
795 | if ( !isset( $pod_types_found[ $pod[ 'type' ] ] ) ) |
||
796 | $pod_types_found[ $pod[ 'type' ] ] = 1; |
||
797 | else |
||
798 | $pod_types_found[ $pod[ 'type' ] ]++; |
||
799 | |||
800 | if ( 'all' != $view && $view != $pod[ 'type' ] ) { |
||
801 | unset( $pods[ $k ] ); |
||
802 | |||
803 | continue; |
||
804 | } |
||
805 | |||
806 | $pod[ 'real_type' ] = $pod[ 'type' ]; |
||
807 | $pod[ 'type' ] = $types[ $pod[ 'type' ] ]; |
||
808 | } |
||
809 | elseif ( 'all' != $view ) |
||
810 | continue; |
||
811 | |||
812 | $pod[ 'storage' ] = ucwords( $pod[ 'storage' ] ); |
||
813 | |||
814 | if ( $pod[ 'id' ] == pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) |
||
815 | $row = $pod; |
||
816 | |||
817 | $pod = array( |
||
818 | 'id' => $pod[ 'id' ], |
||
819 | 'label' => pods_var_raw( 'label', $pod ), |
||
820 | 'name' => pods_var_raw( 'name', $pod ), |
||
821 | 'object' => pods_var_raw( 'object', $pod ), |
||
822 | 'type' => pods_var_raw( 'type', $pod ), |
||
823 | 'real_type' => pods_var_raw( 'real_type', $pod ), |
||
824 | 'storage' => pods_var_raw( 'storage', $pod ), |
||
825 | 'field_count' => count( $pod[ 'fields' ] ) |
||
826 | ); |
||
827 | |||
828 | $total_fields += $pod[ 'field_count' ]; |
||
829 | |||
830 | $pods[ $k ] = $pod; |
||
831 | } |
||
832 | |||
833 | if ( false === $row && 0 < pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) { |
||
834 | pods_message( 'Pod not found', 'error' ); |
||
835 | |||
836 | unset( $_GET[ 'id' ] ); |
||
837 | unset( $_GET[ 'action' ] ); |
||
838 | } |
||
839 | |||
840 | $ui = array( |
||
841 | 'data' => $pods, |
||
842 | 'row' => $row, |
||
843 | 'total' => count( $pods ), |
||
844 | 'total_found' => count( $pods ), |
||
845 | 'items' => 'Pods', |
||
846 | 'item' => 'Pod', |
||
847 | 'fields' => array( |
||
848 | 'manage' => $fields |
||
849 | ), |
||
850 | 'actions_disabled' => array( 'view', 'export' ), |
||
851 | 'actions_custom' => array( |
||
852 | 'add' => array( $this, 'admin_setup_add' ), |
||
853 | 'edit' => array( $this, 'admin_setup_edit' ), |
||
854 | 'duplicate' => array( |
||
855 | 'callback' => array( $this, 'admin_setup_duplicate' ), |
||
856 | 'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' ) |
||
857 | ), |
||
858 | 'reset' => array( |
||
859 | 'label' => __( 'Delete All Items', 'pods' ), |
||
860 | 'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ), |
||
861 | 'callback' => array( $this, 'admin_setup_reset' ), |
||
862 | 'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ), |
||
863 | 'nonce' => true |
||
864 | ), |
||
865 | 'delete' => array( $this, 'admin_setup_delete' ) |
||
866 | ), |
||
867 | 'action_links' => array( |
||
868 | 'add' => pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => '' ) ) |
||
869 | ), |
||
870 | 'search' => false, |
||
871 | 'searchable' => false, |
||
872 | 'sortable' => true, |
||
873 | 'pagination' => false, |
||
874 | 'extra' => array( |
||
875 | 'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' ) |
||
876 | ) |
||
877 | ); |
||
878 | |||
879 | if ( 1 < count( $pod_types_found ) ) { |
||
880 | $ui[ 'views' ] = array( 'all' => __( 'All', 'pods' ) ); |
||
881 | $ui[ 'view' ] = $view; |
||
882 | $ui[ 'heading' ] = array( 'views' => __( 'Type', 'pods' ) ); |
||
883 | $ui[ 'filters_enhanced' ] = true; |
||
884 | |||
885 | foreach ( $pod_types_found as $pod_type => $number_found ) { |
||
886 | $ui[ 'views' ][ $pod_type ] = $types[ $pod_type ]; |
||
887 | } |
||
888 | } |
||
889 | |||
890 | pods_ui( $ui ); |
||
891 | } |
||
892 | |||
893 | /** |
||
894 | * Get the add page of an object |
||
895 | * |
||
896 | * @param $obj |
||
897 | */ |
||
898 | public function admin_setup_add ( $obj ) { |
||
899 | pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) ); |
||
900 | } |
||
901 | |||
902 | /** |
||
903 | * Get the edit page of an object |
||
904 | * |
||
905 | * @param $duplicate |
||
906 | * @param $obj |
||
907 | */ |
||
908 | public function admin_setup_edit ( $duplicate, $obj ) { |
||
909 | pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) ); |
||
910 | } |
||
911 | |||
912 | /** |
||
913 | * Get list of Pod option tabs |
||
914 | * |
||
915 | * @return array |
||
916 | */ |
||
917 | public function admin_setup_edit_tabs ( $pod ) { |
||
918 | $fields = true; |
||
919 | $labels = false; |
||
920 | $admin_ui = false; |
||
921 | $advanced = false; |
||
922 | |||
923 | if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) { |
||
924 | $labels = true; |
||
925 | $admin_ui = true; |
||
926 | $advanced = true; |
||
927 | } |
||
928 | elseif ( 'taxonomy' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) { |
||
929 | $labels = true; |
||
930 | $admin_ui = true; |
||
931 | $advanced = true; |
||
932 | } |
||
933 | elseif ( 'pod' == pods_var( 'type', $pod ) ) { |
||
934 | $labels = true; |
||
935 | $admin_ui = true; |
||
936 | $advanced = true; |
||
937 | } |
||
938 | elseif ( 'settings' == pods_var( 'type', $pod ) ) { |
||
939 | $labels = true; |
||
940 | $admin_ui = true; |
||
941 | } |
||
942 | |||
943 | if ( ! function_exists( 'get_term_meta' ) && 'none' == pods_var( 'storage', $pod, 'none', null, true ) && 'taxonomy' == pods_var( 'type', $pod ) ) |
||
944 | $fields = false; |
||
945 | |||
946 | $tabs = array(); |
||
947 | |||
948 | if ( $fields ) |
||
949 | $tabs[ 'manage-fields' ] = __( 'Manage Fields', 'pods' ); |
||
950 | |||
951 | if ( $labels ) |
||
952 | $tabs[ 'labels' ] = __( 'Labels', 'pods' ); |
||
953 | |||
954 | if ( $admin_ui ) |
||
955 | $tabs[ 'admin-ui' ] = __( 'Admin UI', 'pods' ); |
||
956 | |||
957 | if ( $advanced ) |
||
958 | $tabs[ 'advanced' ] = __( 'Advanced Options', 'pods' ); |
||
959 | |||
960 | if ( 'taxonomy' == pods_var( 'type', $pod ) && !$fields ) |
||
961 | $tabs[ 'extra-fields' ] = __( 'Extra Fields', 'pods' ); |
||
962 | |||
963 | $addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) ); |
||
964 | |||
965 | /** |
||
966 | * Add or modify tabs in Pods editor for a specific Pod |
||
967 | * |
||
968 | * @params array $tabs Tabs to set. |
||
969 | * @params object $pod Current Pods object |
||
970 | * @params array $addtl_args Additional args. |
||
971 | * |
||
972 | * @since unknown |
||
973 | */ |
||
974 | $tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $tabs, $pod, $addtl_args ); |
||
975 | |||
976 | /** |
||
977 | * Add or modify tabs for any Pod in Pods editor of a specific post type. |
||
978 | */ |
||
979 | $tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ], $tabs, $pod, $addtl_args ); |
||
980 | |||
981 | /** |
||
982 | * Add or modify tabs in Pods editor for all pods. |
||
983 | */ |
||
984 | $tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args ); |
||
985 | |||
986 | return $tabs; |
||
987 | } |
||
988 | |||
989 | /** |
||
990 | * Get list of Pod options |
||
991 | * |
||
992 | * @return array |
||
993 | */ |
||
994 | public function admin_setup_edit_options ( $pod ) { |
||
995 | $options = array(); |
||
996 | |||
997 | if ( strlen( pods_v_sanitized( 'object', $pod ) ) < 1 && 'settings' != pods_v_sanitized( 'type', $pod ) ) { |
||
998 | |||
999 | $labels = array( |
||
1000 | 'label' => array( |
||
1001 | 'label' => __( 'Label', 'pods' ), |
||
1002 | 'help' =>__( 'help', 'pods' ), |
||
1003 | 'type' => 'text', |
||
1004 | 'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ), |
||
1005 | 'text_max_length' => 30 |
||
1006 | ), |
||
1007 | 'label_singular' => array( |
||
1008 | 'label' => __( 'Singular Label', 'pods' ), |
||
1009 | 'help' =>__( 'help', 'pods' ), |
||
1010 | 'type' => 'text', |
||
1011 | 'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ), |
||
1012 | 'text_max_length' => 30 |
||
1013 | ), |
||
1014 | 'label_add_new' => array( |
||
1015 | 'label' => __( 'Add New', 'pods' ), |
||
1016 | 'help' =>__( 'help', 'pods' ), |
||
1017 | 'type' => 'text', |
||
1018 | 'default' => '', |
||
1019 | 'object_type' => array( 'post_type', 'pod' ) |
||
1020 | ), |
||
1021 | 'label_add_new_item' => array( |
||
1022 | 'label' => __( 'Add new <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1023 | 'help' =>__( 'help', 'pods' ), |
||
1024 | 'type' => 'text', |
||
1025 | 'default' => '', |
||
1026 | ), |
||
1027 | 'label_new_item' => array( |
||
1028 | 'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1029 | 'help' =>__( 'help', 'pods' ), |
||
1030 | 'type' => 'text', |
||
1031 | 'default' => '', |
||
1032 | 'object_type' => array( 'post_type', 'pod' ) |
||
1033 | ), |
||
1034 | 'label_new_item_name' => array( |
||
1035 | 'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span> Name', 'pods' ), |
||
1036 | 'help' =>__( 'help', 'pods' ), |
||
1037 | 'type' => 'text', |
||
1038 | 'default' => '', |
||
1039 | 'object_type' => array( 'taxonomy' ) |
||
1040 | ), |
||
1041 | 'label_edit' => array( |
||
1042 | 'label' => __( 'Edit', 'pods' ), |
||
1043 | 'help' =>__( 'help', 'pods' ), |
||
1044 | 'type' => 'text', |
||
1045 | 'default' => '', |
||
1046 | 'object_type' => array( 'pod' ) |
||
1047 | ), |
||
1048 | 'label_edit_item' => array( |
||
1049 | 'label' => __( 'Edit <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1050 | 'help' =>__( 'help', 'pods' ), |
||
1051 | 'type' => 'text', |
||
1052 | 'default' => '', |
||
1053 | ), |
||
1054 | 'label_update_item' => array( |
||
1055 | 'label' => __( 'Update <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1056 | 'help' =>__( 'help', 'pods' ), |
||
1057 | 'type' => 'text', |
||
1058 | 'default' => '', |
||
1059 | 'object_type' => array( 'taxonomy', 'pod' ) |
||
1060 | ), |
||
1061 | 'label_duplicate' => array( |
||
1062 | 'label' => __( 'Duplicate', 'pods' ), |
||
1063 | 'help' =>__( 'help', 'pods' ), |
||
1064 | 'type' => 'text', |
||
1065 | 'default' => '', |
||
1066 | 'object_type' => array( 'pod' ) |
||
1067 | ), |
||
1068 | 'label_duplicate_item' => array( |
||
1069 | 'label' => __( 'Duplicate <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1070 | 'help' =>__( 'help', 'pods' ), |
||
1071 | 'type' => 'text', |
||
1072 | 'default' => '', |
||
1073 | 'object_type' => array( 'pod' ) |
||
1074 | ), |
||
1075 | 'label_delete_item' => array( |
||
1076 | 'label' => __( 'Delete <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1077 | 'help' =>__( 'help', 'pods' ), |
||
1078 | 'type' => 'text', |
||
1079 | 'default' => '', |
||
1080 | 'object_type' => array( 'pod' ) |
||
1081 | ), |
||
1082 | 'label_view' => array( |
||
1083 | 'label' => __( 'View', 'pods' ), |
||
1084 | 'help' =>__( 'help', 'pods' ), |
||
1085 | 'type' => 'text', |
||
1086 | 'default' => '', |
||
1087 | 'object_type' => array( 'pod' ) |
||
1088 | ), |
||
1089 | 'label_view_item' => array( |
||
1090 | 'label' => __( 'View <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1091 | 'help' =>__( 'help', 'pods' ), |
||
1092 | 'type' => 'text', |
||
1093 | 'default' => '', |
||
1094 | ), |
||
1095 | 'label_view_items' => array( |
||
1096 | 'label' => __( 'View <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), |
||
1097 | 'help' =>__( 'help', 'pods' ), |
||
1098 | 'type' => 'text', |
||
1099 | 'default' => '', |
||
1100 | 'object_type' => array( 'post_type' ) |
||
1101 | 'label_back_to_manage' => array( |
||
1102 | 'label' => __( 'Back to Manage', 'pods' ), |
||
1103 | 'help' =>__( 'help', 'pods' ), |
||
1104 | 'type' => 'text', |
||
1105 | 'default' => '', |
||
1106 | 'object_type' => array( 'pod' ) |
||
1107 | ), |
||
1108 | 'label_manage' => array( |
||
1109 | 'label' => __( 'Manage', 'pods' ), |
||
1110 | 'help' =>__( 'help', 'pods' ), |
||
1111 | 'type' => 'text', |
||
1112 | 'default' => '', |
||
1113 | 'object_type' => array( 'pod' ) |
||
1114 | ), |
||
1115 | 'label_manage_items' => array( |
||
1116 | 'label' => __( 'Manage <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), |
||
1117 | 'help' =>__( 'help', 'pods' ), |
||
1118 | 'type' => 'text', |
||
1119 | 'default' => '', |
||
1120 | 'object_type' => array( 'pod' ) |
||
1121 | ), |
||
1122 | 'label_reorder' => array( |
||
1123 | 'label' => __( 'Reorder', 'pods' ), |
||
1124 | 'help' =>__( 'help', 'pods' ), |
||
1125 | 'type' => 'text', |
||
1126 | 'default' => '', |
||
1127 | 'object_type' => array( 'pod' ) |
||
1128 | ), |
||
1129 | 'label_reorder_items' => array( |
||
1130 | 'label' => __( 'Reorder <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), |
||
1131 | 'help' =>__( 'help', 'pods' ), |
||
1132 | 'type' => 'text', |
||
1133 | 'default' => '', |
||
1134 | 'object_type' => array( 'pod' ) |
||
1135 | ), |
||
1136 | 'label_all_items' => array( |
||
1137 | 'label' => __( 'All <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1138 | 'help' =>__( 'help', 'pods' ), |
||
1139 | 'type' => 'text', |
||
1140 | 'default' => '', |
||
1141 | ), |
||
1142 | 'label_search' => array( |
||
1143 | 'label' => __( 'Search', 'pods' ), |
||
1144 | 'help' =>__( 'help', 'pods' ), |
||
1145 | 'type' => 'text', |
||
1146 | 'default' => '', |
||
1147 | 'object_type' => array( 'pod' ) |
||
1148 | ), |
||
1149 | 'label_search_items' => array( |
||
1150 | 'label' => __( 'Search <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1151 | 'help' =>__( 'help', 'pods' ), |
||
1152 | 'type' => 'text', |
||
1153 | 'default' => '', |
||
1154 | ), |
||
1155 | 'label_popular_items' => array( |
||
1156 | 'label' => __( 'Popular <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), |
||
1157 | 'help' =>__( 'help', 'pods' ), |
||
1158 | 'type' => 'text', |
||
1159 | 'default' => '', |
||
1160 | 'object_type' => array( 'taxonomy' ) |
||
1161 | ), |
||
1162 | // @todo Why was label_parent added previously? Can't find it in WP |
||
1163 | 'label_parent' => array( |
||
1164 | 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1165 | 'help' =>__( 'help', 'pods' ), |
||
1166 | 'type' => 'text', |
||
1167 | 'default' => '', |
||
1168 | 'object_type' => array( 'post_type', 'pod' ) |
||
1169 | ), |
||
1170 | 'label_parent_item' => array( |
||
1171 | 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1172 | 'help' =>__( 'help', 'pods' ), |
||
1173 | 'type' => 'text', |
||
1174 | 'default' => '', |
||
1175 | 'object_type' => array( 'taxonomy' ) |
||
1176 | ), |
||
1177 | 'label_parent_item_colon' => array( |
||
1178 | 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>:', 'pods' ), |
||
1179 | 'help' =>__( 'help', 'pods' ), |
||
1180 | 'type' => 'text', |
||
1181 | 'default' => '', |
||
1182 | ), |
||
1183 | 'label_not_found' => array( |
||
1184 | 'label' => __( 'Not Found', 'pods' ), |
||
1185 | 'help' =>__( 'help', 'pods' ), |
||
1186 | 'type' => 'text', |
||
1187 | 'default' => '', |
||
1188 | ), |
||
1189 | 'label_no_items_found' => array( |
||
1190 | 'label' => __( 'No <span class="pods-slugged" data-sluggable="label_singular">Item</span> Found', 'pods' ), |
||
1191 | 'help' =>__( 'help', 'pods' ), |
||
1192 | 'type' => 'text', |
||
1193 | 'default' => '', |
||
1194 | 'object_type' => array( 'pod' ) |
||
1195 | ), |
||
1196 | 'label_not_found_in_trash' => array( |
||
1197 | 'label' => __( 'Not Found in Trash', 'pods' ), |
||
1198 | 'help' =>__( 'help', 'pods' ), |
||
1199 | 'type' => 'text', |
||
1200 | 'default' => '', |
||
1201 | 'object_type' => array( 'post_type', 'pod' ) |
||
1202 | ), |
||
1203 | 'label_archives' => array( |
||
1204 | 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Archives', 'pods' ), |
||
1205 | 'help' =>__( 'help', 'pods' ), |
||
1206 | 'type' => 'text', |
||
1207 | 'default' => '', |
||
1208 | 'object_type' => array( 'post_type' ) |
||
1209 | ), |
||
1210 | 'label_attributes' => array( |
||
1211 | 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Attributes', 'pods' ), |
||
1212 | 'help' =>__( 'help', 'pods' ), |
||
1213 | 'type' => 'text', |
||
1214 | 'default' => '', |
||
1215 | 'object_type' => array( 'post_type' ) |
||
1216 | ), |
||
1217 | 'label_insert_into_item' => array( |
||
1218 | 'label' => __( 'Insert into <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1219 | 'help' =>__( 'help', 'pods' ), |
||
1220 | 'type' => 'text', |
||
1221 | 'default' => '', |
||
1222 | 'object_type' => array( 'post_type' ) |
||
1223 | ), |
||
1224 | 'label_uploaded_to_this_item' => array( |
||
1225 | 'label' => __( 'Uploaded to this <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1226 | 'help' =>__( 'help', 'pods' ), |
||
1227 | 'type' => 'text', |
||
1228 | 'default' => '', |
||
1229 | 'object_type' => array( 'post_type' ) |
||
1230 | ), |
||
1231 | 'label_featured_image' => array( |
||
1232 | 'label' => __( 'Featured Image', 'pods' ), |
||
1233 | 'help' =>__( 'help', 'pods' ), |
||
1234 | 'type' => 'text', |
||
1235 | 'default' => '', |
||
1236 | //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working |
||
1237 | 'object_type' => array( 'post_type' ) |
||
1238 | ), |
||
1239 | 'label_set_featured_image' => array( |
||
1240 | 'label' => __( 'Set featured Image', 'pods' ), |
||
1241 | 'help' =>__( 'help', 'pods' ), |
||
1242 | 'type' => 'text', |
||
1243 | 'default' => '', |
||
1244 | //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working |
||
1245 | 'object_type' => array( 'post_type' ) |
||
1246 | ), |
||
1247 | 'label_remove_featured_image' => array( |
||
1248 | 'label' => __( 'Remove featured Image', 'pods' ), |
||
1249 | 'help' =>__( 'help', 'pods' ), |
||
1250 | 'type' => 'text', |
||
1251 | 'default' => '', |
||
1252 | //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working |
||
1253 | 'object_type' => array( 'post_type' ) |
||
1254 | ), |
||
1255 | 'label_use_featured_image' => array( |
||
1256 | 'label' => __( 'Use as featured Image', 'pods' ), |
||
1257 | 'help' =>__( 'help', 'pods' ), |
||
1258 | 'type' => 'text', |
||
1259 | 'default' => '', |
||
1260 | //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working |
||
1261 | 'object_type' => array( 'post_type' ) |
||
1262 | ), |
||
1263 | 'label_filter_items_list' => array( |
||
1264 | 'label' => __( 'Filter <span class="pods-slugged" data-sluggable="label">Items</span> lists', 'pods' ), |
||
1265 | 'help' =>__( 'help', 'pods' ), |
||
1266 | 'type' => 'text', |
||
1267 | 'default' => '', |
||
1268 | 'object_type' => array( 'post_type' ) |
||
1269 | ), |
||
1270 | 'label_items_list_navigation' => array( |
||
1271 | 'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list navigation', 'pods' ), |
||
1272 | 'help' =>__( 'help', 'pods' ), |
||
1273 | 'type' => 'text', |
||
1274 | 'default' => '', |
||
1275 | 'object_type' => array( 'post_type', 'taxonomy' ) |
||
1276 | ), |
||
1277 | 'label_items_list' => array( |
||
1278 | 'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list', 'pods' ), |
||
1279 | 'help' =>__( 'help', 'pods' ), |
||
1280 | 'type' => 'text', |
||
1281 | 'default' => '', |
||
1282 | 'object_type' => array( 'post_type', 'taxonomy' ) |
||
1283 | ), |
||
1284 | 'label_separate_items_with_commas' => array( |
||
1285 | 'label' => __( 'Separate <span class="pods-slugged-lower" data-sluggable="label">items</span> with commas', 'pods' ), |
||
1286 | 'help' =>__( 'help', 'pods' ), |
||
1287 | 'type' => 'text', |
||
1288 | 'default' => '', |
||
1289 | 'object_type' => array( 'taxonomy' ) |
||
1290 | ), |
||
1291 | 'label_add_or_remove_items' => array( |
||
1292 | 'label' => __( 'Add or remove <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ), |
||
1293 | 'help' =>__( 'help', 'pods' ), |
||
1294 | 'type' => 'text', |
||
1295 | 'default' => '', |
||
1296 | 'object_type' => array( 'taxonomy' ) |
||
1297 | ), |
||
1298 | 'label_choose_from_the_most_used' => array( |
||
1299 | 'label' => __( 'Choose from the most used <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ), |
||
1300 | 'help' =>__( 'help', 'pods' ), |
||
1301 | 'type' => 'text', |
||
1302 | 'default' => '', |
||
1303 | 'object_type' => array( 'taxonomy' ) |
||
1304 | ), |
||
1305 | 'label_no_terms' => array( |
||
1306 | 'label' => __( 'No <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ), |
||
1307 | 'help' =>__( 'help', 'pods' ), |
||
1308 | 'type' => 'text', |
||
1309 | 'default' => '', |
||
1310 | 'object_type' => array( 'taxonomy' ) |
||
1311 | ), |
||
1312 | ); |
||
1313 | |||
1314 | $options[ 'labels' ] = array(); |
||
1315 | |||
1316 | /** |
||
1317 | * Filter through all labels if they have an object_type set and match it against the current object type |
||
1318 | */ |
||
1319 | foreach ( $labels as $label => $labeldata ) { |
||
1320 | if ( array_key_exists( 'object_type', $labeldata ) ) { |
||
1321 | if ( in_array( pods_v_sanitized( 'type', $pod ), $labeldata[ 'object_type' ] ) ) { |
||
1322 | // Do not add the object_type to the actual label data |
||
1323 | unset( $labeldata[ 'object_type' ] ); |
||
1324 | $options[ 'labels' ][ $label ] = $labeldata; |
||
1325 | } |
||
1326 | } else { |
||
1327 | $options[ 'labels' ][ $label ] = $labeldata; |
||
1328 | } |
||
1329 | } |
||
1330 | |||
1331 | } elseif ( 'settings' == pods_v_sanitized( 'type', $pod ) ) { |
||
1332 | |||
1333 | $options[ 'labels' ] = array( |
||
1334 | 'label' => array( |
||
1335 | 'label' => __( 'Page Title', 'pods' ), |
||
1336 | 'help' =>__( 'help', 'pods' ), |
||
1337 | 'type' => 'text', |
||
1338 | 'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ), |
||
1339 | 'text_max_length' => 30 |
||
1340 | ), |
||
1341 | 'menu_name' => array( |
||
1342 | 'label' => __( 'Menu Name', 'pods' ), |
||
1343 | 'help' =>__( 'help', 'pods' ), |
||
1344 | 'type' => 'text', |
||
1345 | 'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ), |
||
1346 | 'text_max_length' => 30 |
||
1347 | ), |
||
1348 | ); |
||
1349 | } |
||
1350 | |||
1351 | if ( 'post_type' == $pod[ 'type' ] ) { |
||
1352 | $options[ 'admin-ui' ] = array( |
||
1353 | 'description' => array( |
||
1354 | 'label' => __( 'Post Type Description', 'pods' ), |
||
1355 | 'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ), |
||
1356 | 'type' => 'text', |
||
1357 | 'default' => '' |
||
1358 | ), |
||
1359 | 'show_ui' => array( |
||
1360 | 'label' => __( 'Show Admin UI', 'pods' ), |
||
1361 | 'help' => __( 'Whether to generate a default UI for managing this post type in the admin.', 'pods' ), |
||
1362 | 'type' => 'boolean', |
||
1363 | 'default' => pods_var_raw( 'public', $pod, true ), |
||
1364 | 'boolean_yes_label' => '' |
||
1365 | ), |
||
1366 | 'show_in_menu' => array( |
||
1367 | 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ), |
||
1368 | 'help' => __( 'Whether to show the post type in the admin menu.', 'pods' ), |
||
1369 | 'type' => 'boolean', |
||
1370 | 'default' => pods_var_raw( 'public', $pod, true ), |
||
1371 | 'dependency' => true, |
||
1372 | 'boolean_yes_label' => '' |
||
1373 | ), |
||
1374 | 'menu_location_custom' => array( |
||
1375 | 'label' => __( 'Parent Menu ID (optional)', 'pods' ), |
||
1376 | 'help' => __( 'help', 'pods' ), |
||
1377 | 'type' => 'text', |
||
1378 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1379 | ), |
||
1380 | 'menu_name' => array( |
||
1381 | 'label' => __( 'Menu Name', 'pods' ), |
||
1382 | 'help' => __( 'help', 'pods' ), |
||
1383 | 'type' => 'text', |
||
1384 | 'default' => '', |
||
1385 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1386 | ), |
||
1387 | 'menu_position' => array( |
||
1388 | 'label' => __( 'Menu Position', 'pods' ), |
||
1389 | 'help' => __( 'help', 'pods' ), |
||
1390 | 'type' => 'number', |
||
1391 | 'default' => 0, |
||
1392 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1393 | ), |
||
1394 | 'menu_icon' => array( |
||
1395 | 'label' => __( 'Menu Icon', 'pods' ), |
||
1396 | 'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="http://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank">site tag</a> type <a href="http://pods.io/docs/build/special-magic-tags/" target="_blank">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="https://developer.wordpress.org/resource/dashicons/" target="_blank">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ), |
||
1397 | 'type' => 'text', |
||
1398 | 'default' => '', |
||
1399 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1400 | ), |
||
1401 | 'show_in_nav_menus' => array( |
||
1402 | 'label' => __( 'Show in Navigation Menus', 'pods' ), |
||
1403 | 'help' => __( 'help', 'pods' ), |
||
1404 | 'type' => 'boolean', |
||
1405 | 'default' => true, |
||
1406 | 'boolean_yes_label' => '' |
||
1407 | ), |
||
1408 | 'show_in_admin_bar' => array( |
||
1409 | 'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ), |
||
1410 | 'help' => __( 'help', 'pods' ), |
||
1411 | 'type' => 'boolean', |
||
1412 | 'default' => true, |
||
1413 | 'dependency' => true, |
||
1414 | 'boolean_yes_label' => '' |
||
1415 | ), |
||
1416 | 'name_admin_bar' => array( |
||
1417 | 'label' => __( 'Admin bar name', 'pods' ), |
||
1418 | 'help' =>__( 'Defaults to singular name', 'pods' ), |
||
1419 | 'type' => 'text', |
||
1420 | 'default' => '', |
||
1421 | 'depends-on' => array( 'show_in_admin_bar' => true ) |
||
1422 | ) |
||
1423 | ); |
||
1424 | |||
1425 | $options[ 'advanced' ] = array( |
||
1426 | 'public' => array( |
||
1427 | 'label' => __( 'Public', 'pods' ), |
||
1428 | 'help' => __( 'help', 'pods' ), |
||
1429 | 'type' => 'boolean', |
||
1430 | 'default' => true, |
||
1431 | 'boolean_yes_label' => '' |
||
1432 | ), |
||
1433 | 'publicly_queryable' => array( |
||
1434 | 'label' => __( 'Publicly Queryable', 'pods' ), |
||
1435 | 'help' => __( 'help', 'pods' ), |
||
1436 | 'type' => 'boolean', |
||
1437 | 'default' => pods_var_raw( 'public', $pod, true ), |
||
1438 | 'boolean_yes_label' => '' |
||
1439 | ), |
||
1440 | 'exclude_from_search' => array( |
||
1441 | 'label' => __( 'Exclude from Search', 'pods' ), |
||
1442 | 'help' => __( 'help', 'pods' ), |
||
1443 | 'type' => 'boolean', |
||
1444 | 'default' => !pods_var_raw( 'public', $pod, true ), |
||
1445 | 'boolean_yes_label' => '' |
||
1446 | ), |
||
1447 | 'capability_type' => array( |
||
1448 | 'label' => __( 'User Capability', 'pods' ), |
||
1449 | 'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ), |
||
1450 | 'type' => 'pick', |
||
1451 | 'default' => 'post', |
||
1452 | 'data' => array( |
||
1453 | 'post' => 'post', |
||
1454 | 'page' => 'page', |
||
1455 | 'custom' => __( 'Custom Capability', 'pods' ) |
||
1456 | ), |
||
1457 | 'dependency' => true |
||
1458 | ), |
||
1459 | 'capability_type_custom' => array( |
||
1460 | 'label' => __( 'Custom User Capability', 'pods' ), |
||
1461 | 'help' => __( 'help', 'pods' ), |
||
1462 | 'type' => 'text', |
||
1463 | 'default' => pods_var_raw( 'name', $pod ), |
||
1464 | 'depends-on' => array( 'capability_type' => 'custom' ) |
||
1465 | ), |
||
1466 | 'capability_type_extra' => array( |
||
1467 | 'label' => __( 'Additional User Capabilities', 'pods' ), |
||
1468 | 'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ), |
||
1469 | 'type' => 'boolean', |
||
1470 | 'default' => true, |
||
1471 | 'boolean_yes_label' => '' |
||
1472 | ), |
||
1473 | 'has_archive' => array( |
||
1474 | 'label' => __( 'Enable Archive Page', 'pods' ), |
||
1475 | 'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ), |
||
1476 | 'type' => 'boolean', |
||
1477 | 'default' => false, |
||
1478 | 'dependency' => true, |
||
1479 | 'boolean_yes_label' => '' |
||
1480 | ), |
||
1481 | 'has_archive_slug' => array( |
||
1482 | 'label' => __( 'Archive Page Slug Override', 'pods' ), |
||
1483 | 'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ), |
||
1484 | 'type' => 'text', |
||
1485 | 'default' => '', |
||
1486 | 'depends-on' => array( 'has_archive' => true ) |
||
1487 | ), |
||
1488 | 'hierarchical' => array( |
||
1489 | 'label' => __( 'Hierarchical', 'pods' ), |
||
1490 | 'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ), |
||
1491 | 'type' => 'boolean', |
||
1492 | 'default' => false, |
||
1493 | 'dependency' => true, |
||
1494 | 'boolean_yes_label' => '' |
||
1495 | ), |
||
1496 | 'label_parent_item_colon' => array( |
||
1497 | 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1498 | 'help' => __( 'help', 'pods' ), |
||
1499 | 'type' => 'text', |
||
1500 | 'default' => '', |
||
1501 | 'depends-on' => array( 'hierarchical' => true ) |
||
1502 | ), |
||
1503 | 'label_parent' => array( |
||
1504 | 'label' => __( '<strong>Label: </strong> Parent', 'pods' ), |
||
1505 | 'help' => __( 'help', 'pods' ), |
||
1506 | 'type' => 'text', |
||
1507 | 'default' => '', |
||
1508 | 'depends-on' => array( 'hierarchical' => true ) |
||
1509 | ), |
||
1510 | 'rewrite' => array( |
||
1511 | 'label' => __( 'Rewrite', 'pods' ), |
||
1512 | 'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Reading. If not enbabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ), |
||
1513 | 'type' => 'boolean', |
||
1514 | 'default' => true, |
||
1515 | 'dependency' => true, |
||
1516 | 'boolean_yes_label' => '' |
||
1517 | ), |
||
1518 | 'rewrite_custom_slug' => array( |
||
1519 | 'label' => __( 'Custom Rewrite Slug', 'pods' ), |
||
1520 | 'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ), |
||
1521 | 'type' => 'text', |
||
1522 | 'default' => '', |
||
1523 | 'depends-on' => array( 'rewrite' => true ) |
||
1524 | ), |
||
1525 | 'rewrite_with_front' => array( |
||
1526 | 'label' => __( 'Rewrite with Front', 'pods' ), |
||
1527 | 'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ), |
||
1528 | 'type' => 'boolean', |
||
1529 | 'default' => true, |
||
1530 | 'depends-on' => array( 'rewrite' => true ), |
||
1531 | 'boolean_yes_label' => '' |
||
1532 | ), |
||
1533 | 'rewrite_feeds' => array( |
||
1534 | 'label' => __( 'Rewrite Feeds', 'pods' ), |
||
1535 | 'help' => __( 'help', 'pods' ), |
||
1536 | 'type' => 'boolean', |
||
1537 | 'default' => false, |
||
1538 | 'depends-on' => array( 'rewrite' => true ), |
||
1539 | 'boolean_yes_label' => '' |
||
1540 | ), |
||
1541 | 'rewrite_pages' => array( |
||
1542 | 'label' => __( 'Rewrite Pages', 'pods' ), |
||
1543 | 'help' => __( 'help', 'pods' ), |
||
1544 | 'type' => 'boolean', |
||
1545 | 'default' => true, |
||
1546 | 'depends-on' => array( 'rewrite' => true ), |
||
1547 | 'boolean_yes_label' => '' |
||
1548 | ), |
||
1549 | 'query_var' => array( |
||
1550 | 'label' => __( 'Query Var', 'pods' ), |
||
1551 | 'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ), |
||
1552 | 'type' => 'boolean', |
||
1553 | 'default' => true, |
||
1554 | 'boolean_yes_label' => '' |
||
1555 | ), |
||
1556 | 'can_export' => array( |
||
1557 | 'label' => __( 'Exportable', 'pods' ), |
||
1558 | 'help' => __( 'help', 'pods' ), |
||
1559 | 'type' => 'boolean', |
||
1560 | 'default' => true, |
||
1561 | 'boolean_yes_label' => '' |
||
1562 | ), |
||
1563 | 'default_status' => array( |
||
1564 | 'label' => __( 'Default Status', 'pods' ), |
||
1565 | 'help' => __( 'help', 'pods' ), |
||
1566 | 'type' => 'pick', |
||
1567 | 'pick_object' => 'post-status', |
||
1568 | 'default' => apply_filters( 'pods_api_default_status_' . pods_var_raw( 'name', $pod, 'post_type', null, true ), 'draft', $pod ) |
||
1569 | ) |
||
1570 | ); |
||
1571 | } |
||
1572 | elseif ( 'taxonomy' == $pod[ 'type' ] ) { |
||
1573 | $options[ 'admin-ui' ] = array( |
||
1574 | 'show_ui' => array( |
||
1575 | 'label' => __( 'Show Admin UI', 'pods' ), |
||
1576 | 'help' => __( 'Whether to generate a default UI for managing this taxonomy.', 'pods' ), |
||
1577 | 'type' => 'boolean', |
||
1578 | 'default' => pods_var_raw( 'public', $pod, true ), |
||
1579 | 'dependency' => true, |
||
1580 | 'boolean_yes_label' => '' |
||
1581 | ), |
||
1582 | 'show_in_menu' => array( |
||
1583 | 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ), |
||
1584 | 'help' => __( 'Whether to show the taxonomy in the admin menu.', 'pods' ), |
||
1585 | 'type' => 'boolean', |
||
1586 | 'default' => pods_var_raw( 'public', $pod, true ), |
||
1587 | 'dependency' => true, |
||
1588 | 'depends-on' => array( 'show_ui' => true ), |
||
1589 | 'boolean_yes_label' => '' |
||
1590 | ), |
||
1591 | 'menu_name' => array( |
||
1592 | 'label' => __( 'Menu Name', 'pods' ), |
||
1593 | 'help' => __( 'help', 'pods' ), |
||
1594 | 'type' => 'text', |
||
1595 | 'default' => '', |
||
1596 | 'depends-on' => array( 'show_ui' => true ) |
||
1597 | ), |
||
1598 | 'menu_location' => array( |
||
1599 | 'label' => __( 'Menu Location', 'pods' ), |
||
1600 | 'help' => __( 'help', 'pods' ), |
||
1601 | 'type' => 'pick', |
||
1602 | 'default' => 'default', |
||
1603 | 'depends-on' => array( 'show_ui' => true ), |
||
1604 | 'data' => array( |
||
1605 | 'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ), |
||
1606 | 'settings' => __( 'Add to Settings menu', 'pods' ), |
||
1607 | 'appearances' => __( 'Add to Appearances menu', 'pods' ), |
||
1608 | 'objects' => __( 'Make a top-level menu item', 'pods' ), |
||
1609 | 'top' => __( 'Make a new top-level menu item below Settings', 'pods' ), |
||
1610 | 'submenu' => __( 'Add a submenu item to another menu', 'pods' ) |
||
1611 | ), |
||
1612 | 'dependency' => true |
||
1613 | ), |
||
1614 | 'menu_location_custom' => array( |
||
1615 | 'label' => __( 'Custom Menu Location', 'pods' ), |
||
1616 | 'help' => __( 'help', 'pods' ), |
||
1617 | 'type' => 'text', |
||
1618 | 'depends-on' => array( 'menu_location' => 'submenu' ) |
||
1619 | ), |
||
1620 | 'menu_position' => array( |
||
1621 | 'label' => __( 'Menu Position', 'pods' ), |
||
1622 | 'help' => __( 'help', 'pods' ), |
||
1623 | 'type' => 'number', |
||
1624 | 'default' => 0, |
||
1625 | 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ) |
||
1626 | ), |
||
1627 | 'menu_icon' => array( |
||
1628 | 'label' => __( 'Menu Icon URL', 'pods' ), |
||
1629 | 'help' => __( 'help', 'pods' ), |
||
1630 | 'type' => 'text', |
||
1631 | 'default' => '', |
||
1632 | 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ) |
||
1633 | ), |
||
1634 | 'show_in_nav_menus' => array( |
||
1635 | 'label' => __( 'Show in Navigation Menus', 'pods' ), |
||
1636 | 'help' => __( 'help', 'pods' ), |
||
1637 | 'type' => 'boolean', |
||
1638 | 'default' => pods_var_raw( 'public', $pod, true ), |
||
1639 | 'boolean_yes_label' => '' |
||
1640 | ), |
||
1641 | 'show_tagcloud' => array( |
||
1642 | 'label' => __( 'Allow in Tagcloud Widget', 'pods' ), |
||
1643 | 'help' => __( 'help', 'pods' ), |
||
1644 | 'type' => 'boolean', |
||
1645 | 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ), |
||
1646 | 'boolean_yes_label' => '' |
||
1647 | ), |
||
1648 | // @todo check https://core.trac.wordpress.org/ticket/36964 |
||
1649 | 'show_tagcloud_in_edit' => array( |
||
1650 | 'label' => __( 'Allow Tagcloud on term edit pages', 'pods' ), |
||
1651 | 'help' => __( 'help', 'pods' ), |
||
1652 | 'type' => 'boolean', |
||
1653 | 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'show_tagcloud', $pod, true ) ), |
||
1654 | 'boolean_yes_label' => '' |
||
1655 | ), |
||
1656 | 'show_in_quick_edit' => array( |
||
1657 | 'label' => __( 'Allow in quick/bulk edit panel', 'pods' ), |
||
1658 | 'help' => __( 'help', 'pods' ), |
||
1659 | 'type' => 'boolean', |
||
1660 | 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ), |
||
1661 | 'boolean_yes_label' => '' |
||
1662 | ) |
||
1663 | ); |
||
1664 | |||
1665 | if ( pods_version_check( 'wp', '3.5' ) ) { |
||
1666 | $options[ 'admin-ui' ][ 'show_admin_column' ] = array( |
||
1667 | 'label' => __( 'Show Taxonomy column on Post Types', 'pods' ), |
||
1668 | 'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ), |
||
1669 | 'type' => 'boolean', |
||
1670 | 'default' => false, |
||
1671 | 'boolean_yes_label' => '' |
||
1672 | ); |
||
1673 | } |
||
1674 | |||
1675 | // Integration for Single Value Taxonomy UI |
||
1676 | if ( function_exists( 'tax_single_value_meta_box' ) ) { |
||
1677 | $options[ 'admin-ui' ][ 'single_value' ] = array( |
||
1678 | 'label' => __( 'Single Value Taxonomy', 'pods' ), |
||
1679 | 'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ), |
||
1680 | 'type' => 'boolean', |
||
1681 | 'default' => false, |
||
1682 | 'boolean_yes_label' => '' |
||
1683 | ); |
||
1684 | |||
1685 | $options[ 'admin-ui' ][ 'single_value_required' ] = array( |
||
1686 | 'label' => __( 'Single Value Taxonomy - Required', 'pods' ), |
||
1687 | 'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ), |
||
1688 | 'type' => 'boolean', |
||
1689 | 'default' => false, |
||
1690 | 'boolean_yes_label' => '' |
||
1691 | ); |
||
1692 | } |
||
1693 | |||
1694 | $options[ 'advanced' ] = array( |
||
1695 | 'public' => array( |
||
1696 | 'label' => __( 'Public', 'pods' ), |
||
1697 | 'help' => __( 'help', 'pods' ), |
||
1698 | 'type' => 'boolean', |
||
1699 | 'default' => true, |
||
1700 | 'boolean_yes_label' => '' |
||
1701 | ), |
||
1702 | 'hierarchical' => array( |
||
1703 | 'label' => __( 'Hierarchical', 'pods' ), |
||
1704 | 'help' => __( 'help', 'pods' ), |
||
1705 | 'type' => 'boolean', |
||
1706 | 'default' => true, |
||
1707 | 'dependency' => true, |
||
1708 | 'boolean_yes_label' => '' |
||
1709 | ), |
||
1710 | 'label_parent_item_colon' => array( |
||
1711 | 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
||
1712 | 'help' => __( 'help', 'pods' ), |
||
1713 | 'type' => 'text', |
||
1714 | 'default' => '', |
||
1715 | 'depends-on' => array( 'hierarchical' => true ) |
||
1716 | ), |
||
1717 | 'label_parent' => array( |
||
1718 | 'label' => __( '<strong>Label: </strong> Parent', 'pods' ), |
||
1719 | 'help' => __( 'help', 'pods' ), |
||
1720 | 'type' => 'text', |
||
1721 | 'default' => '', |
||
1722 | 'depends-on' => array( 'hierarchical' => true ) |
||
1723 | ), |
||
1724 | 'label_no_terms' => array( |
||
1725 | 'label' => __( '<strong>Label: </strong> No <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), |
||
1726 | 'help' => __( 'help', 'pods' ), |
||
1727 | 'type' => 'text', |
||
1728 | 'default' => '', |
||
1729 | 'depends-on' => array( 'hierarchical' => true ) |
||
1730 | ), |
||
1731 | 'rewrite' => array( |
||
1732 | 'label' => __( 'Rewrite', 'pods' ), |
||
1733 | 'help' => __( 'help', 'pods' ), |
||
1734 | 'type' => 'boolean', |
||
1735 | 'default' => true, |
||
1736 | 'dependency' => true, |
||
1737 | 'boolean_yes_label' => '' |
||
1738 | ), |
||
1739 | 'rewrite_custom_slug' => array( |
||
1740 | 'label' => __( 'Custom Rewrite Slug', 'pods' ), |
||
1741 | 'help' => __( 'help', 'pods' ), |
||
1742 | 'type' => 'text', |
||
1743 | 'default' => '', |
||
1744 | 'depends-on' => array( 'rewrite' => true ) |
||
1745 | ), |
||
1746 | 'rewrite_with_front' => array( |
||
1747 | 'label' => __( 'Allow Front Prepend', 'pods' ), |
||
1748 | 'help' => __( 'Allows permalinks to be prepended with front base (example: if your permalink structure is /blog/, then your links will be: Checked->/news/, Unchecked->/blog/news/)', 'pods' ), |
||
1749 | 'type' => 'boolean', |
||
1750 | 'default' => true, |
||
1751 | 'boolean_yes_label' => '', |
||
1752 | 'depends-on' => array( 'rewrite' => true ) |
||
1753 | ), |
||
1754 | 'rewrite_hierarchical' => array( |
||
1755 | 'label' => __( 'Hierarchical Permalinks', 'pods' ), |
||
1756 | 'help' => __( 'help', 'pods' ), |
||
1757 | 'type' => 'boolean', |
||
1758 | 'default' => true, |
||
1759 | 'boolean_yes_label' => '', |
||
1760 | 'depends-on' => array( 'rewrite' => true ) |
||
1761 | ), |
||
1762 | 'capability_type' => array( |
||
1763 | 'label' => __( 'User Capability', 'pods' ), |
||
1764 | 'help' => __( 'Uses WordPress term capabilities by default', 'pods' ), |
||
1765 | 'type' => 'pick', |
||
1766 | 'default' => 'default', |
||
1767 | 'data' => array( |
||
1768 | 'default' => 'Default', |
||
1769 | 'custom' => __( 'Custom Capability', 'pods' ) |
||
1770 | ), |
||
1771 | 'dependency' => true |
||
1772 | ), |
||
1773 | 'capability_type_custom' => array( |
||
1774 | 'label' => __( 'Custom User Capability', 'pods' ), |
||
1775 | 'help' => __( 'Enables additional capabilities for this Taxonomy including: manage_{capability}_terms, edit_{capability}_terms, assign_{capability}_terms, and delete_{capability}_terms', 'pods' ), |
||
1776 | 'type' => 'text', |
||
1777 | 'default' => pods_v( 'name', $pod ), |
||
1778 | 'depends-on' => array( 'capability_type' => 'custom' ) |
||
1779 | ), |
||
1780 | 'query_var' => array( |
||
1781 | 'label' => __( 'Query Var', 'pods' ), |
||
1782 | 'help' => __( 'help', 'pods' ), |
||
1783 | 'type' => 'boolean', |
||
1784 | 'default' => false, |
||
1785 | 'boolean_yes_label' => '' |
||
1786 | ), |
||
1787 | 'query_var' => array( |
||
1788 | 'label' => __( 'Query Var', 'pods' ), |
||
1789 | 'help' => __( 'help', 'pods' ), |
||
1790 | 'type' => 'boolean', |
||
1791 | 'default' => false, |
||
1792 | 'dependency' => true, |
||
1793 | 'boolean_yes_label' => '' |
||
1794 | ), |
||
1795 | 'query_var_string' => array( |
||
1796 | 'label' => __( 'Custom Query Var Name', 'pods' ), |
||
1797 | 'help' => __( 'help', 'pods' ), |
||
1798 | 'type' => 'text', |
||
1799 | 'default' => '', |
||
1800 | 'depends-on' => array( 'query_var' => true ) |
||
1801 | ), |
||
1802 | 'sort' => array( |
||
1803 | 'label' => __( 'Remember order saved on Post Types', 'pods' ), |
||
1804 | 'help' => __( 'help', 'pods' ), |
||
1805 | 'type' => 'boolean', |
||
1806 | 'default' => false, |
||
1807 | 'boolean_yes_label' => '' |
||
1808 | ), |
||
1809 | 'update_count_callback' => array( |
||
1810 | 'label' => __( 'Function to call when updating counts', 'pods' ), |
||
1811 | 'help' => __( 'help', 'pods' ), |
||
1812 | 'type' => 'text', |
||
1813 | 'default' => '' |
||
1814 | ), |
||
1815 | ); |
||
1816 | } |
||
1817 | elseif ( 'settings' == $pod[ 'type' ] ) { |
||
1818 | $options[ 'admin-ui' ] = array( |
||
1819 | 'ui_style' => array( |
||
1820 | 'label' => __( 'Admin UI Style', 'pods' ), |
||
1821 | 'help' => __( 'help', 'pods' ), |
||
1822 | 'type' => 'pick', |
||
1823 | 'default' => 'settings', |
||
1824 | 'data' => array( |
||
1825 | 'settings' => __( 'Normal Settings Form', 'pods' ), |
||
1826 | 'post_type' => __( 'Post Type UI', 'pods' ), |
||
1827 | 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ) |
||
1828 | ), |
||
1829 | 'dependency' => true |
||
1830 | ), |
||
1831 | 'menu_location' => array( |
||
1832 | 'label' => __( 'Menu Location', 'pods' ), |
||
1833 | 'help' => __( 'help', 'pods' ), |
||
1834 | 'type' => 'pick', |
||
1835 | 'default' => 'settings', |
||
1836 | 'data' => array( |
||
1837 | 'settings' => __( 'Add to Settings menu', 'pods' ), |
||
1838 | 'appearances' => __( 'Add to Appearances menu', 'pods' ), |
||
1839 | 'top' => __( 'Make a new top-level menu item below Settings', 'pods' ), |
||
1840 | 'submenu' => __( 'Add a submenu item to another menu', 'pods' ) |
||
1841 | ), |
||
1842 | 'dependency' => true |
||
1843 | ), |
||
1844 | 'menu_location_custom' => array( |
||
1845 | 'label' => __( 'Custom Menu Location', 'pods' ), |
||
1846 | 'help' => __( 'help', 'pods' ), |
||
1847 | 'type' => 'text', |
||
1848 | 'depends-on' => array( 'menu_location' => 'submenu' ) |
||
1849 | ), |
||
1850 | 'menu_position' => array( |
||
1851 | 'label' => __( 'Menu Position', 'pods' ), |
||
1852 | 'help' => __( 'help', 'pods' ), |
||
1853 | 'type' => 'number', |
||
1854 | 'default' => 0, |
||
1855 | 'depends-on' => array( 'menu_location' => 'top' ) |
||
1856 | ), |
||
1857 | 'menu_icon' => array( |
||
1858 | 'label' => __( 'Menu Icon URL', 'pods' ), |
||
1859 | 'help' => __( 'help', 'pods' ), |
||
1860 | 'type' => 'text', |
||
1861 | 'default' => '', |
||
1862 | 'depends-on' => array( 'menu_location' => 'top' ) |
||
1863 | ) |
||
1864 | ); |
||
1865 | |||
1866 | // @todo fill this in |
||
1867 | $options[ 'advanced' ] = array( |
||
1868 | 'temporary' => 'This type has the fields hardcoded' // :( |
||
1869 | ); |
||
1870 | } |
||
1871 | elseif ( 'pod' == $pod[ 'type' ] ) { |
||
1872 | $options[ 'admin-ui' ] = array( |
||
1873 | 'ui_style' => array( |
||
1874 | 'label' => __( 'Admin UI Style', 'pods' ), |
||
1875 | 'help' => __( 'help', 'pods' ), |
||
1876 | 'type' => 'pick', |
||
1877 | 'default' => 'settings', |
||
1878 | 'data' => array( |
||
1879 | 'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ), |
||
1880 | 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ) |
||
1881 | ), |
||
1882 | 'dependency' => true |
||
1883 | ), |
||
1884 | 'show_in_menu' => array( |
||
1885 | 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ), |
||
1886 | 'help' => __( 'help', 'pods' ), |
||
1887 | 'type' => 'boolean', |
||
1888 | 'default' => false, |
||
1889 | 'boolean_yes_label' => '', |
||
1890 | 'dependency' => true |
||
1891 | ), |
||
1892 | 'menu_location_custom' => array( |
||
1893 | 'label' => __( 'Parent Menu ID (optional)', 'pods' ), |
||
1894 | 'help' => __( 'help', 'pods' ), |
||
1895 | 'type' => 'text', |
||
1896 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1897 | ), |
||
1898 | 'menu_position' => array( |
||
1899 | 'label' => __( 'Menu Position', 'pods' ), |
||
1900 | 'help' => __( 'help', 'pods' ), |
||
1901 | 'type' => 'number', |
||
1902 | 'default' => 0, |
||
1903 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1904 | ), |
||
1905 | 'menu_icon' => array( |
||
1906 | 'label' => __( 'Menu Icon URL', 'pods' ), |
||
1907 | 'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ), |
||
1908 | 'type' => 'text', |
||
1909 | 'default' => '', |
||
1910 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1911 | ), |
||
1912 | 'ui_icon' => array( |
||
1913 | 'label' => __( 'Header Icon', 'pods' ), |
||
1914 | 'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ), |
||
1915 | 'type' => 'file', |
||
1916 | 'default' => '', |
||
1917 | 'file_edit_title' => 0, |
||
1918 | 'depends-on' => array( 'show_in_menu' => true ) |
||
1919 | ), |
||
1920 | 'ui_actions_enabled' => array( |
||
1921 | 'label' => __( 'Actions Available', 'pods' ), |
||
1922 | 'help' => __( 'help', 'pods' ), |
||
1923 | 'type' => 'pick', |
||
1924 | 'default' => ( 1 == pods_var( 'ui_export', $pod ) ? array( 'add', 'edit', 'duplicate', 'delete', 'export' ) : array( 'add', 'edit', 'duplicate', 'delete' ) ), |
||
1925 | 'data' => array( |
||
1926 | 'add' => __( 'Add New', 'pods' ), |
||
1927 | 'edit' => __( 'Edit', 'pods' ), |
||
1928 | 'duplicate' => __( 'Duplicate', 'pods' ), |
||
1929 | 'delete' => __( 'Delete', 'pods' ), |
||
1930 | 'reorder' => __( 'Reorder', 'pods' ), |
||
1931 | 'export' => __( 'Export', 'pods' ) |
||
1932 | ), |
||
1933 | 'pick_format_type' => 'multi', |
||
1934 | 'dependency' => true |
||
1935 | ), |
||
1936 | 'ui_reorder_field' => array( |
||
1937 | 'label' => __( 'Reorder Field', 'pods' ), |
||
1938 | 'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ), |
||
1939 | 'type' => 'text', |
||
1940 | 'default' => 'menu_order', |
||
1941 | 'depends-on' => array( 'ui_actions_enabled' => 'reorder' ) |
||
1942 | ), |
||
1943 | 'ui_fields_manage' => array( |
||
1944 | 'label' => __( 'Admin Table Columns', 'pods' ), |
||
1945 | 'help' => __( 'help', 'pods' ), |
||
1946 | 'type' => 'pick', |
||
1947 | 'default' => array(), |
||
1948 | 'data' => array(), |
||
1949 | 'pick_format_type' => 'multi' |
||
1950 | ), |
||
1951 | 'ui_filters' => array( |
||
1952 | 'label' => __( 'Search Filters', 'pods' ), |
||
1953 | 'help' => __( 'help', 'pods' ), |
||
1954 | 'type' => 'pick', |
||
1955 | 'default' => array(), |
||
1956 | 'data' => array(), |
||
1957 | 'pick_format_type' => 'multi' |
||
1958 | ) |
||
1959 | ); |
||
1960 | |||
1961 | if ( !empty( $pod[ 'fields' ] ) ) { |
||
1962 | if ( isset( $pod[ 'fields' ][ pods_var_raw( 'pod_index', $pod, 'name' ) ] ) ) |
||
1963 | $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = pods_var_raw( 'pod_index', $pod, 'name' ); |
||
1964 | |||
1965 | if ( isset( $pod[ 'fields' ][ 'modified' ] ) ) |
||
1966 | $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = 'modified'; |
||
1967 | |||
1968 | foreach ( $pod[ 'fields' ] as $field ) { |
||
1969 | $type = ''; |
||
1970 | |||
1971 | if ( isset( $field_types[ $field[ 'type' ] ] ) ) |
||
1972 | $type = ' <small>(' . $field_types[ $field[ 'type' ] ][ 'label' ] . ')</small>'; |
||
1973 | |||
1974 | $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type; |
||
1975 | $options[ 'admin-ui' ][ 'ui_filters' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type; |
||
1976 | } |
||
1977 | |||
1978 | $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ 'id' ] = 'ID'; |
||
1979 | } |
||
1980 | else { |
||
1981 | unset( $options[ 'admin-ui' ][ 'ui_fields_manage' ] ); |
||
1982 | unset( $options[ 'admin-ui' ][ 'ui_filters' ] ); |
||
1983 | } |
||
1984 | |||
1985 | // @todo fill this in |
||
1986 | $options[ 'advanced' ] = array( |
||
1987 | 'temporary' => 'This type has the fields hardcoded' // :( |
||
1988 | ); |
||
1989 | } |
||
1990 | |||
1991 | /** |
||
1992 | * Add admin fields to the Pods editor for a specific Pod |
||
1993 | * |
||
1994 | * @params array $options The Options fields |
||
1995 | * @params object $pod Current Pods object |
||
1996 | * |
||
1997 | * @since unkown |
||
1998 | */ |
||
1999 | $options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $options, $pod ); |
||
2000 | |||
2001 | /** |
||
2002 | * Add admin fields to the Pods editor for any Pod of a specific content type. |
||
2003 | */ |
||
2004 | $options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ], $options, $pod ); |
||
2005 | |||
2006 | /** |
||
2007 | * Add admin fields to the Pods editor for all Pods |
||
2008 | */ |
||
2009 | $options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod ); |
||
2010 | |||
2011 | return $options; |
||
2012 | } |
||
2013 | |||
2014 | /** |
||
2015 | * Get list of Pod field option tabs |
||
2016 | * |
||
2017 | * @return array |
||
2018 | */ |
||
2019 | public function admin_setup_edit_field_tabs ( $pod ) { |
||
2020 | $core_tabs = array( |
||
2021 | 'basic' => __( 'Basic', 'pods' ), |
||
2022 | 'additional-field' => __( 'Additional Field Options', 'pods' ), |
||
2023 | 'advanced' => __( 'Advanced', 'pods' ) |
||
2024 | ); |
||
2025 | |||
2026 | /** |
||
2027 | * Field option tabs |
||
2028 | * |
||
2029 | * Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye). |
||
2030 | * |
||
2031 | * @since unknown |
||
2032 | * |
||
2033 | * @param array $tabs Tabs to add, starts empty |
||
2034 | * @param object|Pod Current Pods object |
||
2035 | */ |
||
2036 | $tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod ); |
||
2037 | |||
2038 | $tabs = array_merge( $core_tabs, $tabs ); |
||
2039 | |||
2040 | return $tabs; |
||
2041 | } |
||
2042 | |||
2043 | /** |
||
2044 | * Get list of Pod field options |
||
2045 | * |
||
2046 | * @return array |
||
2047 | */ |
||
2048 | public function admin_setup_edit_field_options ( $pod ) { |
||
2049 | $options = array(); |
||
2050 | |||
2051 | $options[ 'additional-field' ] = array(); |
||
2052 | |||
2053 | $field_types = PodsForm::field_types(); |
||
2054 | |||
2055 | foreach ( $field_types as $type => $field_type_data ) { |
||
2056 | /** |
||
2057 | * @var $field_type PodsField |
||
2058 | */ |
||
2059 | $field_type = PodsForm::field_loader( $type, $field_type_data[ 'file' ] ); |
||
2060 | |||
2061 | $field_type_vars = get_class_vars( get_class( $field_type ) ); |
||
2062 | |||
2063 | if ( !isset( $field_type_vars[ 'pod_types' ] ) ) |
||
2064 | $field_type_vars[ 'pod_types' ] = true; |
||
2065 | |||
2066 | $options[ 'additional-field' ][ $type ] = array(); |
||
2067 | |||
2068 | // Only show supported field types |
||
2069 | if ( true !== $field_type_vars[ 'pod_types' ] ) { |
||
2070 | if ( empty( $field_type_vars[ 'pod_types' ] ) ) |
||
2071 | continue; |
||
2072 | elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) ) |
||
2073 | continue; |
||
2074 | elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] ) |
||
2075 | continue; |
||
2076 | } |
||
2077 | |||
2078 | $options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type ); |
||
2079 | |||
2080 | /** |
||
2081 | * Modify Additional Field Options tab |
||
2082 | * |
||
2083 | * @since 2.7 |
||
2084 | * |
||
2085 | * @param array $options Additional field type options |
||
2086 | * @param string $type Field type |
||
2087 | * @param array $options Tabs, indexed by label |
||
2088 | * @param object|Pods Pods object for the Pod this UI is for. |
||
2089 | */ |
||
2090 | $options[ 'additional-field' ][ $type ] = apply_filters( 'pods_admin_setup_edit_' . $type . '_additional_field_options', $options[ 'additional-field' ][ $type ], $type, $options, $pod ); |
||
2091 | $options[ 'additional-field' ][ $type ] = apply_filters( 'pods_admin_setup_edit_additional_field_options', $options[ 'additional-field' ][ $type ], $type, $options, $pod ); |
||
2092 | } |
||
2093 | |||
2094 | $input_helpers = array( |
||
2095 | '' => '-- Select --' |
||
2096 | ); |
||
2097 | |||
2098 | if ( class_exists( 'Pods_Helpers' ) ) { |
||
2099 | $helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) ); |
||
2100 | |||
2101 | foreach ( $helpers as $helper ) { |
||
2102 | $input_helpers[ $helper[ 'name' ] ] = $helper[ 'name' ]; |
||
2103 | } |
||
2104 | } |
||
2105 | |||
2106 | $options[ 'advanced' ] = array( |
||
2107 | __( 'Visual', 'pods' ) => array( |
||
2108 | 'class' => array( |
||
2109 | 'name' => 'class', |
||
2110 | 'label' => __( 'Additional CSS Classes', 'pods' ), |
||
2111 | 'help' => __( 'help', 'pods' ), |
||
2112 | 'type' => 'text', |
||
2113 | 'default' => '' |
||
2114 | ), |
||
2115 | 'input_helper' => array( |
||
2116 | 'name' => 'input_helper', |
||
2117 | 'label' => __( 'Input Helper', 'pods' ), |
||
2118 | 'help' => __( 'help', 'pods' ), |
||
2119 | 'type' => 'pick', |
||
2120 | 'default' => '', |
||
2121 | 'data' => $input_helpers |
||
2122 | ) |
||
2123 | ), |
||
2124 | __( 'Values', 'pods' ) => array( |
||
2125 | 'default_value' => array( |
||
2126 | 'name' => 'default_value', |
||
2127 | 'label' => __( 'Default Value', 'pods' ), |
||
2128 | 'help' => __( 'help', 'pods' ), |
||
2129 | 'type' => 'text', |
||
2130 | 'default' => '', |
||
2131 | 'options' => array( |
||
2132 | 'text_max_length' => -1 |
||
2133 | ) |
||
2134 | ), |
||
2135 | 'default_value_parameter' => array( |
||
2136 | 'name' => 'default_value_parameter', |
||
2137 | 'label' => __( 'Set Default Value via Parameter', 'pods' ), |
||
2138 | 'help' => __( 'help', 'pods' ), |
||
2139 | 'type' => 'text', |
||
2140 | 'default' => '' |
||
2141 | ) |
||
2142 | ), |
||
2143 | __( 'Visibility', 'pods' ) => array( |
||
2144 | 'restrict_access' => array( |
||
2145 | 'name' => 'restrict_access', |
||
2146 | 'label' => __( 'Restrict Access', 'pods' ), |
||
2147 | 'group' => array( |
||
2148 | 'admin_only' => array( |
||
2149 | 'name' => 'admin_only', |
||
2150 | 'label' => __( 'Restrict access to Admins?', 'pods' ), |
||
2151 | 'default' => 0, |
||
2152 | 'type' => 'boolean', |
||
2153 | 'dependency' => true, |
||
2154 | 'help' => __( 'This field 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' ) |
||
2155 | ), |
||
2156 | 'restrict_role' => array( |
||
2157 | 'name' => 'restrict_role', |
||
2158 | 'label' => __( 'Restrict access by Role?', 'pods' ), |
||
2159 | 'default' => 0, |
||
2160 | 'type' => 'boolean', |
||
2161 | 'dependency' => true |
||
2162 | ), |
||
2163 | 'restrict_capability' => array( |
||
2164 | 'name' => 'restrict_capability', |
||
2165 | 'label' => __( 'Restrict access by Capability?', 'pods' ), |
||
2166 | 'default' => 0, |
||
2167 | 'type' => 'boolean', |
||
2168 | 'dependency' => true |
||
2169 | ), |
||
2170 | 'hidden' => array( |
||
2171 | 'name' => 'hidden', |
||
2172 | 'label' => __( 'Hide field from UI', 'pods' ), |
||
2173 | 'default' => 0, |
||
2174 | 'type' => 'boolean', |
||
2175 | 'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' ) |
||
2176 | ), |
||
2177 | 'read_only' => array( |
||
2178 | 'name' => 'read_only', |
||
2179 | 'label' => __( 'Make field "Read Only" in UI', 'pods' ), |
||
2180 | 'default' => 0, |
||
2181 | 'type' => 'boolean', |
||
2182 | 'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ), |
||
2183 | 'depends-on' => array( |
||
2184 | 'type' => array( |
||
2185 | 'boolean', |
||
2186 | 'color', |
||
2187 | 'currency', |
||
2188 | 'date', |
||
2189 | 'datetime', |
||
2190 | 'email', |
||
2191 | 'number', |
||
2192 | 'paragraph', |
||
2193 | 'password', |
||
2194 | 'phone', |
||
2195 | 'slug', |
||
2196 | 'text', |
||
2197 | 'time', |
||
2198 | 'website' |
||
2199 | ) |
||
2200 | ) |
||
2201 | ) |
||
2202 | ) |
||
2203 | ), |
||
2204 | 'roles_allowed' => array( |
||
2205 | 'name' => 'roles_allowed', |
||
2206 | 'label' => __( 'Role(s) Allowed', 'pods' ), |
||
2207 | 'help' => __( 'help', 'pods' ), |
||
2208 | 'type' => 'pick', |
||
2209 | 'pick_object' => 'role', |
||
2210 | 'pick_format_type' => 'multi', |
||
2211 | 'default' => 'administrator', |
||
2212 | 'depends-on' => array( |
||
2213 | 'restrict_role' => true |
||
2214 | ) |
||
2215 | ), |
||
2216 | 'capability_allowed' => array( |
||
2217 | 'name' => 'capability_allowed', |
||
2218 | 'label' => __( 'Capability Allowed', 'pods' ), |
||
2219 | 'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ), |
||
2220 | 'type' => 'text', |
||
2221 | 'default' => '', |
||
2222 | 'depends-on' => array( |
||
2223 | 'restrict_capability' => true |
||
2224 | ) |
||
2225 | ) |
||
2226 | /*, |
||
2227 | 'search' => array( |
||
2228 | 'label' => __( 'Include in searches', 'pods' ), |
||
2229 | 'help' => __( 'help', 'pods' ), |
||
2230 | 'default' => 1, |
||
2231 | 'type' => 'boolean', |
||
2232 | )*/ |
||
2233 | ) |
||
2234 | /*, |
||
2235 | __( 'Validation', 'pods' ) => array( |
||
2236 | 'regex_validation' => array( |
||
2237 | 'label' => __( 'RegEx Validation', 'pods' ), |
||
2238 | 'help' => __( 'help', 'pods' ), |
||
2239 | 'type' => 'text', |
||
2240 | 'default' => '' |
||
2241 | ), |
||
2242 | 'message_regex' => array( |
||
2243 | 'label' => __( 'Message if field does not pass RegEx', 'pods' ), |
||
2244 | 'help' => __( 'help', 'pods' ), |
||
2245 | 'type' => 'text', |
||
2246 | 'default' => '' |
||
2247 | ), |
||
2248 | 'message_required' => array( |
||
2249 | 'label' => __( 'Message if field is blank', 'pods' ), |
||
2250 | 'help' => __( 'help', 'pods' ), |
||
2251 | 'type' => 'text', |
||
2252 | 'default' => '', |
||
2253 | 'depends-on' => array( 'required' => true ) |
||
2254 | ), |
||
2255 | 'message_unique' => array( |
||
2256 | 'label' => __( 'Message if field is not unique', 'pods' ), |
||
2257 | 'help' => __( 'help', 'pods' ), |
||
2258 | 'type' => 'text', |
||
2259 | 'default' => '', |
||
2260 | 'depends-on' => array( 'unique' => true ) |
||
2261 | ) |
||
2262 | )*/ |
||
2263 | ); |
||
2264 | |||
2265 | if ( !class_exists( 'Pods_Helpers' ) ) |
||
2266 | unset( $options[ 'advanced' ][ 'input_helper' ] ); |
||
2267 | |||
2268 | /** |
||
2269 | * Modify tabs and their contents for field options |
||
2270 | * |
||
2271 | * @since unknown |
||
2272 | * |
||
2273 | * @param array $options Tabs, indexed by label |
||
2274 | * @param object|Pods Pods object for the Pod this UI is for. |
||
2275 | */ |
||
2276 | $options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod ); |
||
2277 | |||
2278 | return $options; |
||
2279 | } |
||
2280 | |||
2281 | /** |
||
2282 | * Duplicate a pod |
||
2283 | * |
||
2284 | * @param $id |
||
2285 | * @param $obj |
||
2286 | * |
||
2287 | * @return mixed |
||
2288 | */ |
||
2289 | public function admin_setup_duplicate ( $obj ) { |
||
2290 | $new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) ); |
||
2291 | |||
2292 | if ( 0 < $new_id ) |
||
2293 | pods_redirect( pods_query_arg( array( 'action' => 'edit', 'id' => $new_id, 'do' => 'duplicate' ) ) ); |
||
2294 | } |
||
2295 | |||
2296 | /** |
||
2297 | * Restrict Duplicate action to custom types, not extended |
||
2298 | * |
||
2299 | * @param bool $restricted |
||
2300 | * @param array $restrict |
||
2301 | * @param string $action |
||
2302 | * @param array $row |
||
2303 | * @param PodsUI $obj |
||
2304 | * |
||
2305 | * @since 2.3.10 |
||
2306 | * |
||
2307 | * @return bool |
||
2308 | */ |
||
2309 | public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) { |
||
2310 | |||
2311 | if ( in_array( $row[ 'real_type' ], array( 'user', 'media', 'comment' ) ) ) { |
||
2312 | $restricted = true; |
||
2313 | } |
||
2314 | |||
2315 | return $restricted; |
||
2316 | |||
2317 | } |
||
2318 | |||
2319 | /** |
||
2320 | * Reset a pod |
||
2321 | * |
||
2322 | * @param $obj |
||
2323 | * |
||
2324 | * @return mixed |
||
2325 | */ |
||
2326 | public function admin_setup_reset ( $obj, $id ) { |
||
2327 | $pod = pods_api()->load_pod( array( 'id' => $id ), false ); |
||
2328 | |||
2329 | if ( empty( $pod ) ) |
||
2330 | return $obj->error( __( 'Pod not found.', 'pods' ) ); |
||
2331 | |||
2332 | pods_api()->reset_pod( array( 'id' => $id ) ); |
||
2333 | |||
2334 | $obj->message( __( 'Pod reset successfully.', 'pods' ) ); |
||
2335 | |||
2336 | $obj->manage(); |
||
2337 | } |
||
2338 | |||
2339 | /** |
||
2340 | * Restrict Reset action from users and media |
||
2341 | * |
||
2342 | * @param bool $restricted |
||
2343 | * @param array $restrict |
||
2344 | * @param string $action |
||
2345 | * @param array $row |
||
2346 | * @param PodsUI $obj |
||
2347 | * |
||
2348 | * @since 2.3.10 |
||
2349 | */ |
||
2350 | public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) { |
||
2351 | |||
2352 | if ( in_array( $row[ 'real_type' ], array( 'user', 'media' ) ) ) { |
||
2353 | $restricted = true; |
||
2354 | } |
||
2355 | |||
2356 | return $restricted; |
||
2357 | |||
2358 | } |
||
2359 | |||
2360 | /** |
||
2361 | * Delete a pod |
||
2362 | * |
||
2363 | * @param $id |
||
2364 | * @param $obj |
||
2365 | * |
||
2366 | * @return mixed |
||
2367 | */ |
||
2368 | public function admin_setup_delete ( $id, $obj ) { |
||
2369 | $pod = pods_api()->load_pod( array( 'id' => $id ), false ); |
||
2370 | |||
2371 | if ( empty( $pod ) ) |
||
2372 | return $obj->error( __( 'Pod not found.', 'pods' ) ); |
||
2373 | |||
2374 | pods_api()->delete_pod( array( 'id' => $id ) ); |
||
2375 | |||
2376 | unset( $obj->data[ $pod[ 'id' ] ] ); |
||
2377 | |||
2378 | $obj->total = count( $obj->data ); |
||
2379 | $obj->total_found = count( $obj->data ); |
||
2380 | |||
2381 | $obj->message( __( 'Pod deleted successfully.', 'pods' ) ); |
||
2382 | } |
||
2383 | |||
2384 | /** |
||
2385 | * Get advanced administration view. |
||
2386 | */ |
||
2387 | public function admin_advanced () { |
||
2388 | pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) ); |
||
2389 | } |
||
2390 | |||
2391 | /** |
||
2392 | * Get settings administration view |
||
2393 | */ |
||
2394 | public function admin_settings () { |
||
2395 | pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) ); |
||
2396 | } |
||
2397 | |||
2398 | /** |
||
2399 | * Get components administration UI |
||
2400 | */ |
||
2401 | public function admin_components () { |
||
2402 | if ( ! is_object( PodsInit::$components ) ) |
||
2403 | return; |
||
2404 | |||
2405 | $components = PodsInit::$components->components; |
||
2406 | |||
2407 | $view = pods_var( 'view', 'get', 'all', null, true ); |
||
2408 | |||
2409 | $recommended = array( |
||
2410 | 'advanced-relationships', |
||
2411 | 'advanced-content-types', |
||
2412 | 'migrate-packages', |
||
2413 | 'roles-and-capabilities', |
||
2414 | 'pages', |
||
2415 | 'table-storage', |
||
2416 | 'templates' |
||
2417 | ); |
||
2418 | |||
2419 | foreach ( $components as $component => &$component_data ) { |
||
2420 | if ( !in_array( $view, array( 'all', 'recommended', 'dev' ) ) && ( !isset( $component_data[ 'Category' ] ) || $view != sanitize_title( $component_data[ 'Category' ] ) ) ) { |
||
2421 | unset( $components[ $component ] ); |
||
2422 | |||
2423 | continue; |
||
2424 | } |
||
2425 | elseif ( 'recommended' == $view && !in_array( $component_data[ 'ID' ], $recommended ) ) { |
||
2426 | unset( $components[ $component ] ); |
||
2427 | |||
2428 | continue; |
||
2429 | } |
||
2430 | elseif ( 'dev' == $view && pods_developer() && !pods_var_raw( 'DeveloperMode', $component_data, false ) ) { |
||
2431 | unset( $components[ $component ] ); |
||
2432 | |||
2433 | continue; |
||
2434 | } |
||
2435 | elseif ( pods_var_raw( 'DeveloperMode', $component_data, false ) && !pods_developer() ) { |
||
2436 | unset( $components[ $component ] ); |
||
2437 | |||
2438 | continue; |
||
2439 | } |
||
2440 | elseif ( !pods_var_raw( 'TablelessMode', $component_data, false ) && pods_tableless() ) { |
||
2441 | unset( $components[ $component ] ); |
||
2442 | |||
2443 | continue; |
||
2444 | } |
||
2445 | |||
2446 | $component_data[ 'Name' ] = strip_tags( $component_data[ 'Name' ] ); |
||
2447 | |||
2448 | if ( pods_var_raw( 'DeveloperMode', $component_data, false ) ) |
||
2449 | $component_data[ 'Name' ] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>'; |
||
2450 | |||
2451 | $meta = array(); |
||
2452 | |||
2453 | if ( !empty( $component_data[ 'Version' ] ) ) |
||
2454 | $meta[] = 'Version ' . $component_data[ 'Version' ]; |
||
2455 | |||
2456 | if ( empty( $component_data[ 'Author' ] ) ) { |
||
2457 | $component_data[ 'Author' ] = 'Pods Framework Team'; |
||
2458 | $component_data[ 'AuthorURI' ] = 'http://pods.io/'; |
||
2459 | } |
||
2460 | |||
2461 | if ( !empty( $component_data[ 'AuthorURI' ] ) ) |
||
2462 | $component_data[ 'Author' ] = '<a href="' . $component_data[ 'AuthorURI' ] . '">' . $component_data[ 'Author' ] . '</a>'; |
||
2463 | |||
2464 | $meta[] = sprintf( __( 'by %s', 'pods' ), $component_data[ 'Author' ] ); |
||
2465 | |||
2466 | if ( !empty( $component_data[ 'URI' ] ) ) |
||
2467 | $meta[] = '<a href="' . $component_data[ 'URI' ] . '">' . __( 'Visit component site', 'pods' ) . '</a>'; |
||
2468 | |||
2469 | $component_data[ 'Description' ] = wpautop( trim( make_clickable( strip_tags( $component_data[ 'Description' ], 'em,strong' ) ) ) ); |
||
2470 | |||
2471 | if ( !empty( $meta ) ) |
||
2472 | $component_data[ 'Description' ] .= '<div class="pods-component-meta" ' . ( !empty( $component_data[ 'Description' ] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( ' | ', $meta ) . '</div>'; |
||
2473 | |||
2474 | $component_data = array( |
||
2475 | 'id' => $component_data[ 'ID' ], |
||
2476 | 'name' => $component_data[ 'Name' ], |
||
2477 | 'category' => $component_data[ 'Category' ], |
||
2478 | 'version' => '', |
||
2479 | 'description' => $component_data[ 'Description' ], |
||
2480 | 'mustuse' => pods_var_raw( 'MustUse', $component_data, false ), |
||
2481 | 'toggle' => 0 |
||
2482 | ); |
||
2483 | |||
2484 | if ( !empty( $component_data[ 'category' ] ) ) { |
||
2485 | $category_url = pods_query_arg( array( 'view' => sanitize_title( $component_data[ 'category' ] ), 'pg' => '', 'page' => $_GET[ 'page' ] ) ); |
||
2486 | |||
2487 | $component_data[ 'category' ] = '<a href="' . esc_url( $category_url ) . '">' . $component_data[ 'category' ] . '</a>'; |
||
2488 | } |
||
2489 | |||
2490 | if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) && 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) |
||
2491 | $component_data[ 'toggle' ] = 1; |
||
2492 | elseif ( $component_data[ 'mustuse' ] ) |
||
2493 | $component_data[ 'toggle' ] = 1; |
||
2494 | } |
||
2495 | |||
2496 | $ui = array( |
||
2497 | 'data' => $components, |
||
2498 | 'total' => count( $components ), |
||
2499 | 'total_found' => count( $components ), |
||
2500 | 'items' => 'Components', |
||
2501 | 'item' => 'Component', |
||
2502 | 'fields' => array( |
||
2503 | 'manage' => array( |
||
2504 | 'name' => array( |
||
2505 | 'label' => __( 'Name', 'pods' ), |
||
2506 | 'width' => '30%', |
||
2507 | 'type' => 'text', |
||
2508 | 'options' => array( |
||
2509 | 'text_allow_html' => true |
||
2510 | ) |
||
2511 | ), |
||
2512 | 'category' => array( |
||
2513 | 'label' => __( 'Category', 'pods' ), |
||
2514 | 'width' => '10%', |
||
2515 | 'type' => 'text', |
||
2516 | 'options' => array( |
||
2517 | 'text_allow_html' => true |
||
2518 | ) |
||
2519 | ), |
||
2520 | 'description' => array( |
||
2521 | 'label' => __( 'Description', 'pods' ), |
||
2522 | 'width' => '60%', |
||
2523 | 'type' => 'text', |
||
2524 | 'options' => array( |
||
2525 | 'text_allow_html' => true, |
||
2526 | 'text_allowed_html_tags' => 'strong em a ul ol li b i br div' |
||
2527 | ) |
||
2528 | ) |
||
2529 | ) |
||
2530 | ), |
||
2531 | 'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ), |
||
2532 | 'actions_custom' => array( |
||
2533 | 'toggle' => array( |
||
2534 | 'callback' => array( $this, 'admin_components_toggle' ), |
||
2535 | 'nonce' => true |
||
2536 | ) |
||
2537 | ), |
||
2538 | 'filters_enhanced' => true, |
||
2539 | 'views' => array( |
||
2540 | 'all' => __( 'All', 'pods' ), |
||
2541 | //'recommended' => __( 'Recommended', 'pods' ), |
||
2542 | 'field-types' => __( 'Field Types', 'pods' ), |
||
2543 | 'tools' => __( 'Tools', 'pods' ), |
||
2544 | 'integration' => __( 'Integration', 'pods' ), |
||
2545 | 'migration' => __( 'Migration', 'pods' ), |
||
2546 | 'advanced' => __( 'Advanced', 'pods' ) |
||
2547 | ), |
||
2548 | 'view' => $view, |
||
2549 | 'heading' => array( |
||
2550 | 'views' => __( 'Category', 'pods' ) |
||
2551 | ), |
||
2552 | 'search' => false, |
||
2553 | 'searchable' => false, |
||
2554 | 'sortable' => false, |
||
2555 | 'pagination' => false |
||
2556 | ); |
||
2557 | |||
2558 | if ( pods_developer() ) |
||
2559 | $ui[ 'views' ][ 'dev' ] = __( 'Developer Preview', 'pods' ); |
||
2560 | |||
2561 | pods_ui( $ui ); |
||
2562 | } |
||
2563 | |||
2564 | /** |
||
2565 | * Toggle a component on or off |
||
2566 | * |
||
2567 | * @param PodsUI $ui |
||
2568 | * |
||
2569 | * @return bool |
||
2570 | */ |
||
2571 | public function admin_components_toggle ( PodsUI $ui ) { |
||
2572 | $component = $_GET[ 'id' ]; |
||
2573 | |||
2574 | if ( !empty( PodsInit::$components->components[ $component ][ 'PluginDependency' ] ) ) { |
||
2575 | $dependency = explode( '|', PodsInit::$components->components[ $component ][ 'PluginDependency' ] ); |
||
2576 | |||
2577 | if ( !pods_is_plugin_active( $dependency[ 1 ] ) ) { |
||
2578 | $website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[ 1 ] ) . '/'; |
||
2579 | |||
2580 | if ( isset( $dependency[ 2 ] ) ) |
||
2581 | $website = $dependency[ 2 ]; |
||
2582 | |||
2583 | if ( !empty( $website ) ) |
||
2584 | $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' ); |
||
2585 | |||
2586 | $message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website; |
||
2587 | |||
2588 | $ui->error( $message ); |
||
2589 | |||
2590 | $ui->manage(); |
||
2591 | |||
2592 | return; |
||
2593 | } |
||
2594 | } |
||
2595 | |||
2596 | if ( !empty( PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ) ) { |
||
2597 | $dependency = explode( '|', PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ); |
||
2598 | |||
2599 | if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) ) { |
||
2600 | $website = ''; |
||
2601 | |||
2602 | if ( isset( $dependency[ 2 ] ) ) |
||
2603 | $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[ 2 ] . '" target="_blank">' . $dependency[ 2 ] . '</a>' ); |
||
2604 | |||
2605 | $message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website; |
||
2606 | |||
2607 | $ui->error( $message ); |
||
2608 | |||
2609 | $ui->manage(); |
||
2610 | |||
2611 | return; |
||
2612 | } |
||
2613 | } |
||
2614 | |||
2615 | if ( !empty( PodsInit::$components->components[ $component ][ 'MustUse' ] ) ) { |
||
2616 | $message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ] ); |
||
2617 | |||
2618 | $ui->error( $message ); |
||
2619 | |||
2620 | $ui->manage(); |
||
2621 | |||
2622 | return; |
||
2623 | } |
||
2624 | |||
2625 | if ( '1' == pods_v( 'toggled' ) ) { |
||
2626 | $toggle = PodsInit::$components->toggle( $component ); |
||
2627 | |||
2628 | if ( true === $toggle ) |
||
2629 | $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) ); |
||
2630 | elseif ( false === $toggle ) |
||
2631 | $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) ); |
||
2632 | |||
2633 | $components = PodsInit::$components->components; |
||
2634 | |||
2635 | foreach ( $components as $component => &$component_data ) { |
||
2636 | $toggle = 0; |
||
2637 | |||
2638 | if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) ) { |
||
2639 | if ( 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) |
||
2640 | $toggle = 1; |
||
2641 | } |
||
2642 | if ( true === $component_data[ 'DeveloperMode' ] ) { |
||
2643 | if ( !pods_developer() ) { |
||
2644 | unset( $components[ $component ] ); |
||
2645 | continue; |
||
2646 | } |
||
2647 | } |
||
2648 | |||
2649 | $component_data = array( |
||
2650 | 'id' => $component_data[ 'ID' ], |
||
2651 | 'name' => $component_data[ 'Name' ], |
||
2652 | 'description' => make_clickable( $component_data[ 'Description' ] ), |
||
2653 | 'version' => $component_data[ 'Version' ], |
||
2654 | 'author' => $component_data[ 'Author' ], |
||
2655 | 'toggle' => $toggle |
||
2656 | ); |
||
2657 | } |
||
2658 | |||
2659 | $ui->data = $components; |
||
2660 | |||
2661 | pods_transient_clear( 'pods_components' ); |
||
2662 | |||
2663 | $url = pods_query_arg( array( 'toggled' => null ) ); |
||
2664 | |||
2665 | pods_redirect( $url ); |
||
2666 | } |
||
2667 | elseif ( 1 == pods_var( 'toggle' ) ) |
||
2668 | $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) ); |
||
2669 | else |
||
2670 | $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) ); |
||
2671 | |||
2672 | $ui->manage(); |
||
2673 | } |
||
2674 | |||
2675 | /** |
||
2676 | * Get the admin upgrade page |
||
2677 | */ |
||
2678 | public function admin_upgrade () { |
||
2679 | foreach ( PodsInit::$upgrades as $old_version => $new_version ) { |
||
2680 | if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) { |
||
2681 | $new_version = str_replace( '.', '_', $new_version ); |
||
2682 | |||
2683 | pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) ); |
||
2684 | |||
2685 | break; |
||
2686 | } |
||
2687 | } |
||
2688 | } |
||
2689 | |||
2690 | /** |
||
2691 | * Get the admin help page |
||
2692 | */ |
||
2693 | public function admin_help () { |
||
2694 | pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) ); |
||
2695 | } |
||
2696 | |||
2697 | /** |
||
2698 | * Add pods specific capabilities. |
||
2699 | * |
||
2700 | * @param $capabilities List of extra capabilities to add |
||
2701 | * |
||
2702 | * @return array |
||
2703 | */ |
||
2704 | public function admin_capabilities ( $capabilities ) { |
||
2705 | $pods = pods_api()->load_pods( array( 'type' => array( 'settings', 'post_type', 'taxonomy' ), 'fields' => false, 'table_info' => false ) ); |
||
2706 | $other_pods = pods_api()->load_pods( array( 'type' => array( 'pod', 'table' ), 'table_info' => false ) ); |
||
2707 | |||
2708 | $pods = array_merge( $pods, $other_pods ); |
||
2709 | |||
2710 | $capabilities[] = 'pods'; |
||
2711 | $capabilities[] = 'pods_content'; |
||
2712 | $capabilities[] = 'pods_settings'; |
||
2713 | $capabilities[] = 'pods_components'; |
||
2714 | |||
2715 | foreach ( $pods as $pod ) { |
||
2716 | if ( 'settings' == $pod[ 'type' ] ) { |
||
2717 | $capabilities[] = 'pods_edit_' . $pod[ 'name' ]; |
||
2718 | } |
||
2719 | elseif ( 'post_type' == $pod[ 'type' ] ) { |
||
2720 | $capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) ); |
||
2721 | |||
2722 | if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ] ) && 0 < strlen( $capability_type ) ) { |
||
2723 | $capabilities[] = 'read_' . $capability_type; |
||
2724 | $capabilities[] = 'edit_' . $capability_type; |
||
2725 | $capabilities[] = 'delete_' . $capability_type; |
||
2726 | |||
2727 | if ( 1 == pods_var( 'capability_type_extra', $pod[ 'options' ], 1 ) ) { |
||
2728 | $capabilities[] = 'read_private_' . $capability_type . 's'; |
||
2729 | $capabilities[] = 'edit_' . $capability_type . 's'; |
||
2730 | $capabilities[] = 'edit_others_' . $capability_type . 's'; |
||
2731 | $capabilities[] = 'edit_private_' . $capability_type . 's'; |
||
2732 | $capabilities[] = 'edit_published_' . $capability_type . 's'; |
||
2733 | $capabilities[] = 'publish_' . $capability_type . 's'; |
||
2734 | $capabilities[] = 'delete_' . $capability_type . 's'; |
||
2735 | $capabilities[] = 'delete_private_' . $capability_type . 's'; |
||
2736 | $capabilities[] = 'delete_published_' . $capability_type . 's'; |
||
2737 | $capabilities[] = 'delete_others_' . $capability_type . 's'; |
||
2738 | } |
||
2739 | } |
||
2740 | } |
||
2741 | elseif ( 'taxonomy' == $pod[ 'type' ] ) { |
||
2742 | if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ], 'terms' ) ) { |
||
2743 | $capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) . 's' ); |
||
2744 | |||
2745 | $capability_type .= '_terms'; |
||
2746 | |||
2747 | $capabilities[] = 'manage_' . $capability_type; |
||
2748 | $capabilities[] = 'edit_' . $capability_type; |
||
2749 | $capabilities[] = 'delete_' . $capability_type; |
||
2750 | $capabilities[] = 'assign_' . $capability_type; |
||
2751 | } |
||
2752 | } |
||
2753 | else { |
||
2754 | $capabilities[] = 'pods_add_' . $pod[ 'name' ]; |
||
2755 | $capabilities[] = 'pods_edit_' . $pod[ 'name' ]; |
||
2756 | |||
2757 | if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] ) |
||
2758 | $capabilities[] = 'pods_edit_others_' . $pod[ 'name' ]; |
||
2759 | |||
2760 | $capabilities[] = 'pods_delete_' . $pod[ 'name' ]; |
||
2761 | |||
2762 | if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] ) |
||
2763 | $capabilities[] = 'pods_delete_others_' . $pod[ 'name' ]; |
||
2764 | |||
2765 | $actions_enabled = pods_var_raw( 'ui_actions_enabled', $pod[ 'options' ] ); |
||
2766 | |||
2767 | if ( !empty( $actions_enabled ) ) |
||
2768 | $actions_enabled = (array) $actions_enabled; |
||
2769 | else |
||
2770 | $actions_enabled = array(); |
||
2771 | |||
2772 | $available_actions = array( |
||
2773 | 'add', |
||
2774 | 'edit', |
||
2775 | 'duplicate', |
||
2776 | 'delete', |
||
2777 | 'reorder', |
||
2778 | 'export' |
||
2779 | ); |
||
2780 | |||
2781 | if ( !empty( $actions_enabled ) ) { |
||
2782 | $actions_disabled = array( |
||
2783 | 'view' => 'view' |
||
2784 | ); |
||
2785 | |||
2786 | foreach ( $available_actions as $action ) { |
||
2787 | if ( !in_array( $action, $actions_enabled ) ) |
||
2788 | $actions_disabled[ $action ] = $action; |
||
2789 | } |
||
2790 | |||
2791 | if ( !in_array( 'export', $actions_disabled ) ) |
||
2792 | $capabilities[] = 'pods_export_' . $pod[ 'name' ]; |
||
2793 | |||
2794 | if ( !in_array( 'reorder', $actions_disabled ) ) |
||
2795 | $capabilities[] = 'pods_reorder_' . $pod[ 'name' ]; |
||
2796 | } |
||
2797 | elseif ( 1 == pods_var( 'ui_export', $pod[ 'options' ], 0 ) ) |
||
2798 | $capabilities[] = 'pods_export_' . $pod[ 'name' ]; |
||
2799 | } |
||
2800 | } |
||
2801 | |||
2802 | return $capabilities; |
||
2803 | } |
||
2804 | |||
2805 | /** |
||
2806 | * Handle ajax calls for the administration |
||
2807 | */ |
||
2808 | public function admin_ajax () { |
||
2809 | if ( false === headers_sent() ) { |
||
2810 | pods_session_start(); |
||
2811 | |||
2812 | header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) ); |
||
2813 | } |
||
2814 | |||
2815 | // Sanitize input |
||
2816 | $params = pods_unslash( (array) $_POST ); |
||
2817 | |||
2818 | foreach ( $params as $key => $value ) { |
||
2819 | if ( 'action' == $key ) |
||
2820 | continue; |
||
2821 | |||
2822 | // Fixup $_POST data |
||
2823 | $_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ]; |
||
2824 | |||
3218 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.