Completed
Pull Request — 2.x (#4569)
by Scott Kingsley
04:46
created

PodsAdmin::admin_advanced()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @package Pods
5
 */
6
class PodsAdmin {
7
8
	/**
9
	 * @var PodsAdmin
10
	 */
11
	public static $instance = null;
12
13
	/**
14
	 * Singleton handling for a basic pods_admin() request
15
	 *
16
	 * @return \PodsAdmin
17
	 *
18
	 * @since 2.3.5
19
	 */
20
	public static function init() {
21
22
		if ( ! is_object( self::$instance ) ) {
23
			self::$instance = new PodsAdmin();
24
		}
25
26
		return self::$instance;
27
	}
28
29
	/**
30
	 * Setup and Handle Admin functionality
31
	 *
32
	 * @return \PodsAdmin
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
33
	 *
34
	 * @license http://www.gnu.org/licenses/gpl-2.0.html
35
	 * @since   2.0
36
	 */
37
	public function __construct() {
38
39
		// Scripts / Stylesheets
40
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 );
41
42
		// AJAX $_POST fix
43
		add_action( 'admin_init', array( $this, 'admin_init' ), 9 );
44
45
		// Menus
46
		add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 );
47
48
		// AJAX for Admin
49
		add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) );
50
		add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) );
51
52
		// Add Media Bar button for Shortcode
53
		add_action( 'media_buttons', array( $this, 'media_button' ), 12 );
54
55
		// Add the Pods capabilities
56
		add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) );
57
58
		add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) );
59
60
		$this->rest_admin();
61
62
	}
63
64
	/**
65
	 * Init the admin area
66
	 *
67
	 * @since 2.0
68
	 */
69
	public function admin_init() {
70
71
		// Fix for plugins that *don't do it right* so we don't cause issues for users
72
		// @codingStandardsIgnoreLine
73
		if ( defined( 'DOING_AJAX' ) && ! empty( $_POST ) ) {
74
			$pods_admin_ajax_actions = array(
75
				'pods_admin',
76
				'pods_relationship',
77
				'pods_upload',
78
				'pods_admin_components',
79
			);
80
81
			/**
82
			 * Admin AJAX Callbacks
83
			 *
84
			 * @since unknown
85
			 *
86
			 * @param array $pods_admin_ajax_actions Array of actions to handle.
87
			 */
88
			$pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions );
89
90
			if ( in_array( pods_v( 'action', 'get' ), $pods_admin_ajax_actions, true ) || in_array( pods_v( 'action', 'post' ), $pods_admin_ajax_actions, true ) ) {
91
				// @codingStandardsIgnoreLine
92
				foreach ( $_POST as $key => $value ) {
93
					if ( 'action' === $key || 0 === strpos( $key, '_podsfix_' ) ) {
94
						continue;
95
					}
96
97
					// @codingStandardsIgnoreLine
98
					unset( $_POST[ $key ] );
99
100
					// @codingStandardsIgnoreLine
101
					$_POST[ '_podsfix_' . $key ] = $value;
102
				}
103
			}
104
		}//end if
105
	}
106
107
	/**
108
	 * Attach requirements to admin header
109
	 *
110
	 * @since 2.0
111
	 */
112
	public function admin_head() {
113
114
		wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION );
115
116
		wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION );
117
118
		wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION );
119
120
		wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION );
121
122
		// @codingStandardsIgnoreLine
123
		if ( isset( $_GET['page'] ) ) {
124
			// @codingStandardsIgnoreLine
125
			$page = $_GET['page'];
126
			if ( 'pods' === $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) {
127
				?>
128
				<script type="text/javascript">
129
					var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>";
130
				</script>
131
				<?php
132
				wp_enqueue_script( 'jquery' );
133
				wp_enqueue_script( 'jquery-ui-core' );
134
				wp_enqueue_script( 'jquery-ui-sortable' );
135
136
				wp_enqueue_script( 'pods-floatmenu' );
137
138
				wp_enqueue_script( 'jquery-qtip2' );
139
				wp_enqueue_script( 'pods-qtip-init' );
140
141
				wp_enqueue_script( 'pods' );
142
143
				if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) ) {
144
					wp_enqueue_script( 'post' );
145
				} elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
146
					wp_enqueue_script( 'post' );
147
				}
148
149
				if ( 'pods-advanced' === $page ) {
150
					wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
151
					wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
152
					wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
153
					wp_enqueue_script( 'jquery-ui-dialog' );
154
					wp_enqueue_script( 'pods-advanced' );
155
				} elseif ( 'pods-packages' === $page ) {
156
					wp_enqueue_style( 'pods-wizard' );
157
				} elseif ( 'pods-wizard' === $page || 'pods-upgrade' === $page || ( in_array(
158
					$page, array(
159
						'pods',
160
						'pods-add-new',
161
					), true
162
				) && in_array(
163
					pods_v( 'action', 'get', 'manage' ), array(
164
						'add',
165
						'manage',
166
					), true
167
				) ) ) {
168
					wp_enqueue_style( 'pods-wizard' );
169
170
					if ( 'pods-upgrade' === $page ) {
171
						wp_enqueue_script( 'pods-upgrade' );
172
					}
173
				}//end if
174
			}//end if
175
		}//end if
176
177
		// New Styles Enqueue
178
		wp_enqueue_style( 'pods-styles' );
179
	}
180
181
	/**
182
	 * Build the admin menus
183
	 *
184
	 * @since 2.0
185
	 */
186
	public function admin_menu() {
187
188
		$advanced_content_types = PodsMeta::$advanced_content_types;
189
		$taxonomies             = PodsMeta::$taxonomies;
190
		$settings               = PodsMeta::$settings;
191
192
		$all_pods = pods_api()->load_pods( array( 'count' => true ) );
193
194
		if ( ! PodsInit::$upgrade_needed || ( pods_is_admin() && 1 === (int) pods_v( 'pods_upgrade_bypass' ) ) ) {
195
			$submenu_items = array();
196
197
			if ( ! empty( $advanced_content_types ) ) {
198
				$submenu = array();
199
200
				$pods_pages = 0;
201
202
				foreach ( (array) $advanced_content_types as $pod ) {
203
					if ( ! isset( $pod['name'] ) || ! isset( $pod['options'] ) || empty( $pod['fields'] ) ) {
204
						continue;
205
					} elseif ( ! pods_is_admin(
206
						array(
207
							'pods',
208
							'pods_content',
209
							'pods_add_' . $pod['name'],
210
							'pods_edit_' . $pod['name'],
211
							'pods_delete_' . $pod['name'],
212
						)
213
					) ) {
214
						continue;
215
					}
216
217
					$pod = apply_filters( 'pods_advanced_content_type_pod_data_' . $pod['name'], $pod, $pod['name'] );
218
					$pod = apply_filters( 'pods_advanced_content_type_pod_data', $pod, $pod['name'] );
219
220
					if ( 1 === (int) pods_v( 'show_in_menu', $pod['options'], 0 ) ) {
221
						$page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
222
						$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
223
224
						$menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
225
						$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
226
227
						$singular_label = pods_v( 'label_singular', $pod['options'], pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true ), true );
228
						$plural_label   = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
229
230
						$menu_location        = pods_v( 'menu_location', $pod['options'], 'objects' );
231
						$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
232
233
						$menu_position = pods_v( 'menu_position', $pod['options'], '', true );
234
						$menu_icon     = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
235
236
						if ( empty( $menu_position ) ) {
237
							$menu_position = null;
238
						}
239
240
						$parent_page = null;
241
242
						if ( pods_is_admin(
243
							array(
244
								'pods',
245
								'pods_content',
246
								'pods_edit_' . $pod['name'],
247
								'pods_delete_' . $pod['name'],
248
							)
249
						) ) {
250
							if ( ! empty( $menu_location_custom ) ) {
251
								if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
252
									$submenu_items[ $menu_location_custom ] = array();
253
								}
254
255
								$submenu_items[ $menu_location_custom ][] = array(
256
									$menu_location_custom,
257
									$page_title,
258
									$menu_label,
259
									'read',
260
									'pods-manage-' . $pod['name'],
261
									array( $this, 'admin_content' ),
262
								);
263
264
								continue;
265
							} else {
266
								$pods_pages ++;
267
268
								$page        = 'pods-manage-' . $pod['name'];
269
								$parent_page = $page;
270
271
								if ( empty( $menu_position ) ) {
272
									$menu_position = null;
273
								}
274
								add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
275
276
								$all_title = $plural_label;
277
								$all_label = pods_v( 'label_all_items', $pod['options'], __( 'All', 'pods' ) . ' ' . $plural_label );
278
279
								if ( pods_v( 'page', 'get' ) === $page ) {
280
									if ( 'edit' === pods_v( 'action', 'get', 'manage' ) ) {
281
										$all_title = pods_v( 'label_edit_item', $pod['options'], __( 'Edit', 'pods' ) . ' ' . $singular_label );
282
									} elseif ( 'add' === pods_v( 'action', 'get', 'manage' ) ) {
283
										$all_title = pods_v( 'label_add_new_item', $pod['options'], __( 'Add New', 'pods' ) . ' ' . $singular_label );
284
									}
285
								}
286
287
								add_submenu_page(
288
									$parent_page, $all_title, $all_label, 'read', $page, array(
289
										$this,
290
										'admin_content',
291
									)
292
								);
293
							}//end if
294
						}//end if
295
296
						if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod['name'] ) ) ) {
297
							$page = 'pods-add-new-' . $pod['name'];
298
299
							if ( null === $parent_page ) {
300
								$pods_pages ++;
301
302
								$parent_page = $page;
303
304
								if ( empty( $menu_position ) ) {
305
									$menu_position = null;
306
								}
307
								add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
308
							}
309
310
							$add_title = pods_v( 'label_add_new_item', $pod['options'], __( 'Add New', 'pods' ) . ' ' . $singular_label );
311
							$add_label = pods_v( 'label_add_new', $pod['options'], __( 'Add New', 'pods' ) );
312
313
							add_submenu_page(
314
								$parent_page, $add_title, $add_label, 'read', $page, array(
315
									$this,
316
									'admin_content',
317
								)
318
							);
319
						}//end if
320
					} else {
321
						$submenu[] = $pod;
322
					}//end if
323
				}//end foreach
324
325
				$submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu );
326
327
				if ( ! empty( $submenu ) && ( ! defined( 'PODS_DISABLE_CONTENT_MENU' ) || ! PODS_DISABLE_CONTENT_MENU ) ) {
328
					$parent_page = null;
329
330
					foreach ( $submenu as $item ) {
331
						$singular_label = pods_v( 'label_singular', $item['options'], pods_v( 'label', $item, ucwords( str_replace( '_', ' ', $item['name'] ) ), true ), true );
332
						$plural_label   = pods_v( 'label', $item, ucwords( str_replace( '_', ' ', $item['name'] ) ), true );
333
334
						if ( pods_is_admin(
335
							array(
336
								'pods',
337
								'pods_content',
338
								'pods_edit_' . $item['name'],
339
								'pods_delete_' . $item['name'],
340
							)
341
						) ) {
342
							$page = 'pods-manage-' . $item['name'];
343
344 View Code Duplication
							if ( null === $parent_page ) {
345
								$parent_page = $page;
346
347
								add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
348
							}
349
350
							$all_title = $plural_label;
351
							$all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
352
353
							if ( pods_v( 'page', 'get' ) === $page ) {
354
								if ( 'edit' === pods_v( 'action', 'get', 'manage' ) ) {
355
									$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
356
								} elseif ( 'add' === pods_v( 'action', 'get', 'manage' ) ) {
357
									$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
358
								}
359
							}
360
361
							add_submenu_page(
362
								$parent_page, $all_title, $all_label, 'read', $page, array(
363
									$this,
364
									'admin_content',
365
								)
366
							);
367
						} elseif ( current_user_can( 'pods_add_' . $item['name'] ) ) {
368
							$page = 'pods-add-new-' . $item['name'];
369
370 View Code Duplication
							if ( null === $parent_page ) {
371
								$parent_page = $page;
372
373
								add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
374
							}
375
376
							$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
377
							$add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
378
379
							add_submenu_page(
380
								$parent_page, $add_title, $add_label, 'read', $page, array(
381
									$this,
382
									'admin_content',
383
								)
384
							);
385
						}//end if
386
					}//end foreach
387
				}//end if
388
			}//end if
389
390
			if ( ! empty( $taxonomies ) ) {
391
				foreach ( (array) $taxonomies as $pod ) {
392
					// Default taxonomy capability
393
					$capability = 'manage_categories';
394
395
					if ( ! empty( $pod['options']['capability_type'] ) ) {
396
						if ( 'custom' === $pod['options']['capability_type'] && ! empty( $pod['options']['capability_type_custom'] ) ) {
397
							$capability = 'manage_' . (string) $pod['options']['capability_type_custom'] . '_terms';
398
						}
399
					}
400
401 View Code Duplication
					if ( ! pods_is_admin(
402
						array(
403
							'pods',
404
							'pods_content',
405
							'pods_edit_' . $pod['name'],
406
							$capability,
407
						)
408
					) ) {
409
						continue;
410
					}
411
412
					// Check UI settings
413
					if ( 1 !== (int) pods_v( 'show_ui', $pod['options'], 0 ) || 1 !== (int) pods_v( 'show_in_menu', $pod['options'], 0 ) ) {
414
						continue;
415
					}
416
417
					$page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
418
					$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
419
420
					$menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
421
					$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
422
423
					$menu_position = pods_v( 'menu_position', $pod['options'], '', true );
424
					$menu_icon     = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
425
426
					if ( empty( $menu_position ) ) {
427
						$menu_position = null;
428
					}
429
430
					$menu_slug            = 'edit-tags.php?taxonomy=' . $pod['name'];
431
					$menu_location        = pods_v( 'menu_location', $pod['options'], 'default' );
432
					$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
433
434
					if ( 'default' === $menu_location ) {
435
						continue;
436
					}
437
438
					$taxonomy_data = get_taxonomy( $pod['name'] );
439
440
					foreach ( (array) $taxonomy_data->object_type as $post_type ) {
441
						if ( 'post' === $post_type ) {
442
							remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod['name'] );
443
						} elseif ( 'attachment' === $post_type ) {
444
							remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod['name'] . '&amp;post_type=' . $post_type );
445
						} else {
446
							remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod['name'] . '&amp;post_type=' . $post_type );
447
						}
448
					}
449
450
					if ( 'settings' === $menu_location ) {
451
						add_options_page( $page_title, $menu_label, 'read', $menu_slug );
452
					} elseif ( 'appearances' === $menu_location ) {
453
						add_theme_page( $page_title, $menu_label, 'read', $menu_slug );
454 View Code Duplication
					} elseif ( 'objects' === $menu_location ) {
455
						if ( empty( $menu_position ) ) {
456
							$menu_position = null;
457
						}
458
						add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
459
					} elseif ( 'top' === $menu_location ) {
460
						add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
461 View Code Duplication
					} elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
462
						if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
463
							$submenu_items[ $menu_location_custom ] = array();
464
						}
465
466
						$submenu_items[ $menu_location_custom ][] = array(
467
							$menu_location_custom,
468
							$page_title,
469
							$menu_label,
470
							'read',
471
							$menu_slug,
472
							'',
473
						);
474
					}//end if
475
				}//end foreach
476
			}//end if
477
478
			if ( ! empty( $settings ) ) {
479
				foreach ( (array) $settings as $pod ) {
480 View Code Duplication
					if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
481
						continue;
482
					}
483
484
					$page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
485
					$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
486
487
					$menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
488
					$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
489
490
					$menu_position = pods_v( 'menu_position', $pod['options'], '', true );
491
					$menu_icon     = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
492
493
					if ( empty( $menu_position ) ) {
494
						$menu_position = null;
495
					}
496
497
					$menu_slug            = 'pods-settings-' . $pod['name'];
498
					$menu_location        = pods_v( 'menu_location', $pod['options'], 'settings' );
499
					$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
500
501
					if ( 'settings' === $menu_location ) {
502
						add_options_page(
503
							$page_title, $menu_label, 'read', $menu_slug, array(
504
								$this,
505
								'admin_content_settings',
506
							)
507
						);
508
					} elseif ( 'appearances' === $menu_location ) {
509
						add_theme_page(
510
							$page_title, $menu_label, 'read', $menu_slug, array(
511
								$this,
512
								'admin_content_settings',
513
							)
514
						);
515 View Code Duplication
					} elseif ( 'objects' === $menu_location ) {
516
						if ( empty( $menu_position ) ) {
517
							$menu_position = null;
518
						}
519
						add_menu_page(
520
							$page_title, $menu_label, 'read', $menu_slug, array(
521
								$this,
522
								'admin_content_settings',
523
							), $menu_icon, $menu_position
524
						);
525
					} elseif ( 'top' === $menu_location ) {
526
						add_menu_page(
527
							$page_title, $menu_label, 'read', $menu_slug, array(
528
								$this,
529
								'admin_content_settings',
530
							), $menu_icon, $menu_position
531
						);
532 View Code Duplication
					} elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
533
						if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
534
							$submenu_items[ $menu_location_custom ] = array();
535
						}
536
537
						$submenu_items[ $menu_location_custom ][] = array(
538
							$menu_location_custom,
539
							$page_title,
540
							$menu_label,
541
							'read',
542
							$menu_slug,
543
							array( $this, 'admin_content_settings' ),
544
						);
545
					}//end if
546
				}//end foreach
547
			}//end if
548
549
			foreach ( $submenu_items as $items ) {
550
				foreach ( $items as $item ) {
551
					call_user_func_array( 'add_submenu_page', $item );
552
				}
553
			}
554
555
			$admin_menus = array(
556
				'pods'            => array(
557
					'label'    => __( 'Edit Pods', 'pods' ),
558
					'function' => array( $this, 'admin_setup' ),
559
					'access'   => 'pods',
560
				),
561
				'pods-add-new'    => array(
562
					'label'    => __( 'Add New', 'pods' ),
563
					'function' => array( $this, 'admin_setup' ),
564
					'access'   => 'pods',
565
				),
566
				'pods-components' => array(
567
					'label'    => __( 'Components', 'pods' ),
568
					'function' => array( $this, 'admin_components' ),
569
					'access'   => 'pods_components',
570
				),
571
				'pods-settings'   => array(
572
					'label'    => __( 'Settings', 'pods' ),
573
					'function' => array( $this, 'admin_settings' ),
574
					'access'   => 'pods_settings',
575
				),
576
				'pods-help'       => array(
577
					'label'    => __( 'Help', 'pods' ),
578
					'function' => array( $this, 'admin_help' ),
579
				),
580
			);
581
582
			if ( empty( $all_pods ) ) {
583
				unset( $admin_menus['pods'] );
584
			}
585
586
			add_filter( 'parent_file', array( $this, 'parent_file' ) );
587
		} else {
588
			$admin_menus = array(
589
				'pods-upgrade'  => array(
590
					'label'    => __( 'Upgrade', 'pods' ),
591
					'function' => array( $this, 'admin_upgrade' ),
592
					'access'   => 'manage_options',
593
				),
594
				'pods-settings' => array(
595
					'label'    => __( 'Settings', 'pods' ),
596
					'function' => array( $this, 'admin_settings' ),
597
					'access'   => 'pods_settings',
598
				),
599
				'pods-help'     => array(
600
					'label'    => __( 'Help', 'pods' ),
601
					'function' => array( $this, 'admin_help' ),
602
				),
603
			);
604
605
			add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
606
		}//end if
607
608
		/**
609
		 * Add or change Pods Admin menu items
610
		 *
611
		 * @param array $admin_menus The submenu items in Pods Admin menu.
612
		 *
613
		 * @since  unknown
614
		 */
615
		$admin_menus = apply_filters( 'pods_admin_menu', $admin_menus );
616
617
		$parent = false;
618
619
		// PODS_LIGHT disables all Pods components so remove the components menu
620
		if ( defined( 'PODS_LIGHT' ) && true === PODS_LIGHT ) {
621
			unset( $admin_menus['pods-components'] );
622
		}
623
624
		if ( ! empty( $admin_menus ) && ( ! defined( 'PODS_DISABLE_ADMIN_MENU' ) || ! PODS_DISABLE_ADMIN_MENU ) ) {
625
			foreach ( $admin_menus as $page => $menu_item ) {
626
				if ( ! pods_is_admin( pods_v( 'access', $menu_item ) ) ) {
627
					continue;
628
				}
629
630
				// Don't just show the help page
631
				if ( false === $parent && 'pods-help' === $page ) {
632
					continue;
633
				}
634
635
				if ( ! isset( $menu_item['label'] ) ) {
636
					$menu_item['label'] = $page;
637
				}
638
639
				if ( false === $parent ) {
640
					$parent = $page;
641
642
					$menu = __( 'Pods Admin', 'pods' );
643
644
					if ( 'pods-upgrade' === $parent ) {
645
						$menu = __( 'Pods Upgrade', 'pods' );
646
					}
647
648
					add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' );
649
				}
650
651
				add_submenu_page( $parent, $menu_item['label'], $menu_item['label'], 'read', $page, $menu_item['function'] );
652
653
				if ( 'pods-components' === $page && is_object( PodsInit::$components ) ) {
654
					PodsInit::$components->menu( $parent );
655
				}
656
			}//end foreach
657
		}//end if
658
	}
659
660
	/**
661
	 * Set the correct parent_file to highlight the correct top level menu
662
	 *
663
	 * @param string $parent_file The parent file
664
	 *
665
	 * @return mixed|string
666
	 *
667
	 * @since unknown
668
	 */
669
	public function parent_file( $parent_file ) {
670
671
		global $current_screen;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
672
673
		if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) {
674
			$taxonomies = PodsMeta::$taxonomies;
675
			if ( ! empty( $taxonomies ) ) {
676
				foreach ( (array) $taxonomies as $pod ) {
677
					if ( $current_screen->taxonomy !== $pod['name'] ) {
678
						continue;
679
					}
680
681
					$menu_slug            = 'edit-tags.php?taxonomy=' . $pod['name'];
682
					$menu_location        = pods_v( 'menu_location', $pod['options'], 'default' );
683
					$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
684
685
					if ( 'settings' === $menu_location ) {
686
						$parent_file = 'options-general.php';
687
					} elseif ( 'appearances' === $menu_location ) {
688
						$parent_file = 'themes.php';
689
					} elseif ( 'objects' === $menu_location ) {
690
						$parent_file = $menu_slug;
691
					} elseif ( 'top' === $menu_location ) {
692
						$parent_file = $menu_slug;
693
					} elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
694
						$parent_file = $menu_location_custom;
695
					}
696
697
					break;
698
				}//end foreach
699
			}//end if
700
		}//end if
701
702
		if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) && is_object( PodsInit::$components ) ) {
703
			global $submenu_file;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
704
			$components = PodsInit::$components->components;
705
			foreach ( $components as $component => $component_data ) {
706
				if ( ! empty( $component_data['MenuPage'] ) && $parent_file === $component_data['MenuPage'] ) {
707
					$parent_file = 'pods';
708
709
					// @codingStandardsIgnoreLine
710
					$submenu_file = $component_data['MenuPage'];
711
				}
712
			}
713
		}
714
715
		return $parent_file;
716
	}
717
718
	/**
719
	 * Show upgrade notice.
720
	 */
721
	public function upgrade_notice() {
722
723
		echo '<div class="error fade"><p>';
724
		// @codingStandardsIgnoreLine
725
		echo sprintf( __( '<strong>NOTICE:</strong> Pods %1$s requires your action to complete the upgrade. Please run the <a href="%2$s">Upgrade Wizard</a>.', 'pods' ), esc_html( PODS_VERSION ), esc_url( admin_url( 'admin.php?page=pods-upgrade' ) ) );
726
		echo '</p></div>';
727
	}
728
729
	/**
730
	 * Create PodsUI content for the administration pages
731
	 */
732
	public function admin_content() {
733
734
		// @codingStandardsIgnoreLine
735
		$pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET['page'] );
736
737
		$pod = pods( $pod_name, pods_v( 'id', 'get', null, true ) );
738
739
		// @codingStandardsIgnoreLine
740
		if ( false !== strpos( $_GET['page'], 'pods-add-new-' ) ) {
741
			// @codingStandardsIgnoreLine
742
			$_GET['action'] = pods_v( 'action', 'get', 'add' );
743
		}
744
745
		$pod->ui();
746
	}
747
748
	/**
749
	 * Create PodsUI content for the settings administration pages
750
	 */
751
	public function admin_content_settings() {
752
753
		// @codingStandardsIgnoreLine
754
		$pod_name = str_replace( 'pods-settings-', '', $_GET['page'] );
755
756
		$pod = pods( $pod_name );
757
758
		if ( 'custom' !== pods_v( 'ui_style', $pod->pod_data['options'], 'settings', true ) ) {
759
			$actions_disabled = array(
760
				'manage'    => 'manage',
761
				'add'       => 'add',
762
				'delete'    => 'delete',
763
				'duplicate' => 'duplicate',
764
				'view'      => 'view',
765
				'export'    => 'export',
766
			);
767
768
			// @codingStandardsIgnoreLine
769
			$_GET['action'] = 'edit';
770
771
			$page_title = pods_v( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data['name'] ) ), true );
772
			$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod->pod_data );
773
774
			$ui = array(
775
				'pod'              => $pod,
776
				'fields'           => array(
777
					'edit' => $pod->pod_data['fields'],
778
				),
779
				'header'           => array(
780
					'edit' => $page_title,
781
				),
782
				'label'            => array(
783
					'edit' => __( 'Save Changes', 'pods' ),
784
				),
785
				'style'            => pods_v( 'ui_style', $pod->pod_data['options'], 'settings', true ),
786
				'icon'             => pods_evaluate_tags( pods_v( 'menu_icon', $pod->pod_data['options'] ), true ),
787
				'actions_disabled' => $actions_disabled,
788
			);
789
790
			$ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod );
791
792
			// Force disabled actions, do not pass go, do not collect $two_hundred
793
			$ui['actions_disabled'] = $actions_disabled;
794
795
			pods_ui( $ui );
796
		} else {
797
			do_action( 'pods_admin_ui_custom', $pod );
798
			do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod );
799
		}//end if
800
	}
801
802
	/**
803
	 * Add media button for Pods shortcode
804
	 *
805
	 * @param string $context Media button context.
806
	 *
807
	 * @return string
808
	 */
809
	public function media_button( $context = null ) {
810
811
		// If shortcodes are disabled don't show the button
812
		if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
813
			return '';
814
		}
815
816
		/**
817
		 * Filter to remove Pods shortcode button from the post editor.
818
		 *
819
		 * @param bool   $show_button Set to false to block the shortcode button from appearing.
820
		 * @param string $context     Media button context.
821
		 *
822
		 * @since 2.3.19
823
		 */
824
		if ( ! apply_filters( 'pods_admin_media_button', true, $context ) ) {
825
			return '';
826
		}
827
828
		$current_page = basename( $_SERVER['PHP_SELF'] );
829
		$current_page = explode( '?', $current_page );
830
		$current_page = explode( '#', $current_page[0] );
831
		$current_page = $current_page[0];
832
833
		// Only show the button on post type pages
834
		if ( ! in_array(
835
			$current_page, array(
836
				'post-new.php',
837
				'post.php',
838
			), true
839
		) ) {
840
			return '';
841
		}
842
843
		add_action( 'admin_footer', array( $this, 'mce_popup' ) );
844
845
		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="' . esc_url( PODS_URL . 'ui/images/icon16.png' ) . '" alt="' . esc_attr__( 'Pods Shortcode', 'pods' ) . '" />' . esc_html__( 'Pods Shortcode', 'pods' ) . '</a>';
846
	}
847
848
	/**
849
	 * Enqueue assets for Media Library Popup
850
	 */
851
	public function register_media_assets() {
852
853
		if ( 'pods_media_attachment' === pods_v( 'inlineId', 'get' ) ) {
854
			wp_enqueue_style( 'pods-styles' );
855
		}
856
	}
857
858
	/**
859
	 * Output Pods shortcode popup window
860
	 */
861
	public function mce_popup() {
862
863
		pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) );
864
	}
865
866
	/**
867
	 * Handle main Pods Setup area for managing Pods and Fields
868
	 */
869
	public function admin_setup() {
870
871
		$pods = pods_api()->load_pods( array( 'fields' => false ) );
872
873
		$view = pods_v( 'view', 'get', 'all', true );
874
875
		// @codingStandardsIgnoreLine
876
		if ( empty( $pods ) && ! isset( $_GET['action'] ) ) {
877
			// @codingStandardsIgnoreLine
878
			$_GET['action'] = 'add';
879
		}
880
881
		// @codingStandardsIgnoreLine
882
		if ( 'pods-add-new' === $_GET['page'] ) {
883
			// @codingStandardsIgnoreLine
884
			if ( isset( $_GET['action'] ) && 'add' !== $_GET['action'] ) {
885
				pods_redirect(
886
					pods_query_arg(
887
						array(
888
							'page'   => 'pods',
889
							// @codingStandardsIgnoreLine
890
							'action' => $_GET['action'],
891
						)
892
					)
893
				);
894
			} else {
895
				// @codingStandardsIgnoreLine
896
				$_GET['action'] = 'add';
897
			}
898
			// @codingStandardsIgnoreLine
899
		} elseif ( isset( $_GET['action'] ) && 'add' === $_GET['action'] ) {
900
			pods_redirect(
901
				pods_query_arg(
902
					array(
903
						'page'   => 'pods-add-new',
904
						'action' => '',
905
					)
906
				)
907
			);
908
		}//end if
909
910
		$types = array(
911
			'post_type' => __( 'Post Type (extended)', 'pods' ),
912
			'taxonomy'  => __( 'Taxonomy (extended)', 'pods' ),
913
			'cpt'       => __( 'Custom Post Type', 'pods' ),
914
			'ct'        => __( 'Custom Taxonomy', 'pods' ),
915
			'user'      => __( 'User (extended)', 'pods' ),
916
			'media'     => __( 'Media (extended)', 'pods' ),
917
			'comment'   => __( 'Comments (extended)', 'pods' ),
918
			'pod'       => __( 'Advanced Content Type', 'pods' ),
919
			'settings'  => __( 'Custom Settings Page', 'pods' ),
920
		);
921
922
		$row = false;
923
924
		$pod_types_found = array();
925
926
		$fields = array(
927
			'label'       => array( 'label' => __( 'Label', 'pods' ) ),
928
			'name'        => array( 'label' => __( 'Name', 'pods' ) ),
929
			'type'        => array( 'label' => __( 'Type', 'pods' ) ),
930
			'storage'     => array(
931
				'label' => __( 'Storage Type', 'pods' ),
932
				'width' => '10%',
933
			),
934
			'field_count' => array(
935
				'label' => __( 'Number of Fields', 'pods' ),
936
				'width' => '8%',
937
			),
938
		);
939
940
		$total_fields = 0;
941
942
		foreach ( $pods as $k => $pod ) {
0 ignored issues
show
Bug introduced by
The expression $pods of type array|object|integer|double|string|null|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
943
			if ( isset( $types[ $pod['type'] ] ) ) {
944
				if ( in_array(
945
					$pod['type'], array(
946
						'post_type',
947
						'taxonomy',
948
					), true
949
				) ) {
950
					if ( empty( $pod['object'] ) ) {
951
						if ( 'post_type' === $pod['type'] ) {
952
							$pod['type'] = 'cpt';
953
						} else {
954
							$pod['type'] = 'ct';
955
						}
956
					}
957
				}
958
959
				if ( ! isset( $pod_types_found[ $pod['type'] ] ) ) {
960
					$pod_types_found[ $pod['type'] ] = 1;
961
				} else {
962
					$pod_types_found[ $pod['type'] ] ++;
963
				}
964
965
				if ( 'all' !== $view && $view !== $pod['type'] ) {
966
					unset( $pods[ $k ] );
967
968
					continue;
969
				}
970
971
				$pod['real_type'] = $pod['type'];
972
				$pod['type']      = $types[ $pod['type'] ];
973
			} elseif ( 'all' !== $view ) {
974
				continue;
975
			}//end if
976
977
			$pod['storage'] = ucwords( $pod['storage'] );
978
979
			// @codingStandardsIgnoreLine
980
			if ( $pod['id'] == pods_v( 'id' ) && 'delete' !== pods_v( 'action' ) ) {
981
				$row = $pod;
982
			}
983
984
			$pod = array(
985
				'id'          => $pod['id'],
986
				'label'       => pods_v( 'label', $pod ),
987
				'name'        => pods_v( 'name', $pod ),
988
				'object'      => pods_v( 'object', $pod ),
989
				'type'        => pods_v( 'type', $pod ),
990
				'real_type'   => pods_v( 'real_type', $pod ),
991
				'storage'     => pods_v( 'storage', $pod ),
992
				'field_count' => count( $pod['fields'] ),
993
			);
994
995
			$total_fields += $pod['field_count'];
996
997
			$pods[ $k ] = $pod;
998
		}//end foreach
999
1000
		if ( false === $row && 0 < pods_v( 'id' ) && 'delete' !== pods_v( 'action' ) ) {
1001
			pods_message( 'Pod not found', 'error' );
1002
1003
			// @codingStandardsIgnoreLine
1004
			unset( $_GET['id'], $_GET['action'] );
1005
		}
1006
1007
		$ui = array(
1008
			'data'             => $pods,
1009
			'row'              => $row,
1010
			'total'            => count( $pods ),
1011
			'total_found'      => count( $pods ),
1012
			'items'            => 'Pods',
1013
			'item'             => 'Pod',
1014
			'fields'           => array(
1015
				'manage' => $fields,
1016
			),
1017
			'actions_disabled' => array( 'view', 'export' ),
1018
			'actions_custom'   => array(
1019
				'add'       => array( $this, 'admin_setup_add' ),
1020
				'edit'      => array( $this, 'admin_setup_edit' ),
1021
				'duplicate' => array(
1022
					'callback'          => array( $this, 'admin_setup_duplicate' ),
1023
					'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' ),
1024
				),
1025
				'reset'     => array(
1026
					'label'             => __( 'Delete All Items', 'pods' ),
1027
					'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' ),
1028
					'callback'          => array( $this, 'admin_setup_reset' ),
1029
					'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ),
1030
					'nonce'             => true,
1031
				),
1032
				'delete'    => array( $this, 'admin_setup_delete' ),
1033
			),
1034
			'action_links'     => array(
1035
				'add' => pods_query_arg(
1036
					array(
1037
						'page'   => 'pods-add-new',
1038
						'action' => '',
1039
						'id'     => '',
1040
						'do'     => '',
1041
					)
1042
				),
1043
			),
1044
			'search'           => false,
1045
			'searchable'       => false,
1046
			'sortable'         => true,
1047
			'pagination'       => false,
1048
			'extra'            => array(
1049
				'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' ),
1050
			),
1051
		);
1052
1053
		if ( 1 < count( $pod_types_found ) ) {
1054
			$ui['views']            = array( 'all' => __( 'All', 'pods' ) );
1055
			$ui['view']             = $view;
1056
			$ui['heading']          = array( 'views' => __( 'Type', 'pods' ) );
1057
			$ui['filters_enhanced'] = true;
1058
1059
			foreach ( $pod_types_found as $pod_type => $number_found ) {
1060
				$ui['views'][ $pod_type ] = $types[ $pod_type ];
1061
			}
1062
		}
1063
1064
		pods_ui( $ui );
1065
	}
1066
1067
	/**
1068
	 * Get the add page of an object
1069
	 *
1070
	 * @param PodsUI $obj PodsUI object.
1071
	 */
1072
	public function admin_setup_add( $obj ) {
1073
1074
		pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) );
1075
	}
1076
1077
	/**
1078
	 * Get the edit page of an object
1079
	 *
1080
	 * @param boolean $duplicate Whether the screen is for duplicating.
1081
	 * @param PodsUI  $obj       PodsUI object.
1082
	 */
1083
	public function admin_setup_edit( $duplicate, $obj ) {
1084
1085
		pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) );
1086
	}
1087
1088
	/**
1089
	 * Get list of Pod option tabs
1090
	 *
1091
	 * @param array $pod Pod options.
1092
	 *
1093
	 * @return array
1094
	 */
1095
	public function admin_setup_edit_tabs( $pod ) {
1096
1097
		$fields   = true;
1098
		$labels   = false;
1099
		$admin_ui = false;
1100
		$advanced = false;
1101
1102
		if ( 'post_type' === pods_v( 'type', $pod ) && '' === pods_v( 'object', $pod ) ) {
1103
			$labels   = true;
1104
			$admin_ui = true;
1105
			$advanced = true;
1106
		} elseif ( 'taxonomy' === pods_v( 'type', $pod ) && '' === pods_v( 'object', $pod ) ) {
1107
			$labels   = true;
1108
			$admin_ui = true;
1109
			$advanced = true;
1110
		} elseif ( 'pod' === pods_v( 'type', $pod ) ) {
1111
			$labels   = true;
1112
			$admin_ui = true;
1113
			$advanced = true;
1114
		} elseif ( 'settings' === pods_v( 'type', $pod ) ) {
1115
			$labels   = true;
1116
			$admin_ui = true;
1117
		}
1118
1119
		if ( ! function_exists( 'get_term_meta' ) && 'none' === pods_v( 'storage', $pod, 'none', true ) && 'taxonomy' === pods_v( 'type', $pod ) ) {
1120
			$fields = false;
1121
		}
1122
1123
		$tabs = array();
1124
1125
		if ( $fields ) {
1126
			$tabs['manage-fields'] = __( 'Manage Fields', 'pods' );
1127
		}
1128
1129
		if ( $labels ) {
1130
			$tabs['labels'] = __( 'Labels', 'pods' );
1131
		}
1132
1133
		if ( $admin_ui ) {
1134
			$tabs['admin-ui'] = __( 'Admin UI', 'pods' );
1135
		}
1136
1137
		if ( $advanced ) {
1138
			$tabs['advanced'] = __( 'Advanced Options', 'pods' );
1139
		}
1140
1141
		if ( 'taxonomy' === pods_v( 'type', $pod ) && ! $fields ) {
1142
			$tabs['extra-fields'] = __( 'Extra Fields', 'pods' );
1143
		}
1144
1145
		$addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) );
1146
1147
		/**
1148
		 * Add or modify tabs in Pods editor for a specific Pod
1149
		 *
1150
		 * @param array  $tabs       Tabs to set.
1151
		 * @param object $pod        Current Pods object.
1152
		 * @param array  $addtl_args Additional args.
1153
		 *
1154
		 * @since  unknown
1155
		 */
1156
		$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod['type'] . '_' . $pod['name'], $tabs, $pod, $addtl_args );
1157
1158
		/**
1159
		 * Add or modify tabs for any Pod in Pods editor of a specific post type.
1160
		 */
1161
		$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod['type'], $tabs, $pod, $addtl_args );
1162
1163
		/**
1164
		 * Add or modify tabs in Pods editor for all pods.
1165
		 */
1166
		$tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args );
1167
1168
		return $tabs;
1169
	}
1170
1171
	/**
1172
	 * Get list of Pod options
1173
	 *
1174
	 * @param array $pod Pod options.
1175
	 *
1176
	 * @return array
1177
	 */
1178
	public function admin_setup_edit_options( $pod ) {
1179
1180
		$options = array();
1181
1182
		if ( '' === pods_v( 'object', $pod ) && 'settings' !== pods_v( 'type', $pod ) ) {
1183
			$labels = array(
1184
				'label'                            => array(
1185
					'label'           => __( 'Label', 'pods' ),
1186
					'help'            => __( 'help', 'pods' ),
1187
					'type'            => 'text',
1188
					'default'         => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
1189
					'text_max_length' => 30,
1190
				),
1191
				'label_singular'                   => array(
1192
					'label'           => __( 'Singular Label', 'pods' ),
1193
					'help'            => __( 'help', 'pods' ),
1194
					'type'            => 'text',
1195
					'default'         => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
1196
					'text_max_length' => 30,
1197
				),
1198
				'label_add_new'                    => array(
1199
					'label'       => __( 'Add New', 'pods' ),
1200
					'help'        => __( 'help', 'pods' ),
1201
					'type'        => 'text',
1202
					'default'     => '',
1203
					'object_type' => array( 'post_type', 'pod' ),
1204
				),
1205
				'label_add_new_item'               => array(
1206
					'label'   => __( 'Add new <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1207
					'help'    => __( 'help', 'pods' ),
1208
					'type'    => 'text',
1209
					'default' => '',
1210
				),
1211
				'label_new_item'                   => array(
1212
					'label'       => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1213
					'help'        => __( 'help', 'pods' ),
1214
					'type'        => 'text',
1215
					'default'     => '',
1216
					'object_type' => array( 'post_type', 'pod' ),
1217
				),
1218
				'label_new_item_name'              => array(
1219
					'label'       => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span> Name', 'pods' ),
1220
					'help'        => __( 'help', 'pods' ),
1221
					'type'        => 'text',
1222
					'default'     => '',
1223
					'object_type' => array( 'taxonomy' ),
1224
				),
1225
				'label_edit'                       => array(
1226
					'label'       => __( 'Edit', 'pods' ),
1227
					'help'        => __( 'help', 'pods' ),
1228
					'type'        => 'text',
1229
					'default'     => '',
1230
					'object_type' => array( 'pod' ),
1231
				),
1232
				'label_edit_item'                  => array(
1233
					'label'   => __( 'Edit <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1234
					'help'    => __( 'help', 'pods' ),
1235
					'type'    => 'text',
1236
					'default' => '',
1237
				),
1238
				'label_update_item'                => array(
1239
					'label'       => __( 'Update <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1240
					'help'        => __( 'help', 'pods' ),
1241
					'type'        => 'text',
1242
					'default'     => '',
1243
					'object_type' => array( 'taxonomy', 'pod' ),
1244
				),
1245
				'label_duplicate'                  => array(
1246
					'label'       => __( 'Duplicate', 'pods' ),
1247
					'help'        => __( 'help', 'pods' ),
1248
					'type'        => 'text',
1249
					'default'     => '',
1250
					'object_type' => array( 'pod' ),
1251
				),
1252
				'label_duplicate_item'             => array(
1253
					'label'       => __( 'Duplicate <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1254
					'help'        => __( 'help', 'pods' ),
1255
					'type'        => 'text',
1256
					'default'     => '',
1257
					'object_type' => array( 'pod' ),
1258
				),
1259
				'label_delete_item'                => array(
1260
					'label'       => __( 'Delete <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1261
					'help'        => __( 'help', 'pods' ),
1262
					'type'        => 'text',
1263
					'default'     => '',
1264
					'object_type' => array( 'pod' ),
1265
				),
1266
				'label_view'                       => array(
1267
					'label'       => __( 'View', 'pods' ),
1268
					'help'        => __( 'help', 'pods' ),
1269
					'type'        => 'text',
1270
					'default'     => '',
1271
					'object_type' => array( 'pod' ),
1272
				),
1273
				'label_view_item'                  => array(
1274
					'label'   => __( 'View <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1275
					'help'    => __( 'help', 'pods' ),
1276
					'type'    => 'text',
1277
					'default' => '',
1278
				),
1279
				'label_view_items'                 => array(
1280
					'label'       => __( 'View <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1281
					'help'        => __( 'help', 'pods' ),
1282
					'type'        => 'text',
1283
					'default'     => '',
1284
					'object_type' => array( 'post_type' ),
1285
				),
1286
				'label_back_to_manage'             => array(
1287
					'label'       => __( 'Back to Manage', 'pods' ),
1288
					'help'        => __( 'help', 'pods' ),
1289
					'type'        => 'text',
1290
					'default'     => '',
1291
					'object_type' => array( 'pod' ),
1292
				),
1293
				'label_manage'                     => array(
1294
					'label'       => __( 'Manage', 'pods' ),
1295
					'help'        => __( 'help', 'pods' ),
1296
					'type'        => 'text',
1297
					'default'     => '',
1298
					'object_type' => array( 'pod' ),
1299
				),
1300
				'label_manage_items'               => array(
1301
					'label'       => __( 'Manage <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1302
					'help'        => __( 'help', 'pods' ),
1303
					'type'        => 'text',
1304
					'default'     => '',
1305
					'object_type' => array( 'pod' ),
1306
				),
1307
				'label_reorder'                    => array(
1308
					'label'       => __( 'Reorder', 'pods' ),
1309
					'help'        => __( 'help', 'pods' ),
1310
					'type'        => 'text',
1311
					'default'     => '',
1312
					'object_type' => array( 'pod' ),
1313
				),
1314
				'label_reorder_items'              => array(
1315
					'label'       => __( 'Reorder <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1316
					'help'        => __( 'help', 'pods' ),
1317
					'type'        => 'text',
1318
					'default'     => '',
1319
					'object_type' => array( 'pod' ),
1320
				),
1321
				'label_all_items'                  => array(
1322
					'label'   => __( 'All <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1323
					'help'    => __( 'help', 'pods' ),
1324
					'type'    => 'text',
1325
					'default' => '',
1326
				),
1327
				'label_search'                     => array(
1328
					'label'       => __( 'Search', 'pods' ),
1329
					'help'        => __( 'help', 'pods' ),
1330
					'type'        => 'text',
1331
					'default'     => '',
1332
					'object_type' => array( 'pod' ),
1333
				),
1334
				'label_search_items'               => array(
1335
					'label'   => __( 'Search <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1336
					'help'    => __( 'help', 'pods' ),
1337
					'type'    => 'text',
1338
					'default' => '',
1339
				),
1340
				'label_popular_items'              => array(
1341
					'label'       => __( 'Popular <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1342
					'help'        => __( 'help', 'pods' ),
1343
					'type'        => 'text',
1344
					'default'     => '',
1345
					'object_type' => array( 'taxonomy' ),
1346
				),
1347
				// @todo Why was label_parent added previously? Can't find it in WP
1348
				'label_parent'                     => array(
1349
					'label'       => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1350
					'help'        => __( 'help', 'pods' ),
1351
					'type'        => 'text',
1352
					'default'     => '',
1353
					'object_type' => array( 'post_type', 'pod' ),
1354
				),
1355
				'label_parent_item'                => array(
1356
					'label'       => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1357
					'help'        => __( 'help', 'pods' ),
1358
					'type'        => 'text',
1359
					'default'     => '',
1360
					'object_type' => array( 'taxonomy' ),
1361
				),
1362
				'label_parent_item_colon'          => array(
1363
					'label'   => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>:', 'pods' ),
1364
					'help'    => __( 'help', 'pods' ),
1365
					'type'    => 'text',
1366
					'default' => '',
1367
				),
1368
				'label_not_found'                  => array(
1369
					'label'   => __( 'Not Found', 'pods' ),
1370
					'help'    => __( 'help', 'pods' ),
1371
					'type'    => 'text',
1372
					'default' => '',
1373
				),
1374
				'label_no_items_found'             => array(
1375
					'label'       => __( 'No <span class="pods-slugged" data-sluggable="label_singular">Item</span> Found', 'pods' ),
1376
					'help'        => __( 'help', 'pods' ),
1377
					'type'        => 'text',
1378
					'default'     => '',
1379
					'object_type' => array( 'pod' ),
1380
				),
1381
				'label_not_found_in_trash'         => array(
1382
					'label'       => __( 'Not Found in Trash', 'pods' ),
1383
					'help'        => __( 'help', 'pods' ),
1384
					'type'        => 'text',
1385
					'default'     => '',
1386
					'object_type' => array( 'post_type', 'pod' ),
1387
				),
1388
				'label_archives'                   => array(
1389
					'label'       => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Archives', 'pods' ),
1390
					'help'        => __( 'help', 'pods' ),
1391
					'type'        => 'text',
1392
					'default'     => '',
1393
					'object_type' => array( 'post_type' ),
1394
				),
1395
				'label_attributes'                 => array(
1396
					'label'       => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Attributes', 'pods' ),
1397
					'help'        => __( 'help', 'pods' ),
1398
					'type'        => 'text',
1399
					'default'     => '',
1400
					'object_type' => array( 'post_type' ),
1401
				),
1402
				'label_insert_into_item'           => array(
1403
					'label'       => __( 'Insert into <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1404
					'help'        => __( 'help', 'pods' ),
1405
					'type'        => 'text',
1406
					'default'     => '',
1407
					'object_type' => array( 'post_type' ),
1408
				),
1409
				'label_uploaded_to_this_item'      => array(
1410
					'label'       => __( 'Uploaded to this <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1411
					'help'        => __( 'help', 'pods' ),
1412
					'type'        => 'text',
1413
					'default'     => '',
1414
					'object_type' => array( 'post_type' ),
1415
				),
1416
				'label_featured_image'             => array(
1417
					'label'       => __( 'Featured Image', 'pods' ),
1418
					'help'        => __( 'help', 'pods' ),
1419
					'type'        => 'text',
1420
					'default'     => '',
1421
					// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1422
					'object_type' => array( 'post_type' ),
1423
				),
1424
				'label_set_featured_image'         => array(
1425
					'label'       => __( 'Set featured Image', 'pods' ),
1426
					'help'        => __( 'help', 'pods' ),
1427
					'type'        => 'text',
1428
					'default'     => '',
1429
					// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1430
					'object_type' => array( 'post_type' ),
1431
				),
1432
				'label_remove_featured_image'      => array(
1433
					'label'       => __( 'Remove featured Image', 'pods' ),
1434
					'help'        => __( 'help', 'pods' ),
1435
					'type'        => 'text',
1436
					'default'     => '',
1437
					// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1438
					'object_type' => array( 'post_type' ),
1439
				),
1440
				'label_use_featured_image'         => array(
1441
					'label'       => __( 'Use as featured Image', 'pods' ),
1442
					'help'        => __( 'help', 'pods' ),
1443
					'type'        => 'text',
1444
					'default'     => '',
1445
					// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1446
					'object_type' => array( 'post_type' ),
1447
				),
1448
				'label_filter_items_list'          => array(
1449
					'label'       => __( 'Filter <span class="pods-slugged" data-sluggable="label">Items</span> lists', 'pods' ),
1450
					'help'        => __( 'help', 'pods' ),
1451
					'type'        => 'text',
1452
					'default'     => '',
1453
					'object_type' => array( 'post_type' ),
1454
				),
1455
				'label_items_list_navigation'      => array(
1456
					'label'       => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list navigation', 'pods' ),
1457
					'help'        => __( 'help', 'pods' ),
1458
					'type'        => 'text',
1459
					'default'     => '',
1460
					'object_type' => array( 'post_type', 'taxonomy' ),
1461
				),
1462
				'label_items_list'                 => array(
1463
					'label'       => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list', 'pods' ),
1464
					'help'        => __( 'help', 'pods' ),
1465
					'type'        => 'text',
1466
					'default'     => '',
1467
					'object_type' => array( 'post_type', 'taxonomy' ),
1468
				),
1469
				'label_separate_items_with_commas' => array(
1470
					'label'       => __( 'Separate <span class="pods-slugged-lower" data-sluggable="label">items</span> with commas', 'pods' ),
1471
					'help'        => __( 'help', 'pods' ),
1472
					'type'        => 'text',
1473
					'default'     => '',
1474
					'object_type' => array( 'taxonomy' ),
1475
				),
1476
				'label_add_or_remove_items'        => array(
1477
					'label'       => __( 'Add or remove <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1478
					'help'        => __( 'help', 'pods' ),
1479
					'type'        => 'text',
1480
					'default'     => '',
1481
					'object_type' => array( 'taxonomy' ),
1482
				),
1483
				'label_choose_from_the_most_used'  => array(
1484
					'label'       => __( 'Choose from the most used <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1485
					'help'        => __( 'help', 'pods' ),
1486
					'type'        => 'text',
1487
					'default'     => '',
1488
					'object_type' => array( 'taxonomy' ),
1489
				),
1490
				'label_no_terms'                   => array(
1491
					'label'       => __( 'No <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1492
					'help'        => __( 'help', 'pods' ),
1493
					'type'        => 'text',
1494
					'default'     => '',
1495
					'object_type' => array( 'taxonomy' ),
1496
				),
1497
			);
1498
1499
			$options['labels'] = array();
1500
1501
			/**
1502
			 * Filter through all labels if they have an object_type set and match it against the current object type
1503
			 */
1504
			foreach ( $labels as $label => $labeldata ) {
1505
				if ( array_key_exists( 'object_type', $labeldata ) ) {
1506
					if ( in_array( pods_v( 'type', $pod ), $labeldata['object_type'], true ) ) {
1507
						// Do not add the object_type to the actual label data
1508
						unset( $labeldata['object_type'] );
1509
						$options['labels'][ $label ] = $labeldata;
1510
					}
1511
				} else {
1512
					$options['labels'][ $label ] = $labeldata;
1513
				}
1514
			}
1515
		} elseif ( 'settings' === pods_v( 'type', $pod ) ) {
1516
1517
			$options['labels'] = array(
1518
				'label'     => array(
1519
					'label'           => __( 'Page Title', 'pods' ),
1520
					'help'            => __( 'help', 'pods' ),
1521
					'type'            => 'text',
1522
					'default'         => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
1523
					'text_max_length' => 30,
1524
				),
1525
				'menu_name' => array(
1526
					'label'           => __( 'Menu Name', 'pods' ),
1527
					'help'            => __( 'help', 'pods' ),
1528
					'type'            => 'text',
1529
					'default'         => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
1530
					'text_max_length' => 30,
1531
				),
1532
			);
1533
		}//end if
1534
1535
		if ( 'post_type' === $pod['type'] ) {
1536
			$options['admin-ui'] = array(
1537
				'description'          => array(
1538
					'label'   => __( 'Post Type Description', 'pods' ),
1539
					'help'    => __( 'A short descriptive summary of what the post type is.', 'pods' ),
1540
					'type'    => 'text',
1541
					'default' => '',
1542
				),
1543
				'show_ui'              => array(
1544
					'label'             => __( 'Show Admin UI', 'pods' ),
1545
					'help'              => __( 'Whether to generate a default UI for managing this post type in the admin.', 'pods' ),
1546
					'type'              => 'boolean',
1547
					'default'           => pods_v( 'public', $pod, true ),
1548
					'boolean_yes_label' => '',
1549
				),
1550
				'show_in_menu'         => array(
1551
					'label'             => __( 'Show Admin Menu in Dashboard', 'pods' ),
1552
					'help'              => __( 'Whether to show the post type in the admin menu.', 'pods' ),
1553
					'type'              => 'boolean',
1554
					'default'           => pods_v( 'public', $pod, true ),
1555
					'dependency'        => true,
1556
					'boolean_yes_label' => '',
1557
				),
1558
				'menu_location_custom' => array(
1559
					'label'      => __( 'Parent Menu ID (optional)', 'pods' ),
1560
					'help'       => __( 'help', 'pods' ),
1561
					'type'       => 'text',
1562
					'depends-on' => array( 'show_in_menu' => true ),
1563
				),
1564
				'menu_name'            => array(
1565
					'label'      => __( 'Menu Name', 'pods' ),
1566
					'help'       => __( 'help', 'pods' ),
1567
					'type'       => 'text',
1568
					'default'    => '',
1569
					'depends-on' => array( 'show_in_menu' => true ),
1570
				),
1571
				'menu_position'        => array(
1572
					'label'              => __( 'Menu Position', 'pods' ),
1573
					'help'               => __( 'help', 'pods' ),
1574
					'type'               => 'number',
1575
					'number_decimals'    => 2,
1576
					'number_format'      => '9999.99',
1577
					'number_format_soft' => 1,
1578
					'default'            => 0,
1579
					'depends-on'         => array( 'show_in_menu' => true ),
1580
				),
1581
				'menu_icon'            => array(
1582
					'label'      => __( 'Menu Icon', 'pods' ),
1583
					'help'       => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="https://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank">site tag</a> type <a href="https://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' ),
1584
					'type'       => 'text',
1585
					'default'    => '',
1586
					'depends-on' => array( 'show_in_menu' => true ),
1587
				),
1588
				'show_in_nav_menus'    => array(
1589
					'label'             => __( 'Show in Navigation Menus', 'pods' ),
1590
					'help'              => __( 'help', 'pods' ),
1591
					'type'              => 'boolean',
1592
					'default'           => true,
1593
					'boolean_yes_label' => '',
1594
				),
1595
				'show_in_admin_bar'    => array(
1596
					'label'             => __( 'Show in Admin Bar "New" Menu', 'pods' ),
1597
					'help'              => __( 'help', 'pods' ),
1598
					'type'              => 'boolean',
1599
					'default'           => true,
1600
					'dependency'        => true,
1601
					'boolean_yes_label' => '',
1602
				),
1603
				'name_admin_bar'       => array(
1604
					'label'      => __( 'Admin bar name', 'pods' ),
1605
					'help'       => __( 'Defaults to singular name', 'pods' ),
1606
					'type'       => 'text',
1607
					'default'    => '',
1608
					'depends-on' => array( 'show_in_admin_bar' => true ),
1609
				),
1610
			);
1611
1612
			$options['advanced'] = array(
1613
				'public'                  => array(
1614
					'label'             => __( 'Public', 'pods' ),
1615
					'help'              => __( 'help', 'pods' ),
1616
					'type'              => 'boolean',
1617
					'default'           => true,
1618
					'boolean_yes_label' => '',
1619
				),
1620
				'publicly_queryable'      => array(
1621
					'label'             => __( 'Publicly Queryable', 'pods' ),
1622
					'help'              => __( 'help', 'pods' ),
1623
					'type'              => 'boolean',
1624
					'default'           => pods_v( 'public', $pod, true ),
1625
					'boolean_yes_label' => '',
1626
				),
1627
				'exclude_from_search'     => array(
1628
					'label'             => __( 'Exclude from Search', 'pods' ),
1629
					'help'              => __( 'help', 'pods' ),
1630
					'type'              => 'boolean',
1631
					'default'           => ! pods_v( 'public', $pod, true ),
1632
					'boolean_yes_label' => '',
1633
				),
1634
				'capability_type'         => array(
1635
					'label'      => __( 'User Capability', 'pods' ),
1636
					'help'       => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),
1637
					'type'       => 'pick',
1638
					'default'    => 'post',
1639
					'data'       => array(
1640
						'post'   => 'post',
1641
						'page'   => 'page',
1642
						'custom' => __( 'Custom Capability', 'pods' ),
1643
					),
1644
					'dependency' => true,
1645
				),
1646
				'capability_type_custom'  => array(
1647
					'label'      => __( 'Custom User Capability', 'pods' ),
1648
					'help'       => __( 'help', 'pods' ),
1649
					'type'       => 'text',
1650
					'default'    => pods_v( 'name', $pod ),
1651
					'depends-on' => array( 'capability_type' => 'custom' ),
1652
				),
1653
				'capability_type_extra'   => array(
1654
					'label'             => __( 'Additional User Capabilities', 'pods' ),
1655
					'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' ),
1656
					'type'              => 'boolean',
1657
					'default'           => true,
1658
					'boolean_yes_label' => '',
1659
				),
1660
				'has_archive'             => array(
1661
					'label'             => __( 'Enable Archive Page', 'pods' ),
1662
					'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' ),
1663
					'type'              => 'boolean',
1664
					'default'           => false,
1665
					'dependency'        => true,
1666
					'boolean_yes_label' => '',
1667
				),
1668
				'has_archive_slug'        => array(
1669
					'label'      => __( 'Archive Page Slug Override', 'pods' ),
1670
					'help'       => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),
1671
					'type'       => 'text',
1672
					'default'    => '',
1673
					'depends-on' => array( 'has_archive' => true ),
1674
				),
1675
				'hierarchical'            => array(
1676
					'label'             => __( 'Hierarchical', 'pods' ),
1677
					'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' ),
1678
					'type'              => 'boolean',
1679
					'default'           => false,
1680
					'dependency'        => true,
1681
					'boolean_yes_label' => '',
1682
				),
1683
				'label_parent_item_colon' => array(
1684
					'label'      => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1685
					'help'       => __( 'help', 'pods' ),
1686
					'type'       => 'text',
1687
					'default'    => '',
1688
					'depends-on' => array( 'hierarchical' => true ),
1689
				),
1690
				'label_parent'            => array(
1691
					'label'      => __( '<strong>Label: </strong> Parent', 'pods' ),
1692
					'help'       => __( 'help', 'pods' ),
1693
					'type'       => 'text',
1694
					'default'    => '',
1695
					'depends-on' => array( 'hierarchical' => true ),
1696
				),
1697
				'rewrite'                 => array(
1698
					'label'             => __( 'Rewrite', 'pods' ),
1699
					'help'              => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Permalinks. If not enabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ),
1700
					'type'              => 'boolean',
1701
					'default'           => true,
1702
					'dependency'        => true,
1703
					'boolean_yes_label' => '',
1704
				),
1705
				'rewrite_custom_slug'     => array(
1706
					'label'      => __( 'Custom Rewrite Slug', 'pods' ),
1707
					'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' ),
1708
					'type'       => 'text',
1709
					'default'    => '',
1710
					'depends-on' => array( 'rewrite' => true ),
1711
				),
1712
				'rewrite_with_front'      => array(
1713
					'label'             => __( 'Rewrite with Front', 'pods' ),
1714
					'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' ),
1715
					'type'              => 'boolean',
1716
					'default'           => true,
1717
					'depends-on'        => array( 'rewrite' => true ),
1718
					'boolean_yes_label' => '',
1719
				),
1720
				'rewrite_feeds'           => array(
1721
					'label'             => __( 'Rewrite Feeds', 'pods' ),
1722
					'help'              => __( 'help', 'pods' ),
1723
					'type'              => 'boolean',
1724
					'default'           => false,
1725
					'depends-on'        => array( 'rewrite' => true ),
1726
					'boolean_yes_label' => '',
1727
				),
1728
				'rewrite_pages'           => array(
1729
					'label'             => __( 'Rewrite Pages', 'pods' ),
1730
					'help'              => __( 'help', 'pods' ),
1731
					'type'              => 'boolean',
1732
					'default'           => true,
1733
					'depends-on'        => array( 'rewrite' => true ),
1734
					'boolean_yes_label' => '',
1735
				),
1736
				'query_var'               => array(
1737
					'label'             => __( 'Query Var', 'pods' ),
1738
					'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' ),
1739
					'type'              => 'boolean',
1740
					'default'           => true,
1741
					'boolean_yes_label' => '',
1742
				),
1743
				'can_export'              => array(
1744
					'label'             => __( 'Exportable', 'pods' ),
1745
					'help'              => __( 'help', 'pods' ),
1746
					'type'              => 'boolean',
1747
					'default'           => true,
1748
					'boolean_yes_label' => '',
1749
				),
1750
				'default_status'          => array(
1751
					'label'       => __( 'Default Status', 'pods' ),
1752
					'help'        => __( 'help', 'pods' ),
1753
					'type'        => 'pick',
1754
					'pick_object' => 'post-status',
1755
					'default'     => apply_filters( 'pods_api_default_status_' . pods_v( 'name', $pod, 'post_type', true ), 'draft', $pod ),
1756
				),
1757
			);
1758
		} elseif ( 'taxonomy' === $pod['type'] ) {
1759
			$options['admin-ui'] = array(
1760
				'show_ui'               => array(
1761
					'label'             => __( 'Show Admin UI', 'pods' ),
1762
					'help'              => __( 'Whether to generate a default UI for managing this taxonomy.', 'pods' ),
1763
					'type'              => 'boolean',
1764
					'default'           => pods_v( 'public', $pod, true ),
1765
					'dependency'        => true,
1766
					'boolean_yes_label' => '',
1767
				),
1768
				'show_in_menu'          => array(
1769
					'label'             => __( 'Show Admin Menu in Dashboard', 'pods' ),
1770
					'help'              => __( 'Whether to show the taxonomy in the admin menu.', 'pods' ),
1771
					'type'              => 'boolean',
1772
					'default'           => pods_v( 'public', $pod, true ),
1773
					'dependency'        => true,
1774
					'depends-on'        => array( 'show_ui' => true ),
1775
					'boolean_yes_label' => '',
1776
				),
1777
				'menu_name'             => array(
1778
					'label'      => __( 'Menu Name', 'pods' ),
1779
					'help'       => __( 'help', 'pods' ),
1780
					'type'       => 'text',
1781
					'default'    => '',
1782
					'depends-on' => array( 'show_ui' => true ),
1783
				),
1784
				'menu_location'         => array(
1785
					'label'      => __( 'Menu Location', 'pods' ),
1786
					'help'       => __( 'help', 'pods' ),
1787
					'type'       => 'pick',
1788
					'default'    => 'default',
1789
					'depends-on' => array( 'show_ui' => true ),
1790
					'data'       => array(
1791
						'default'     => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
1792
						'settings'    => __( 'Add a submenu item to Settings menu', 'pods' ),
1793
						'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
1794
						'submenu'     => __( 'Add a submenu item to another menu', 'pods' ),
1795
						'objects'     => __( 'Make a new menu item', 'pods' ),
1796
						'top'         => __( 'Make a new menu item below Settings', 'pods' ),
1797
					),
1798
					'dependency' => true,
1799
				),
1800
				'menu_location_custom'  => array(
1801
					'label'      => __( 'Custom Menu Location', 'pods' ),
1802
					'help'       => __( 'help', 'pods' ),
1803
					'type'       => 'text',
1804
					'depends-on' => array( 'menu_location' => 'submenu' ),
1805
				),
1806
				'menu_position'         => array(
1807
					'label'              => __( 'Menu Position', 'pods' ),
1808
					'help'               => __( 'help', 'pods' ),
1809
					'type'               => 'number',
1810
					'number_decimals'    => 2,
1811
					'number_format'      => '9999.99',
1812
					'number_format_soft' => 1,
1813
					'default'            => 0,
1814
					'depends-on'         => array( 'menu_location' => array( 'objects', 'top' ) ),
1815
				),
1816
				'menu_icon'             => array(
1817
					'label'      => __( 'Menu Icon URL', 'pods' ),
1818
					'help'       => __( 'help', 'pods' ),
1819
					'type'       => 'text',
1820
					'default'    => '',
1821
					'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ),
1822
				),
1823
				'show_in_nav_menus'     => array(
1824
					'label'             => __( 'Show in Navigation Menus', 'pods' ),
1825
					'help'              => __( 'help', 'pods' ),
1826
					'type'              => 'boolean',
1827
					'default'           => pods_v( 'public', $pod, true ),
1828
					'boolean_yes_label' => '',
1829
				),
1830
				'show_tagcloud'         => array(
1831
					'label'             => __( 'Allow in Tagcloud Widget', 'pods' ),
1832
					'help'              => __( 'help', 'pods' ),
1833
					'type'              => 'boolean',
1834
					'default'           => pods_v( 'show_ui', $pod, pods_v( 'public', $pod, true ) ),
1835
					'boolean_yes_label' => '',
1836
				),
1837
				// @todo check https://core.trac.wordpress.org/ticket/36964
1838
				'show_tagcloud_in_edit' => array(
1839
					'label'             => __( 'Allow Tagcloud on term edit pages', 'pods' ),
1840
					'help'              => __( 'help', 'pods' ),
1841
					'type'              => 'boolean',
1842
					'default'           => pods_v( 'show_ui', $pod, pods_v( 'show_tagcloud', $pod, true ) ),
1843
					'boolean_yes_label' => '',
1844
				),
1845
				'show_in_quick_edit'    => array(
1846
					'label'             => __( 'Allow in quick/bulk edit panel', 'pods' ),
1847
					'help'              => __( 'help', 'pods' ),
1848
					'type'              => 'boolean',
1849
					'default'           => pods_v( 'show_ui', $pod, pods_v( 'public', $pod, true ) ),
1850
					'boolean_yes_label' => '',
1851
				),
1852
			);
1853
1854
			$options['admin-ui']['show_admin_column'] = array(
1855
				'label'             => __( 'Show Taxonomy column on Post Types', 'pods' ),
1856
				'help'              => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
1857
				'type'              => 'boolean',
1858
				'default'           => false,
1859
				'boolean_yes_label' => '',
1860
			);
1861
1862
			// Integration for Single Value Taxonomy UI
1863
			if ( function_exists( 'tax_single_value_meta_box' ) ) {
1864
				$options['admin-ui']['single_value'] = array(
1865
					'label'             => __( 'Single Value Taxonomy', 'pods' ),
1866
					'help'              => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),
1867
					'type'              => 'boolean',
1868
					'default'           => false,
1869
					'boolean_yes_label' => '',
1870
				);
1871
1872
				$options['admin-ui']['single_value_required'] = array(
1873
					'label'             => __( 'Single Value Taxonomy - Required', 'pods' ),
1874
					'help'              => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),
1875
					'type'              => 'boolean',
1876
					'default'           => false,
1877
					'boolean_yes_label' => '',
1878
				);
1879
			}
1880
1881
			$options['advanced'] = array(
1882
				'public'                  => array(
1883
					'label'             => __( 'Public', 'pods' ),
1884
					'help'              => __( 'help', 'pods' ),
1885
					'type'              => 'boolean',
1886
					'default'           => true,
1887
					'boolean_yes_label' => '',
1888
				),
1889
				'hierarchical'            => array(
1890
					'label'             => __( 'Hierarchical', 'pods' ),
1891
					'help'              => __( 'help', 'pods' ),
1892
					'type'              => 'boolean',
1893
					'default'           => true,
1894
					'dependency'        => true,
1895
					'boolean_yes_label' => '',
1896
				),
1897
				'label_parent_item_colon' => array(
1898
					'label'      => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1899
					'help'       => __( 'help', 'pods' ),
1900
					'type'       => 'text',
1901
					'default'    => '',
1902
					'depends-on' => array( 'hierarchical' => true ),
1903
				),
1904
				'label_parent'            => array(
1905
					'label'      => __( '<strong>Label: </strong> Parent', 'pods' ),
1906
					'help'       => __( 'help', 'pods' ),
1907
					'type'       => 'text',
1908
					'default'    => '',
1909
					'depends-on' => array( 'hierarchical' => true ),
1910
				),
1911
				'label_no_terms'          => array(
1912
					'label'      => __( '<strong>Label: </strong> No <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1913
					'help'       => __( 'help', 'pods' ),
1914
					'type'       => 'text',
1915
					'default'    => '',
1916
					'depends-on' => array( 'hierarchical' => true ),
1917
				),
1918
				'rewrite'                 => array(
1919
					'label'             => __( 'Rewrite', 'pods' ),
1920
					'help'              => __( 'help', 'pods' ),
1921
					'type'              => 'boolean',
1922
					'default'           => true,
1923
					'dependency'        => true,
1924
					'boolean_yes_label' => '',
1925
				),
1926
				'rewrite_custom_slug'     => array(
1927
					'label'      => __( 'Custom Rewrite Slug', 'pods' ),
1928
					'help'       => __( 'help', 'pods' ),
1929
					'type'       => 'text',
1930
					'default'    => '',
1931
					'depends-on' => array( 'rewrite' => true ),
1932
				),
1933
				'rewrite_with_front'      => array(
1934
					'label'             => __( 'Allow Front Prepend', 'pods' ),
1935
					'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' ),
1936
					'type'              => 'boolean',
1937
					'default'           => true,
1938
					'boolean_yes_label' => '',
1939
					'depends-on'        => array( 'rewrite' => true ),
1940
				),
1941
				'rewrite_hierarchical'    => array(
1942
					'label'             => __( 'Hierarchical Permalinks', 'pods' ),
1943
					'help'              => __( 'help', 'pods' ),
1944
					'type'              => 'boolean',
1945
					'default'           => true,
1946
					'boolean_yes_label' => '',
1947
					'depends-on'        => array( 'rewrite' => true ),
1948
				),
1949
				'capability_type'         => array(
1950
					'label'      => __( 'User Capability', 'pods' ),
1951
					'help'       => __( 'Uses WordPress term capabilities by default', 'pods' ),
1952
					'type'       => 'pick',
1953
					'default'    => 'default',
1954
					'data'       => array(
1955
						'default' => 'Default',
1956
						'custom'  => __( 'Custom Capability', 'pods' ),
1957
					),
1958
					'dependency' => true,
1959
				),
1960
				'capability_type_custom'  => array(
1961
					'label'      => __( 'Custom User Capability', 'pods' ),
1962
					'help'       => __( 'Enables additional capabilities for this Taxonomy including: manage_{capability}_terms, edit_{capability}_terms, assign_{capability}_terms, and delete_{capability}_terms', 'pods' ),
1963
					'type'       => 'text',
1964
					'default'    => pods_v( 'name', $pod ),
1965
					'depends-on' => array( 'capability_type' => 'custom' ),
1966
				),
1967
				'query_var'               => array(
1968
					'label'             => __( 'Query Var', 'pods' ),
1969
					'help'              => __( 'help', 'pods' ),
1970
					'type'              => 'boolean',
1971
					'default'           => false,
1972
					'boolean_yes_label' => '',
1973
				),
1974
				'query_var'               => array(
1975
					'label'             => __( 'Query Var', 'pods' ),
1976
					'help'              => __( 'help', 'pods' ),
1977
					'type'              => 'boolean',
1978
					'default'           => false,
1979
					'dependency'        => true,
1980
					'boolean_yes_label' => '',
1981
				),
1982
				'query_var_string'        => array(
1983
					'label'      => __( 'Custom Query Var Name', 'pods' ),
1984
					'help'       => __( 'help', 'pods' ),
1985
					'type'       => 'text',
1986
					'default'    => '',
1987
					'depends-on' => array( 'query_var' => true ),
1988
				),
1989
				'sort'                    => array(
1990
					'label'             => __( 'Remember order saved on Post Types', 'pods' ),
1991
					'help'              => __( 'help', 'pods' ),
1992
					'type'              => 'boolean',
1993
					'default'           => false,
1994
					'boolean_yes_label' => '',
1995
				),
1996
				'update_count_callback'   => array(
1997
					'label'   => __( 'Function to call when updating counts', 'pods' ),
1998
					'help'    => __( 'help', 'pods' ),
1999
					'type'    => 'text',
2000
					'default' => '',
2001
				),
2002
			);
2003
		} elseif ( 'settings' === $pod['type'] ) {
2004
			$options['admin-ui'] = array(
2005
				'ui_style'             => array(
2006
					'label'      => __( 'Admin UI Style', 'pods' ),
2007
					'help'       => __( 'help', 'pods' ),
2008
					'type'       => 'pick',
2009
					'default'    => 'settings',
2010
					'data'       => array(
2011
						'settings'  => __( 'Normal Settings Form', 'pods' ),
2012
						'post_type' => __( 'Post Type UI', 'pods' ),
2013
						'custom'    => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ),
2014
					),
2015
					'dependency' => true,
2016
				),
2017
				'menu_location'        => array(
2018
					'label'      => __( 'Menu Location', 'pods' ),
2019
					'help'       => __( 'help', 'pods' ),
2020
					'type'       => 'pick',
2021
					'default'    => 'settings',
2022
					'data'       => array(
2023
						'settings'    => __( 'Add a submenu item to Settings menu', 'pods' ),
2024
						'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
2025
						'submenu'     => __( 'Add a submenu item to another menu', 'pods' ),
2026
						'top'         => __( 'Make a new menu item below Settings', 'pods' ),
2027
					),
2028
					'dependency' => true,
2029
				),
2030
				'menu_location_custom' => array(
2031
					'label'      => __( 'Custom Menu Location', 'pods' ),
2032
					'help'       => __( 'help', 'pods' ),
2033
					'type'       => 'text',
2034
					'depends-on' => array( 'menu_location' => 'submenu' ),
2035
				),
2036
				'menu_position'        => array(
2037
					'label'              => __( 'Menu Position', 'pods' ),
2038
					'help'               => __( 'help', 'pods' ),
2039
					'type'               => 'number',
2040
					'number_decimals'    => 2,
2041
					'number_format'      => '9999.99',
2042
					'number_format_soft' => 1,
2043
					'default'            => 0,
2044
					'depends-on'         => array( 'menu_location' => 'top' ),
2045
				),
2046
				'menu_icon'            => array(
2047
					'label'      => __( 'Menu Icon URL', 'pods' ),
2048
					'help'       => __( 'help', 'pods' ),
2049
					'type'       => 'text',
2050
					'default'    => '',
2051
					'depends-on' => array( 'menu_location' => 'top' ),
2052
				),
2053
			);
2054
2055
			// @todo fill this in
2056
			$options['advanced'] = array(
2057
				'temporary' => 'This type has the fields hardcoded',
2058
			// :(
2059
			);
2060
		} elseif ( 'pod' === $pod['type'] ) {
2061
			$actions_enabled = array(
2062
				'add',
2063
				'edit',
2064
				'duplicate',
2065
				'delete',
2066
			);
2067
2068
			if ( 1 === (int) pods_v( 'ui_export', $pod ) ) {
2069
				$actions_enabled = array(
2070
					'add',
2071
					'edit',
2072
					'duplicate',
2073
					'delete',
2074
					'export',
2075
				);
2076
			}
2077
2078
			$options['admin-ui'] = array(
2079
				'ui_style'             => array(
2080
					'label'      => __( 'Admin UI Style', 'pods' ),
2081
					'help'       => __( 'help', 'pods' ),
2082
					'type'       => 'pick',
2083
					'default'    => 'settings',
2084
					'data'       => array(
2085
						'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),
2086
						'custom'    => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ),
2087
					),
2088
					'dependency' => true,
2089
				),
2090
				'show_in_menu'         => array(
2091
					'label'             => __( 'Show Admin Menu in Dashboard', 'pods' ),
2092
					'help'              => __( 'help', 'pods' ),
2093
					'type'              => 'boolean',
2094
					'default'           => false,
2095
					'boolean_yes_label' => '',
2096
					'dependency'        => true,
2097
				),
2098
				'menu_location_custom' => array(
2099
					'label'      => __( 'Parent Menu ID (optional)', 'pods' ),
2100
					'help'       => __( 'help', 'pods' ),
2101
					'type'       => 'text',
2102
					'depends-on' => array( 'show_in_menu' => true ),
2103
				),
2104
				'menu_position'        => array(
2105
					'label'              => __( 'Menu Position', 'pods' ),
2106
					'help'               => __( 'help', 'pods' ),
2107
					'type'               => 'number',
2108
					'number_decimals'    => 2,
2109
					'number_format'      => '9999.99',
2110
					'number_format_soft' => 1,
2111
					'default'            => 0,
2112
					'depends-on'         => array( 'show_in_menu' => true ),
2113
				),
2114
				'menu_icon'            => array(
2115
					'label'      => __( 'Menu Icon URL', 'pods' ),
2116
					'help'       => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),
2117
					'type'       => 'text',
2118
					'default'    => '',
2119
					'depends-on' => array( 'show_in_menu' => true ),
2120
				),
2121
				'ui_icon'              => array(
2122
					'label'           => __( 'Header Icon', 'pods' ),
2123
					'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' ),
2124
					'type'            => 'file',
2125
					'default'         => '',
2126
					'file_edit_title' => 0,
2127
					'depends-on'      => array( 'show_in_menu' => true ),
2128
				),
2129
				'ui_actions_enabled'   => array(
2130
					'label'            => __( 'Actions Available', 'pods' ),
2131
					'help'             => __( 'help', 'pods' ),
2132
					'type'             => 'pick',
2133
					'default'          => $actions_enabled,
2134
					'data'             => array(
2135
						'add'       => __( 'Add New', 'pods' ),
2136
						'edit'      => __( 'Edit', 'pods' ),
2137
						'duplicate' => __( 'Duplicate', 'pods' ),
2138
						'delete'    => __( 'Delete', 'pods' ),
2139
						'reorder'   => __( 'Reorder', 'pods' ),
2140
						'export'    => __( 'Export', 'pods' ),
2141
					),
2142
					'pick_format_type' => 'multi',
2143
					'dependency'       => true,
2144
				),
2145
				'ui_reorder_field'     => array(
2146
					'label'      => __( 'Reorder Field', 'pods' ),
2147
					'help'       => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),
2148
					'type'       => 'text',
2149
					'default'    => 'menu_order',
2150
					'depends-on' => array( 'ui_actions_enabled' => 'reorder' ),
2151
				),
2152
				'ui_fields_manage'     => array(
2153
					'label'            => __( 'Admin Table Columns', 'pods' ),
2154
					'help'             => __( 'help', 'pods' ),
2155
					'type'             => 'pick',
2156
					'default'          => array(),
2157
					'data'             => array(),
2158
					'pick_format_type' => 'multi',
2159
				),
2160
				'ui_filters'           => array(
2161
					'label'            => __( 'Search Filters', 'pods' ),
2162
					'help'             => __( 'help', 'pods' ),
2163
					'type'             => 'pick',
2164
					'default'          => array(),
2165
					'data'             => array(),
2166
					'pick_format_type' => 'multi',
2167
				),
2168
			);
2169
2170
			if ( ! empty( $pod['fields'] ) ) {
2171
				if ( isset( $pod['fields'][ pods_v( 'pod_index', $pod, 'name' ) ] ) ) {
2172
					$options['admin-ui']['ui_fields_manage']['default'][] = pods_v( 'pod_index', $pod, 'name' );
2173
				}
2174
2175
				if ( isset( $pod['fields']['modified'] ) ) {
2176
					$options['admin-ui']['ui_fields_manage']['default'][] = 'modified';
2177
				}
2178
2179
				foreach ( $pod['fields'] as $field ) {
2180
					$type = '';
2181
2182
					if ( isset( $field_types[ $field['type'] ] ) ) {
2183
						$type = ' <small>(' . $field_types[ $field['type'] ]['label'] . ')</small>';
2184
					}
2185
2186
					$options['admin-ui']['ui_fields_manage']['data'][ $field['name'] ] = $field['label'] . $type;
2187
					$options['admin-ui']['ui_filters']['data'][ $field['name'] ]       = $field['label'] . $type;
2188
				}
2189
2190
				$options['admin-ui']['ui_fields_manage']['data']['id'] = 'ID';
2191
			} else {
2192
				unset( $options['admin-ui']['ui_fields_manage'] );
2193
				unset( $options['admin-ui']['ui_filters'] );
2194
			}//end if
2195
2196
			// @todo fill this in
2197
			$options['advanced'] = array(
2198
				'temporary' => 'This type has the fields hardcoded',
2199
			// :(
2200
			);
2201
		}//end if
2202
2203
		/**
2204
		 * Add admin fields to the Pods editor for a specific Pod
2205
		 *
2206
		 * @param array  $options The Options fields.
2207
		 * @param object $pod     Current Pods object.
2208
		 *
2209
		 * @since  unkown
2210
		 */
2211
		$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod['type'] . '_' . $pod['name'], $options, $pod );
2212
2213
		/**
2214
		 * Add admin fields to the Pods editor for any Pod of a specific content type.
2215
		 *
2216
		 * @param array  $options The Options fields.
2217
		 * @param object $pod     Current Pods object.
2218
		 */
2219
		$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod['type'], $options, $pod );
2220
2221
		/**
2222
		 * Add admin fields to the Pods editor for all Pods
2223
		 *
2224
		 * @param array  $options The Options fields.
2225
		 * @param object $pod     Current Pods object.
2226
		 */
2227
		$options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod );
2228
2229
		return $options;
2230
	}
2231
2232
	/**
2233
	 * Get list of Pod field option tabs
2234
	 *
2235
	 * @param array $pod Pod options.
2236
	 *
2237
	 * @return array
2238
	 */
2239
	public function admin_setup_edit_field_tabs( $pod ) {
2240
2241
		$core_tabs = array(
2242
			'basic'            => __( 'Basic', 'pods' ),
2243
			'additional-field' => __( 'Additional Field Options', 'pods' ),
2244
			'advanced'         => __( 'Advanced', 'pods' ),
2245
		);
2246
2247
		/**
2248
		 * Field option tabs
2249
		 *
2250
		 * Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye).
2251
		 *
2252
		 * @since unknown
2253
		 *
2254
		 * @param array      $tabs Tabs to add, starts empty.
2255
		 * @param object|Pod $pod  Current Pods object.
2256
		 */
2257
		$tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod );
2258
2259
		$tabs = array_merge( $core_tabs, $tabs );
2260
2261
		return $tabs;
2262
	}
2263
2264
	/**
2265
	 * Get list of Pod field options
2266
	 *
2267
	 * @param array $pod Pod options.
2268
	 *
2269
	 * @return array
2270
	 */
2271
	public function admin_setup_edit_field_options( $pod ) {
2272
2273
		$options = array();
2274
2275
		$options['additional-field'] = array();
2276
2277
		$field_types = PodsForm::field_types();
2278
2279
		foreach ( $field_types as $type => $field_type_data ) {
2280
			/**
2281
			 * @var $field_type PodsField
2282
			 */
2283
			$field_type = PodsForm::field_loader( $type, $field_type_data['file'] );
2284
2285
			$field_type_vars = get_class_vars( get_class( $field_type ) );
2286
2287
			if ( ! isset( $field_type_vars['pod_types'] ) ) {
2288
				$field_type_vars['pod_types'] = true;
2289
			}
2290
2291
			$options['additional-field'][ $type ] = array();
2292
2293
			// Only show supported field types
2294
			if ( true !== $field_type_vars['pod_types'] ) {
2295
				if ( empty( $field_type_vars['pod_types'] ) ) {
2296
					continue;
2297
				} elseif ( is_array( $field_type_vars['pod_types'] ) && ! in_array( pods_v( 'type', $pod ), $field_type_vars['pod_types'], true ) ) {
2298
					continue;
2299
				} elseif ( ! is_array( $field_type_vars['pod_types'] ) && pods_v( 'type', $pod ) !== $field_type_vars['pod_types'] ) {
2300
					continue;
2301
				}
2302
			}
2303
2304
			$options['additional-field'][ $type ] = PodsForm::ui_options( $type );
2305
2306
			/**
2307
			 * Modify Additional Field Options tab
2308
			 *
2309
			 * @since 2.7
2310
			 *
2311
			 * @param array       $options Additional field type options,
2312
			 * @param string      $type    Field type,
2313
			 * @param array       $options Tabs, indexed by label,
2314
			 * @param object|Pods $pod     Pods object for the Pod this UI is for.
2315
			 */
2316
			$options['additional-field'][ $type ] = apply_filters( 'pods_admin_setup_edit_' . $type . '_additional_field_options', $options['additional-field'][ $type ], $type, $options, $pod );
2317
			$options['additional-field'][ $type ] = apply_filters( 'pods_admin_setup_edit_additional_field_options', $options['additional-field'][ $type ], $type, $options, $pod );
2318
		}//end foreach
2319
2320
		$input_helpers = array(
2321
			'' => '-- Select --',
2322
		);
2323
2324
		if ( class_exists( 'Pods_Helpers' ) ) {
2325
			$helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) );
2326
2327
			foreach ( $helpers as $helper ) {
2328
				$input_helpers[ $helper['name'] ] = $helper['name'];
2329
			}
2330
		}
2331
2332
		$options['advanced'] = array(
2333
			__( 'Visual', 'pods' )     => array(
2334
				'class'        => array(
2335
					'name'    => 'class',
2336
					'label'   => __( 'Additional CSS Classes', 'pods' ),
2337
					'help'    => __( 'help', 'pods' ),
2338
					'type'    => 'text',
2339
					'default' => '',
2340
				),
2341
				'input_helper' => array(
2342
					'name'    => 'input_helper',
2343
					'label'   => __( 'Input Helper', 'pods' ),
2344
					'help'    => __( 'help', 'pods' ),
2345
					'type'    => 'pick',
2346
					'default' => '',
2347
					'data'    => $input_helpers,
2348
				),
2349
			),
2350
			__( 'Values', 'pods' )     => array(
2351
				'default_value'           => array(
2352
					'name'    => 'default_value',
2353
					'label'   => __( 'Default Value', 'pods' ),
2354
					'help'    => __( 'help', 'pods' ),
2355
					'type'    => 'text',
2356
					'default' => '',
2357
					'options' => array(
2358
						'text_max_length' => - 1,
2359
					),
2360
				),
2361
				'default_value_parameter' => array(
2362
					'name'    => 'default_value_parameter',
2363
					'label'   => __( 'Set Default Value via Parameter', 'pods' ),
2364
					'help'    => __( 'help', 'pods' ),
2365
					'type'    => 'text',
2366
					'default' => '',
2367
				),
2368
			),
2369
			__( 'Visibility', 'pods' ) => array(
2370
				'restrict_access'    => array(
2371
					'name'  => 'restrict_access',
2372
					'label' => __( 'Restrict Access', 'pods' ),
2373
					'group' => array(
2374
						'admin_only'          => array(
2375
							'name'       => 'admin_only',
2376
							'label'      => __( 'Restrict access to Admins?', 'pods' ),
2377
							'default'    => 0,
2378
							'type'       => 'boolean',
2379
							'dependency' => true,
2380
							'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' ),
2381
						),
2382
						'restrict_role'       => array(
2383
							'name'       => 'restrict_role',
2384
							'label'      => __( 'Restrict access by Role?', 'pods' ),
2385
							'default'    => 0,
2386
							'type'       => 'boolean',
2387
							'dependency' => true,
2388
						),
2389
						'restrict_capability' => array(
2390
							'name'       => 'restrict_capability',
2391
							'label'      => __( 'Restrict access by Capability?', 'pods' ),
2392
							'default'    => 0,
2393
							'type'       => 'boolean',
2394
							'dependency' => true,
2395
						),
2396
						'hidden'              => array(
2397
							'name'    => 'hidden',
2398
							'label'   => __( 'Hide field from UI', 'pods' ),
2399
							'default' => 0,
2400
							'type'    => 'boolean',
2401
							'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' ),
2402
						),
2403
						'read_only'           => array(
2404
							'name'       => 'read_only',
2405
							'label'      => __( 'Make field "Read Only" in UI', 'pods' ),
2406
							'default'    => 0,
2407
							'type'       => 'boolean',
2408
							'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' ),
2409
							'depends-on' => array(
2410
								'type' => array(
2411
									'boolean',
2412
									'color',
2413
									'currency',
2414
									'date',
2415
									'datetime',
2416
									'email',
2417
									'number',
2418
									'paragraph',
2419
									'password',
2420
									'phone',
2421
									'slug',
2422
									'text',
2423
									'time',
2424
									'website',
2425
								),
2426
							),
2427
						),
2428
					),
2429
				),
2430
				'roles_allowed'      => array(
2431
					'name'             => 'roles_allowed',
2432
					'label'            => __( 'Role(s) Allowed', 'pods' ),
2433
					'help'             => __( 'help', 'pods' ),
2434
					'type'             => 'pick',
2435
					'pick_object'      => 'role',
2436
					'pick_format_type' => 'multi',
2437
					'default'          => 'administrator',
2438
					'depends-on'       => array(
2439
						'restrict_role' => true,
2440
					),
2441
				),
2442
				'capability_allowed' => array(
2443
					'name'       => 'capability_allowed',
2444
					'label'      => __( 'Capability Allowed', 'pods' ),
2445
					'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' ),
2446
					'type'       => 'text',
2447
					'default'    => '',
2448
					'depends-on' => array(
2449
						'restrict_capability' => true,
2450
					),
2451
				),
2452
				/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2453
				,
2454
                        'search' => array(
2455
                            'label' => __( 'Include in searches', 'pods' ),
2456
                            'help' => __( 'help', 'pods' ),
2457
                            'default' => 1,
2458
                            'type' => 'boolean',
2459
                        )*/
2460
			),
2461
			/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2462
			,
2463
                __( 'Validation', 'pods' ) => array(
2464
                    'regex_validation' => array(
2465
                        'label' => __( 'RegEx Validation', 'pods' ),
2466
                        'help' => __( 'help', 'pods' ),
2467
                        'type' => 'text',
2468
                        'default' => ''
2469
                    ),
2470
                    'message_regex' => array(
2471
                        'label' => __( 'Message if field does not pass RegEx', 'pods' ),
2472
                        'help' => __( 'help', 'pods' ),
2473
                        'type' => 'text',
2474
                        'default' => ''
2475
                    ),
2476
                    'message_required' => array(
2477
                        'label' => __( 'Message if field is blank', 'pods' ),
2478
                        'help' => __( 'help', 'pods' ),
2479
                        'type' => 'text',
2480
                        'default' => '',
2481
                        'depends-on' => array( 'required' => true )
2482
                    ),
2483
                    'message_unique' => array(
2484
                        'label' => __( 'Message if field is not unique', 'pods' ),
2485
                        'help' => __( 'help', 'pods' ),
2486
                        'type' => 'text',
2487
                        'default' => '',
2488
                        'depends-on' => array( 'unique' => true )
2489
                    )
2490
                )*/
2491
		);
2492
2493
		if ( ! class_exists( 'Pods_Helpers' ) ) {
2494
			unset( $options['advanced']['input_helper'] );
2495
		}
2496
2497
		/**
2498
		 * Modify tabs and their contents for field options
2499
		 *
2500
		 * @since unknown
2501
		 *
2502
		 * @param array       $options Tabs, indexed by label.
2503
		 * @param object|Pods $pod     Pods object for the Pod this UI is for.
2504
		 */
2505
		$options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod );
2506
2507
		return $options;
2508
	}
2509
2510
	/**
2511
	 * Duplicate a pod
2512
	 *
2513
	 * @param PodsUI $obj PodsUI object.
2514
	 */
2515
	public function admin_setup_duplicate( $obj ) {
2516
2517
		$new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) );
2518
2519
		if ( 0 < $new_id ) {
2520
			pods_redirect(
2521
				pods_query_arg(
2522
					array(
2523
						'action' => 'edit',
2524
						'id'     => $new_id,
2525
						'do'     => 'duplicate',
2526
					)
2527
				)
2528
			);
2529
		}
2530
	}
2531
2532
	/**
2533
	 * Restrict Duplicate action to custom types, not extended
2534
	 *
2535
	 * @param bool   $restricted Whether action is restricted.
2536
	 * @param array  $restrict   Restriction array.
2537
	 * @param string $action     Current action.
2538
	 * @param array  $row        Item data row.
2539
	 * @param PodsUI $obj        PodsUI object.
2540
	 *
2541
	 * @since 2.3.10
2542
	 *
2543
	 * @return bool
2544
	 */
2545 View Code Duplication
	public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2546
2547
		if ( in_array(
2548
			$row['real_type'], array(
2549
				'user',
2550
				'media',
2551
				'comment',
2552
			), true
2553
		) ) {
2554
			$restricted = true;
2555
		}
2556
2557
		return $restricted;
2558
2559
	}
2560
2561
	/**
2562
	 * Reset a pod
2563
	 *
2564
	 * @param PodsUI     $obj PodsUI object.
2565
	 * @param int|string $id  Item ID.
2566
	 *
2567
	 * @return mixed
2568
	 */
2569
	public function admin_setup_reset( $obj, $id ) {
2570
2571
		$pod = pods_api()->load_pod( array( 'id' => $id ), false );
2572
2573
		if ( empty( $pod ) ) {
2574
			return $obj->error( __( 'Pod not found.', 'pods' ) );
2575
		}
2576
2577
		pods_api()->reset_pod( array( 'id' => $id ) );
2578
2579
		$obj->message( __( 'Pod reset successfully.', 'pods' ) );
2580
2581
		$obj->manage();
2582
	}
2583
2584
	/**
2585
	 * Restrict Reset action from users and media
2586
	 *
2587
	 * @param bool   $restricted Whether action is restricted.
2588
	 * @param array  $restrict   Restriction array.
2589
	 * @param string $action     Current action.
2590
	 * @param array  $row        Item data row.
2591
	 * @param PodsUI $obj        PodsUI object.
2592
	 *
2593
	 * @since 2.3.10
2594
	 */
2595 View Code Duplication
	public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2596
2597
		if ( in_array(
2598
			$row['real_type'], array(
2599
				'user',
2600
				'media',
2601
			), true
2602
		) ) {
2603
			$restricted = true;
2604
		}
2605
2606
		return $restricted;
2607
2608
	}
2609
2610
	/**
2611
	 * Delete a pod
2612
	 *
2613
	 * @param int|string $id  Item ID.
2614
	 * @param PodsUI     $obj PodsUI object.
2615
	 *
2616
	 * @return mixed
2617
	 */
2618
	public function admin_setup_delete( $id, $obj ) {
2619
2620
		$pod = pods_api()->load_pod( array( 'id' => $id ), false );
2621
2622
		if ( empty( $pod ) ) {
2623
			return $obj->error( __( 'Pod not found.', 'pods' ) );
2624
		}
2625
2626
		pods_api()->delete_pod( array( 'id' => $id ) );
2627
2628
		unset( $obj->data[ $pod['id'] ] );
2629
2630
		$obj->total       = count( $obj->data );
2631
		$obj->total_found = count( $obj->data );
2632
2633
		$obj->message( __( 'Pod deleted successfully.', 'pods' ) );
2634
	}
2635
2636
	/**
2637
	 * Get advanced administration view.
2638
	 */
2639
	public function admin_advanced() {
2640
2641
		pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) );
2642
	}
2643
2644
	/**
2645
	 * Get settings administration view
2646
	 */
2647
	public function admin_settings() {
2648
2649
		pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) );
2650
	}
2651
2652
	/**
2653
	 * Get components administration UI
2654
	 */
2655
	public function admin_components() {
2656
2657
		if ( ! is_object( PodsInit::$components ) ) {
2658
			return;
2659
		}
2660
2661
		$components = PodsInit::$components->components;
2662
2663
		$view = pods_v( 'view', 'get', 'all', true );
2664
2665
		$recommended = array(
2666
			'advanced-relationships',
2667
			'advanced-content-types',
2668
			'migrate-packages',
2669
			'roles-and-capabilities',
2670
			'pages',
2671
			'table-storage',
2672
			'templates',
2673
		);
2674
2675
		foreach ( $components as $component => &$component_data ) {
2676
			if ( ! in_array(
2677
				$view, array(
2678
					'all',
2679
					'recommended',
2680
					'dev',
2681
				), true
2682
			) && ( ! isset( $component_data['Category'] ) || sanitize_title( $component_data['Category'] ) !== $view ) ) {
2683
				unset( $components[ $component ] );
2684
2685
				continue;
2686
			} elseif ( 'recommended' === $view && ! in_array( $component_data['ID'], $recommended, true ) ) {
2687
				unset( $components[ $component ] );
2688
2689
				continue;
2690
			} elseif ( 'dev' === $view && pods_developer() && ! pods_v( 'DeveloperMode', $component_data, false ) ) {
2691
				unset( $components[ $component ] );
2692
2693
				continue;
2694
			} elseif ( pods_v( 'DeveloperMode', $component_data, false ) && ! pods_developer() ) {
2695
				unset( $components[ $component ] );
2696
2697
				continue;
2698
			} elseif ( ! pods_v( 'TablelessMode', $component_data, false ) && pods_tableless() ) {
2699
				unset( $components[ $component ] );
2700
2701
				continue;
2702
			}//end if
2703
2704
			$component_data['Name'] = strip_tags( $component_data['Name'] );
2705
2706
			if ( pods_v( 'DeveloperMode', $component_data, false ) ) {
2707
				$component_data['Name'] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>';
2708
			}
2709
2710
			$meta = array();
2711
2712
			if ( ! empty( $component_data['Version'] ) ) {
2713
				$meta[] = sprintf( __( 'Version %s', 'pods' ), $component_data['Version'] );
2714
			}
2715
2716
			if ( empty( $component_data['Author'] ) ) {
2717
				$component_data['Author']    = 'Pods Framework Team';
2718
				$component_data['AuthorURI'] = 'https://pods.io/';
2719
			}
2720
2721
			if ( ! empty( $component_data['AuthorURI'] ) ) {
2722
				$component_data['Author'] = '<a href="' . $component_data['AuthorURI'] . '">' . $component_data['Author'] . '</a>';
2723
			}
2724
2725
			$meta[] = sprintf( __( 'by %s', 'pods' ), $component_data['Author'] );
2726
2727 View Code Duplication
			if ( ! empty( $component_data['URI'] ) ) {
2728
				$meta[] = '<a href="' . $component_data['URI'] . '">' . __( 'Visit component site', 'pods' ) . '</a>';
2729
			}
2730
2731
			$component_data['Description'] = wpautop( trim( make_clickable( strip_tags( $component_data['Description'], 'em,strong' ) ) ) );
2732
2733 View Code Duplication
			if ( ! empty( $meta ) ) {
2734
				$component_data['Description'] .= '<div class="pods-component-meta" ' . ( ! empty( $component_data['Description'] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( '&nbsp;&nbsp;|&nbsp;&nbsp;', $meta ) . '</div>';
2735
			}
2736
2737
			$component_data = array(
2738
				'id'          => $component_data['ID'],
2739
				'name'        => $component_data['Name'],
2740
				'category'    => $component_data['Category'],
2741
				'version'     => '',
2742
				'description' => $component_data['Description'],
2743
				'mustuse'     => pods_v( 'MustUse', $component_data, false ),
2744
				'toggle'      => 0,
2745
			);
2746
2747
			if ( ! empty( $component_data['category'] ) ) {
2748
				$category_url = pods_query_arg(
2749
					array(
2750
						'view' => sanitize_title( $component_data['category'] ),
2751
						'pg'   => '',
2752
						// @codingStandardsIgnoreLine
2753
						'page' => $_GET['page'],
2754
					)
2755
				);
2756
2757
				$component_data['category'] = '<a href="' . esc_url( $category_url ) . '">' . $component_data['category'] . '</a>';
2758
			}
2759
2760
			if ( isset( PodsInit::$components->settings['components'][ $component_data['id'] ] ) && 0 !== PodsInit::$components->settings['components'][ $component_data['id'] ] ) {
2761
				$component_data['toggle'] = 1;
2762
			} elseif ( $component_data['mustuse'] ) {
2763
				$component_data['toggle'] = 1;
2764
			}
2765
		}//end foreach
2766
2767
		$ui = array(
2768
			'data'             => $components,
2769
			'total'            => count( $components ),
2770
			'total_found'      => count( $components ),
2771
			'items'            => __( 'Components', 'pods' ),
2772
			'item'             => __( 'Component', 'pods' ),
2773
			'fields'           => array(
2774
				'manage' => array(
2775
					'name'        => array(
2776
						'label'   => __( 'Name', 'pods' ),
2777
						'width'   => '30%',
2778
						'type'    => 'text',
2779
						'options' => array(
2780
							'text_allow_html' => true,
2781
						),
2782
					),
2783
					'category'    => array(
2784
						'label'   => __( 'Category', 'pods' ),
2785
						'width'   => '10%',
2786
						'type'    => 'text',
2787
						'options' => array(
2788
							'text_allow_html' => true,
2789
						),
2790
					),
2791
					'description' => array(
2792
						'label'   => __( 'Description', 'pods' ),
2793
						'width'   => '60%',
2794
						'type'    => 'text',
2795
						'options' => array(
2796
							'text_allow_html'        => true,
2797
							'text_allowed_html_tags' => 'strong em a ul ol li b i br div',
2798
						),
2799
					),
2800
				),
2801
			),
2802
			'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),
2803
			'actions_custom'   => array(
2804
				'toggle' => array(
2805
					'callback' => array( $this, 'admin_components_toggle' ),
2806
					'nonce'    => true,
2807
				),
2808
			),
2809
			'filters_enhanced' => true,
2810
			'views'            => array(
2811
				'all'         => __( 'All', 'pods' ),
2812
				// 'recommended' => __( 'Recommended', 'pods' ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2813
				'field-types' => __( 'Field Types', 'pods' ),
2814
				'tools'       => __( 'Tools', 'pods' ),
2815
				'integration' => __( 'Integration', 'pods' ),
2816
				'migration'   => __( 'Migration', 'pods' ),
2817
				'advanced'    => __( 'Advanced', 'pods' ),
2818
			),
2819
			'view'             => $view,
2820
			'heading'          => array(
2821
				'views' => __( 'Category', 'pods' ),
2822
			),
2823
			'search'           => false,
2824
			'searchable'       => false,
2825
			'sortable'         => false,
2826
			'pagination'       => false,
2827
		);
2828
2829
		if ( pods_developer() ) {
2830
			$ui['views']['dev'] = __( 'Developer Preview', 'pods' );
2831
		}
2832
2833
		pods_ui( $ui );
2834
	}
2835
2836
	/**
2837
	 * Toggle a component on or off
2838
	 *
2839
	 * @param PodsUI $ui PodsUI object
2840
	 *
2841
	 * @return bool
2842
	 */
2843
	public function admin_components_toggle( $ui ) {
2844
2845
		// @codingStandardsIgnoreLine
2846
		$component = $_GET['id'];
2847
2848
		if ( ! empty( PodsInit::$components->components[ $component ]['PluginDependency'] ) ) {
2849
			$dependency = explode( '|', PodsInit::$components->components[ $component ]['PluginDependency'] );
2850
2851
			if ( ! pods_is_plugin_active( $dependency[1] ) ) {
2852
				$website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[1] ) . '/';
2853
2854
				if ( isset( $dependency[2] ) ) {
2855
					$website = $dependency[2];
2856
				}
2857
2858
				if ( ! empty( $website ) ) {
2859
					$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' );
2860
				}
2861
2862
				$message = sprintf( __( 'The %1$s component requires that you have the <strong>%2$s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ]['Name'], $dependency[0] ) . $website;
2863
2864
				$ui->error( $message );
2865
2866
				$ui->manage();
2867
2868
				return;
2869
			}
2870
		}//end if
2871
2872
		if ( ! empty( PodsInit::$components->components[ $component ]['ThemeDependency'] ) ) {
2873
			$dependency = explode( '|', PodsInit::$components->components[ $component ]['ThemeDependency'] );
2874
2875
			$check = strtolower( $dependency[1] );
2876
2877
			if ( strtolower( get_template() ) !== $check && strtolower( get_stylesheet() ) !== $check ) {
2878
				$website = '';
2879
2880
				if ( isset( $dependency[2] ) ) {
2881
					$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[2] . '" target="_blank">' . $dependency[2] . '</a>' );
2882
				}
2883
2884
				$message = sprintf( __( 'The %1$s component requires that you have the <strong>%2$s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ]['Name'], $dependency[0] ) . $website;
2885
2886
				$ui->error( $message );
2887
2888
				$ui->manage();
2889
2890
				return;
2891
			}
2892
		}//end if
2893
2894
		if ( ! empty( PodsInit::$components->components[ $component ]['MustUse'] ) ) {
2895
			$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'] );
2896
2897
			$ui->error( $message );
2898
2899
			$ui->manage();
2900
2901
			return;
2902
		}
2903
2904
		if ( '1' === pods_v( 'toggled' ) ) {
2905
			$toggle = PodsInit::$components->toggle( $component );
2906
2907
			if ( true === $toggle ) {
2908
				$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component enabled', 'pods' ) );
2909 View Code Duplication
			} elseif ( false === $toggle ) {
2910
				$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component disabled', 'pods' ) );
2911
			}
2912
2913
			$components = PodsInit::$components->components;
2914
2915
			foreach ( $components as $component => &$component_data ) {
2916
				$toggle = 0;
2917
2918
				if ( isset( PodsInit::$components->settings['components'][ $component_data['ID'] ] ) ) {
2919
					if ( 0 !== PodsInit::$components->settings['components'][ $component_data['ID'] ] ) {
2920
						$toggle = 1;
2921
					}
2922
				}
2923
				if ( true === $component_data['DeveloperMode'] ) {
2924
					if ( ! pods_developer() ) {
2925
						unset( $components[ $component ] );
2926
						continue;
2927
					}
2928
				}
2929
2930
				$component_data = array(
2931
					'id'          => $component_data['ID'],
2932
					'name'        => $component_data['Name'],
2933
					'description' => make_clickable( $component_data['Description'] ),
2934
					'version'     => $component_data['Version'],
2935
					'author'      => $component_data['Author'],
2936
					'toggle'      => $toggle,
2937
				);
2938
			}//end foreach
2939
2940
			$ui->data = $components;
2941
2942
			pods_transient_clear( 'pods_components' );
2943
2944
			$url = pods_query_arg( array( 'toggled' => null ) );
2945
2946
			pods_redirect( $url );
2947 View Code Duplication
		} elseif ( 1 === (int) pods_v( 'toggle' ) ) {
2948
			$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component enabled', 'pods' ) );
2949
		} else {
2950
			$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component disabled', 'pods' ) );
2951
		}//end if
2952
2953
		$ui->manage();
2954
	}
2955
2956
	/**
2957
	 * Get the admin upgrade page
2958
	 */
2959
	public function admin_upgrade() {
2960
2961
		foreach ( PodsInit::$upgrades as $old_version => $new_version ) {
2962
			if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) {
2963
				$new_version = str_replace( '.', '_', $new_version );
2964
2965
				pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) );
2966
2967
				break;
2968
			}
2969
		}
2970
	}
2971
2972
	/**
2973
	 * Get the admin help page
2974
	 */
2975
	public function admin_help() {
2976
2977
		pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) );
2978
	}
2979
2980
	/**
2981
	 * Add pods specific capabilities.
2982
	 *
2983
	 * @param array $capabilities List of extra capabilities to add.
2984
	 *
2985
	 * @return array
2986
	 */
2987
	public function admin_capabilities( $capabilities ) {
2988
2989
		$pods = pods_api()->load_pods(
2990
			array(
2991
				'type'       => array(
2992
					'settings',
2993
					'post_type',
2994
					'taxonomy',
2995
				),
2996
				'fields'     => false,
2997
				'table_info' => false,
2998
			)
2999
		);
3000
3001
		$other_pods = pods_api()->load_pods(
3002
			array(
3003
				'type'       => array(
3004
					'pod',
3005
					'table',
3006
				),
3007
				'table_info' => false,
3008
			)
3009
		);
3010
3011
		$pods = array_merge( $pods, $other_pods );
3012
3013
		$capabilities[] = 'pods';
3014
		$capabilities[] = 'pods_content';
3015
		$capabilities[] = 'pods_settings';
3016
		$capabilities[] = 'pods_components';
3017
3018
		foreach ( $pods as $pod ) {
3019
			if ( 'settings' === $pod['type'] ) {
3020
				$capabilities[] = 'pods_edit_' . $pod['name'];
3021
			} elseif ( 'post_type' === $pod['type'] ) {
3022
				$capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) );
3023
3024
				if ( 'custom' === pods_v( 'capability_type', $pod['options'] ) && 0 < strlen( $capability_type ) ) {
3025
					$capabilities[] = 'read_' . $capability_type;
3026
					$capabilities[] = 'edit_' . $capability_type;
3027
					$capabilities[] = 'delete_' . $capability_type;
3028
3029
					if ( 1 === (int) pods_v( 'capability_type_extra', $pod['options'], 1 ) ) {
3030
						$capability_type_plural = $capability_type . 's';
3031
3032
						$capabilities[] = 'read_private_' . $capability_type_plural;
3033
						$capabilities[] = 'edit_' . $capability_type_plural;
3034
						$capabilities[] = 'edit_others_' . $capability_type_plural;
3035
						$capabilities[] = 'edit_private_' . $capability_type_plural;
3036
						$capabilities[] = 'edit_published_' . $capability_type_plural;
3037
						$capabilities[] = 'publish_' . $capability_type_plural;
3038
						$capabilities[] = 'delete_' . $capability_type_plural;
3039
						$capabilities[] = 'delete_private_' . $capability_type_plural;
3040
						$capabilities[] = 'delete_published_' . $capability_type_plural;
3041
						$capabilities[] = 'delete_others_' . $capability_type_plural;
3042
					}
3043
				}
3044
			} elseif ( 'taxonomy' === $pod['type'] ) {
3045
				if ( 'custom' === pods_v( 'capability_type', $pod['options'], 'terms' ) ) {
3046
					$capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) . 's' );
3047
3048
					$capability_type       .= '_term';
3049
					$capability_type_plural = $capability_type . 's';
3050
3051
					// Singular
3052
					$capabilities[] = 'edit_' . $capability_type;
3053
					$capabilities[] = 'delete_' . $capability_type;
3054
					$capabilities[] = 'assign_' . $capability_type;
3055
					// Plural
3056
					$capabilities[] = 'manage_' . $capability_type_plural;
3057
					$capabilities[] = 'edit_' . $capability_type_plural;
3058
					$capabilities[] = 'delete_' . $capability_type_plural;
3059
					$capabilities[] = 'assign_' . $capability_type_plural;
3060
				}
3061
			} else {
3062
				$capabilities[] = 'pods_add_' . $pod['name'];
3063
				$capabilities[] = 'pods_edit_' . $pod['name'];
3064
3065 View Code Duplication
				if ( isset( $pod['fields']['author'] ) && 'pick' === $pod['fields']['author']['type'] && 'user' === $pod['fields']['author']['pick_object'] ) {
3066
					$capabilities[] = 'pods_edit_others_' . $pod['name'];
3067
				}
3068
3069
				$capabilities[] = 'pods_delete_' . $pod['name'];
3070
3071 View Code Duplication
				if ( isset( $pod['fields']['author'] ) && 'pick' === $pod['fields']['author']['type'] && 'user' === $pod['fields']['author']['pick_object'] ) {
3072
					$capabilities[] = 'pods_delete_others_' . $pod['name'];
3073
				}
3074
3075
				$actions_enabled = pods_v( 'ui_actions_enabled', $pod['options'] );
3076
3077
				if ( ! empty( $actions_enabled ) ) {
3078
					$actions_enabled = (array) $actions_enabled;
3079
				} else {
3080
					$actions_enabled = array();
3081
				}
3082
3083
				$available_actions = array(
3084
					'add',
3085
					'edit',
3086
					'duplicate',
3087
					'delete',
3088
					'reorder',
3089
					'export',
3090
				);
3091
3092
				if ( ! empty( $actions_enabled ) ) {
3093
					$actions_disabled = array(
3094
						'view' => 'view',
3095
					);
3096
3097 View Code Duplication
					foreach ( $available_actions as $action ) {
3098
						if ( ! in_array( $action, $actions_enabled, true ) ) {
3099
							$actions_disabled[ $action ] = $action;
3100
						}
3101
					}
3102
3103
					if ( ! in_array( 'export', $actions_disabled, true ) ) {
3104
						$capabilities[] = 'pods_export_' . $pod['name'];
3105
					}
3106
3107
					if ( ! in_array( 'reorder', $actions_disabled, true ) ) {
3108
						$capabilities[] = 'pods_reorder_' . $pod['name'];
3109
					}
3110
				} elseif ( 1 === (int) pods_v( 'ui_export', $pod['options'], 0 ) ) {
3111
					$capabilities[] = 'pods_export_' . $pod['name'];
3112
				}//end if
3113
			}//end if
3114
		}//end foreach
3115
3116
		return $capabilities;
3117
	}
3118
3119
	/**
3120
	 * Handle ajax calls for the administration
3121
	 */
3122
	public function admin_ajax() {
3123
3124
		if ( false === headers_sent() ) {
3125
			pods_session_start();
3126
3127
			header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
3128
		}
3129
3130
		// Sanitize input
3131
		// @codingStandardsIgnoreLine
3132
		$params = pods_unslash( (array) $_POST );
3133
3134
		foreach ( $params as $key => $value ) {
3135
			if ( 'action' === $key ) {
3136
				continue;
3137
			}
3138
3139
			// Fixup $_POST data @codingStandardsIgnoreLine
3140
			$_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ];
3141
3142
			// Fixup $params with unslashed data
3143
			$params[ str_replace( '_podsfix_', '', $key ) ] = $value;
3144
3145
			// Unset the _podsfix_* keys
3146
			unset( $params[ $key ] );
3147
		}
3148
3149
		$params = (object) $params;
3150
3151
		$methods = array(
3152
			'add_pod'                 => array( 'priv' => true ),
3153
			'save_pod'                => array( 'priv' => true ),
3154
			'load_sister_fields'      => array( 'priv' => true ),
3155
			'process_form'            => array( 'custom_nonce' => true ),
3156
			// priv handled through nonce
3157
							'upgrade' => array( 'priv' => true ),
3158
			'migrate'                 => array( 'priv' => true ),
3159
		);
3160
3161
		/**
3162
		 * AJAX Callbacks in field editor
3163
		 *
3164
		 * @since unknown
3165
		 *
3166
		 * @param array     $methods Callback methods.
3167
		 * @param PodsAdmin $obj     PodsAdmin object.
3168
		 */
3169
		$methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this );
3170
3171
		if ( ! isset( $params->method ) || ! isset( $methods[ $params->method ] ) ) {
3172
			pods_error( 'Invalid AJAX request', $this );
3173
		}
3174
3175
		$defaults = array(
3176
			'priv'         => null,
3177
			'name'         => $params->method,
3178
			'custom_nonce' => null,
3179
		);
3180
3181
		$method = (object) array_merge( $defaults, (array) $methods[ $params->method ] );
3182
3183
		if ( true !== $method->custom_nonce && ( ! isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) ) {
3184
			pods_error( __( 'Unauthorized request', 'pods' ), $this );
3185
		}
3186
3187
		// Cleaning up $params
3188
		unset( $params->action );
3189
		unset( $params->method );
3190
3191
		if ( true !== $method->custom_nonce ) {
3192
			unset( $params->_wpnonce );
3193
		}
3194
3195
		// Check permissions (convert to array to support multiple)
3196
		if ( ! empty( $method->priv ) && ! pods_is_admin( array( 'pods' ) ) && true !== $method->priv && ! pods_is_admin( $method->priv ) ) {
3197
			pods_error( __( 'Access denied', 'pods' ), $this );
3198
		}
3199
3200
		$params->method = $method->name;
3201
3202
		$params = apply_filters( 'pods_api_' . $method->name, $params, $method );
3203
3204
		$api = pods_api();
3205
3206
		$api->display_errors = false;
3207
3208
		if ( 'upgrade' === $method->name ) {
3209
			$output = (string) pods_upgrade( $params->version )->ajax( $params );
3210
		} elseif ( 'migrate' === $method->name ) {
3211
			$output = (string) apply_filters( 'pods_api_migrate_run', $params );
3212
		} else {
3213
			if ( ! method_exists( $api, $method->name ) ) {
3214
				pods_error( 'API method does not exist', $this );
3215
			} elseif ( 'save_pod' === $method->name ) {
3216
				if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) {
3217
					$params->fields = $params->field_data_json;
3218
3219
					unset( $params->field_data_json );
3220
3221
					foreach ( $params->fields as $k => $v ) {
3222
						if ( empty( $v ) ) {
3223
							unset( $params->fields[ $k ] );
3224
						} elseif ( ! is_array( $v ) ) {
3225
							$params->fields[ $k ] = (array) @json_decode( $v, true );
3226
						}
3227
					}
3228
				}
3229
			}
3230
3231
			// Dynamically call the API method
3232
			$params = (array) $params;
3233
3234
			$output = call_user_func( array( $api, $method->name ), $params );
3235
		}//end if
3236
3237
		// Output in json format
3238
		if ( false !== $output ) {
3239
3240
			/**
3241
			 * Pods Admin AJAX request was successful
3242
			 *
3243
			 * @since  2.6.8
3244
			 *
3245
			 * @param array               $params AJAX parameters.
3246
			 * @param array|object|string $output Output for AJAX request.
3247
			 */
3248
			do_action( "pods_admin_ajax_success_{$method->name}", $params, $output );
3249
3250
			if ( is_array( $output ) || is_object( $output ) ) {
3251
				wp_send_json( $output );
3252
			} else {
3253
				// @codingStandardsIgnoreLine
3254
				echo $output;
3255
			}
3256
		} else {
3257
			pods_error( 'There was a problem with your request.' );
3258
		}//end if
3259
3260
		die();
3261
		// KBAI!
3262
	}
3263
3264
	/**
3265
	 * Profiles the Pods configuration
3266
	 *
3267
	 * @param null|string|array $pod             Which Pod(s) to get configuration for. Can be a the name
3268
	 *                                           of one Pod, or an array of names of Pods, or null, which is the
3269
	 *                                           default, to profile all Pods.
3270
	 * @param bool              $full_field_info If true all info about each field is returned. If false,
3271
	 *                                           which is the default only name and type, will be returned.
3272
	 *
3273
	 * @return array
3274
	 *
3275
	 * @since 3.0.0
3276
	 */
3277
	public function configuration( $pod = null, $full_field_info = false ) {
3278
3279
		$api = pods_api();
3280
3281
		if ( is_null( $pod ) ) {
3282
			$the_pods = $api->load_pods();
3283
		} elseif ( is_array( $pod ) ) {
3284
			foreach ( $pod as $p ) {
3285
				$the_pods[] = $api->load_pod( $p );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$the_pods was never initialized. Although not strictly required by PHP, it is generally a good practice to add $the_pods = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
3286
			}
3287
		} else {
3288
			$the_pods[] = $api->load_pod( $pod );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$the_pods was never initialized. Although not strictly required by PHP, it is generally a good practice to add $the_pods = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
3289
		}
3290
3291
		foreach ( $the_pods as $the_pod ) {
0 ignored issues
show
Bug introduced by
The variable $the_pods does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The expression $the_pods of type array|object|integer|double|string|null|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
3292
			$configuration[ $the_pod['name'] ] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$configuration was never initialized. Although not strictly required by PHP, it is generally a good practice to add $configuration = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
3293
				'name'    => $the_pod['name'],
3294
				'ID'      => $the_pod['id'],
3295
				'storage' => $the_pod['storage'],
3296
				'fields'  => $the_pod['fields'],
3297
			);
3298
		}
3299
3300
		if ( ! $full_field_info ) {
3301
			foreach ( $the_pods as $the_pod ) {
0 ignored issues
show
Bug introduced by
The expression $the_pods of type array|object|integer|double|string|null|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
3302
				$fields = $configuration[ $the_pod['name'] ]['fields'];
0 ignored issues
show
Bug introduced by
The variable $configuration does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3303
3304
				unset( $configuration[ $the_pod['name'] ]['fields'] );
3305
3306
				foreach ( $fields as $field ) {
3307
					$info = array(
3308
						'name' => $field['name'],
3309
						'type' => $field['type'],
3310
					);
3311
3312
					if ( 'pick' === $info['type'] ) {
3313
						$info['pick_object'] = $field['pick_object'];
3314
3315
						if ( isset( $field['pick_val'] ) && '' !== $field['pick_val'] ) {
3316
							$info['pick_val'] = $field['pick_val'];
3317
						}
3318
					}
3319
3320
					if ( is_array( $info ) ) {
3321
						$configuration[ $the_pod['name'] ]['fields'][ $field['name'] ] = $info;
3322
					}
3323
3324
					unset( $info );
3325
3326
				}//end foreach
3327
			}//end foreach
3328
		}//end if
3329
3330
		if ( is_array( $configuration ) ) {
3331
			return $configuration;
3332
		}
3333
3334
	}
3335
3336
	/**
3337
	 * Build UI for extending REST API, if makes sense to do so.
3338
	 *
3339
	 * @since  2.6.0
3340
	 *
3341
	 * @access protected
3342
	 */
3343
	protected function rest_admin() {
3344
3345
		if ( function_exists( 'register_rest_field' ) ) {
3346
			add_filter(
3347
				'pods_admin_setup_edit_field_options', array(
3348
					$this,
3349
					'add_rest_fields_to_field_editor',
3350
				), 12, 2
3351
			);
3352
			add_filter( 'pods_admin_setup_edit_field_tabs', array( $this, 'add_rest_field_tab' ), 12 );
3353
		}
3354
3355
		add_filter( 'pods_admin_setup_edit_tabs', array( $this, 'add_rest_settings_tab' ), 12, 2 );
3356
		add_filter( 'pods_admin_setup_edit_options', array( $this, 'add_rest_settings_tab_fields' ), 12, 2 );
3357
3358
	}
3359
3360
	/**
3361
	 * Check if Pod type <em>could</em> extend core REST API response
3362
	 *
3363
	 * @since  2.5.6
3364
	 *
3365
	 * @access protected
3366
	 *
3367
	 * @param array $pod Pod options.
3368
	 *
3369
	 * @return bool
3370
	 */
3371
	protected function restable_pod( $pod ) {
3372
3373
		$type = $pod['type'];
3374
3375
		$restable_types = array(
3376
			'post_type',
3377
			'user',
3378
			'taxonomy',
3379
			'media',
3380
		);
3381
3382
		return in_array( $type, $restable_types, true );
3383
3384
	}
3385
3386
	/**
3387
	 * Add a rest api tab.
3388
	 *
3389
	 * @since 2.6.0
3390
	 *
3391
	 * @param array $tabs Tab array.
3392
	 * @param array $pod  Pod options.
3393
	 *
3394
	 * @return array
3395
	 */
3396
	public function add_rest_settings_tab( $tabs, $pod ) {
3397
3398
		$tabs['rest-api'] = __( 'REST API', 'pods' );
3399
3400
		return $tabs;
3401
3402
	}
3403
3404
	/**
3405
	 * Populate REST API tab.
3406
	 *
3407
	 * @since 0.1.0
3408
	 *
3409
	 * @param array $options Tab options.
3410
	 * @param array $pod     Pod options.
3411
	 *
3412
	 * @return array
3413
	 */
3414
	public function add_rest_settings_tab_fields( $options, $pod ) {
3415
3416
		if ( ! function_exists( 'register_rest_field' ) ) {
3417
			$options['rest-api'] = array(
3418
				'no_dependencies' => array(
3419
					'label' => __( sprintf( 'Pods REST API support requires WordPress 4.3.1 or later and the %s or later.', '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">WordPress REST API 2.0-beta9</a>' ), 'pods' ),
3420
					'help'  => __( sprintf( 'See %s for more information.', '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/</a>' ), 'pods' ),
3421
					'type'  => 'html',
3422
				),
3423
			);
3424
		} elseif ( $this->restable_pod( $pod ) ) {
3425
			$options['rest-api'] = array(
3426
				'rest_enable' => array(
3427
					'label'      => __( 'Enable', 'pods' ),
3428
					'help'       => __( 'Add REST API support for this Pod.', 'pods' ),
3429
					'type'       => 'boolean',
3430
					'default'    => '',
3431
					'dependency' => true,
3432
				),
3433
				'rest_base'   => array(
3434
					'label'      => __( 'REST Base (if any)', 'pods' ),
3435
					'help'       => __( 'This will form the url for the route. Default / empty value here will use the pod name.', 'pods' ),
3436
					'type'       => 'text',
3437
					'default'    => '',
3438
					'depends-on' => array( 'rest_enable' => true ),
3439
				),
3440
				'read_all'    => array(
3441
					'label'      => __( 'Show All Fields (read-only)', 'pods' ),
3442
					'help'       => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
3443
					'type'       => 'boolean',
3444
					'default'    => '',
3445
					'depends-on' => array( 'rest_enable' => true ),
3446
				),
3447
				'write_all'   => array(
3448
					'label'             => __( 'Allow All Fields To Be Updated', 'pods' ),
3449
					'help'              => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
3450
					'type'              => 'boolean',
3451
					'default'           => pods_v( 'name', $pod ),
3452
					'boolean_yes_label' => '',
3453
					'depends-on'        => array( 'rest_enable' => true ),
3454
				),
3455
3456
			);
3457
3458
		} else {
3459
			$options['rest-api'] = array(
3460
				'not_restable' => array(
3461
					'label' => __( 'Pods REST API support covers post type, taxonomy and user Pods.', 'pods' ),
3462
					'help'  => __( sprintf( 'See %s for more information.', '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/"</a>' ), 'pods' ),
3463
					'type'  => 'html',
3464
				),
3465
			);
3466
3467
		}//end if
3468
3469
		return $options;
3470
3471
	}
3472
3473
	/**
3474
	 * Add a REST API section to advanced tab of field editor.
3475
	 *
3476
	 * @since 2.5.6
3477
	 *
3478
	 * @param array $options Tab options.
3479
	 * @param array $pod     Pod options.
3480
	 *
3481
	 * @return array
3482
	 */
3483
	public function add_rest_fields_to_field_editor( $options, $pod ) {
3484
3485
		if ( $this->restable_pod( $pod ) ) {
3486
			$options['rest'][ __( 'Read/ Write', 'pods' ) ]                = array(
3487
				'rest_read'  => array(
3488
					'label'   => __( 'Read via REST API?', 'pods' ),
3489
					'help'    => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),
3490
					'type'    => 'boolean',
3491
					'default' => '',
3492
				),
3493
				'rest_write' => array(
3494
					'label'   => __( 'Write via REST API?', 'pods' ),
3495
					'help'    => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),
3496
					'type'    => 'boolean',
3497
					'default' => '',
3498
				),
3499
			);
3500
			$options['rest'][ __( 'Relationship Field Options', 'pods' ) ] = array(
3501
				'rest_pick_response' => array(
3502
					'label'      => __( 'Response Type', 'pods' ),
3503
					'help'       => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),
3504
					'type'       => 'pick',
3505
					'default'    => 'array',
3506
					'depends-on' => array( 'type' => 'pick' ),
3507
					'data'       => array(
3508
						'array' => __( 'Full', 'pods' ),
3509
						'id'    => __( 'ID only', 'pods' ),
3510
						'name'  => __( 'Name', 'pods' ),
3511
3512
					),
3513
				),
3514
				'rest_pick_depth'    => array(
3515
					'label'      => __( 'Depth', 'pods' ),
3516
					'help'       => __( 'How far to traverse relationships in response', 'pods' ),
3517
					'type'       => 'number',
3518
					'default'    => '2',
3519
					'depends-on' => array( 'type' => 'pick' ),
3520
3521
				),
3522
3523
			);
3524
3525
		}//end if
3526
3527
		return $options;
3528
3529
	}
3530
3531
	/**
3532
	 * Add REST field tab
3533
	 *
3534
	 * @since 2.5.6
3535
	 *
3536
	 * @param array $tabs Tab list.
3537
	 *
3538
	 * @return array
3539
	 */
3540
	public function add_rest_field_tab( $tabs ) {
3541
3542
		$tabs['rest'] = __( 'REST API', 'pods' );
3543
3544
		return $tabs;
3545
	}
3546
3547
}
3548