Completed
Pull Request — 2.x (#4778)
by Scott Kingsley
06:34
created

PodsInit::add_rest_support()   C

Complexity

Conditions 17
Paths 27

Size

Total Lines 62
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 33
c 0
b 0
f 0
nc 27
nop 0
dl 0
loc 62
rs 6.1162

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @package Pods
4
 */
5
class PodsInit {
6
7
	/**
8
	 * @var PodsInit
9
	 */
10
	static $instance = null;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $instance.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	/**
13
	 * @var array
14
	 */
15
	static $no_conflict = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $no_conflict.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
17
	/**
18
	 * @var array
19
	 */
20
	static $content_types_registered = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $content_types_registered.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
21
22
	/**
23
	 * @var PodsComponents
24
	 */
25
	static $components;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $components.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
26
27
	/**
28
	 * @var PodsMeta
29
	 */
30
	static $meta;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $meta.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
31
32
	/**
33
	 * @var PodsI18n
34
	 */
35
	static $i18n;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $i18n.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
36
37
	/**
38
	 * @var PodsAdmin
39
	 */
40
	static $admin;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $admin.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
41
42
	/**
43
	 * @var mixed|void
44
	 */
45
	static $version;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $version.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
46
47
	/**
48
	 * @var mixed|void
49
	 */
50
	static $version_last;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $version_last.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
51
52
	/**
53
	 * @var mixed|void
54
	 */
55
	static $db_version;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $db_version.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
56
57
	/**
58
	 * Upgrades to trigger (last installed version => upgrade version)
59
	 *
60
	 * @var array
61
	 */
62
	static $upgrades = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $upgrades.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
63
		'1.0.0' => '2.0.0'
64
		//'2.0.0' => '2.1.0'
65
	);
66
67
	/**
68
	 * Whether an Upgrade for 1.x has happened
69
	 *
70
	 * @var bool
71
	 */
72
	static $upgraded;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $upgraded.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
73
74
	/**
75
	 * Whether an Upgrade is needed
76
	 *
77
	 * @var bool
78
	 */
79
	static $upgrade_needed = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $upgrade_needed.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
80
81
	/**
82
	 * Singleton handling for a basic pods_init() request
83
	 *
84
	 * @return \PodsInit
85
	 *
86
	 * @since 2.3.5
87
	 */
88
	public static function init() {
89
90
		if ( ! is_object( self::$instance ) ) {
91
			self::$instance = new PodsInit();
92
		}
93
94
		return self::$instance;
95
	}
96
97
	/**
98
	 * Setup and Initiate Pods
99
	 *
100
	 * @return \PodsInit
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...
101
	 *
102
	 * @license http://www.gnu.org/licenses/gpl-2.0.html
103
	 * @since   1.8.9
104
	 */
105
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
106
107
		self::$version      = get_option( 'pods_framework_version' );
108
		self::$version_last = get_option( 'pods_framework_version_last' );
109
		self::$db_version   = get_option( 'pods_framework_db_version' );
110
		self::$upgraded     = (int) get_option( 'pods_framework_upgraded_1_x' );
111
112
		if ( empty( self::$version_last ) && 0 < strlen( get_option( 'pods_version' ) ) ) {
113
			$old_version = get_option( 'pods_version' );
114
115
			if ( ! empty( $old_version ) ) {
116
				if ( false === strpos( $old_version, '.' ) ) {
117
					$old_version = pods_version_to_point( $old_version );
118
				}
119
120
				update_option( 'pods_framework_version_last', $old_version );
121
122
				self::$version_last = $old_version;
123
			}
124
		}
125
126
		self::$upgrade_needed = $this->needs_upgrade();
127
128
		add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
129
		add_action( 'plugins_loaded', array( $this, 'activate_install' ), 9 );
130
131
		add_action( 'wp_loaded', array( $this, 'flush_rewrite_rules' ) );
132
133
		$this->run();
134
135
	}
136
137
	/**
138
	 * Load the plugin textdomain and set default constants
139
	 */
140
	public function plugins_loaded() {
141
142
		if ( ! defined( 'PODS_LIGHT' ) ) {
143
			define( 'PODS_LIGHT', false );
144
		}
145
146
		if ( ! defined( 'PODS_TABLELESS' ) ) {
147
			define( 'PODS_TABLELESS', false );
148
		}
149
150
		load_plugin_textdomain( 'pods' );
151
152
	}
153
154
	/**
155
	 * Load Pods Components
156
	 */
157
	public function load_components() {
158
159
		if ( empty( self::$version ) ) {
160
			return;
161
		}
162
163
		if ( ! defined( 'PODS_LIGHT' ) || ! PODS_LIGHT ) {
164
			self::$components = pods_components();
165
		}
166
167
	}
168
169
	/**
170
	 * Load Pods Meta
171
	 */
172
	public function load_meta() {
173
174
		self::$meta = pods_meta()->core();
175
	}
176
177
	/**
178
	 *
179
	 */
180
	public function load_i18n() {
181
182
		self::$i18n = pods_i18n();
183
	}
184
185
186
	/**
187
	 * Set up the Pods core
188
	 */
189
	public function core() {
190
191
		if ( empty( self::$version ) ) {
192
			return;
193
		}
194
195
		// Session start
196
		pods_session_start();
197
198
		add_shortcode( 'pods', 'pods_shortcode' );
199
		add_shortcode( 'pods-form', 'pods_shortcode_form' );
200
201
		$security_settings = array(
202
			'pods_disable_file_browser'     => 0,
203
			'pods_files_require_login'      => 1,
204
			'pods_files_require_login_cap'  => '',
205
			'pods_disable_file_upload'      => 0,
206
			'pods_upload_require_login'     => 1,
207
			'pods_upload_require_login_cap' => ''
208
		);
209
210
		foreach ( $security_settings as $security_setting => $setting ) {
211
			$setting = get_option( $security_setting );
212
			if ( ! empty( $setting ) ) {
213
				$security_settings[ $security_setting ] = $setting;
214
			}
215
		}
216
217
		foreach ( $security_settings as $security_setting => $setting ) {
218
			if ( 0 == $setting ) {
219
				$setting = false;
220
			} elseif ( 1 == $setting ) {
221
				$setting = true;
222
			}
223
224
			if ( in_array( $security_setting, array( 'pods_files_require_login', 'pods_upload_require_login' ) ) ) {
225
				if ( 0 < strlen( $security_settings[ $security_setting . '_cap' ] ) ) {
226
					$setting = $security_settings[ $security_setting . '_cap' ];
227
				}
228
			} elseif ( in_array( $security_setting, array(
229
				'pods_files_require_login_cap',
230
				'pods_upload_require_login_cap'
231
			) ) ) {
232
				continue;
233
			}
234
235
			if ( ! defined( strtoupper( $security_setting ) ) ) {
236
				define( strtoupper( $security_setting ), $setting );
237
			}
238
		}
239
240
		$this->register_pods();
241
242
		$avatar = PodsForm::field_loader( 'avatar' );
243
244
		if ( method_exists( $avatar, 'get_avatar' ) ) {
245
			add_filter( 'get_avatar', array( $avatar, 'get_avatar' ), 10, 4 );
246
		}
247
	}
248
249
	/**
250
	 * Register Scripts and Styles
251
	 */
252
	public function register_assets() {
253
254
		$maybe_min = SCRIPT_DEBUG ? '' : '.min';
255
256
		wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' );
257
258
		if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) {
259
			wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' );
260
		}
261
262
		wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array(
263
			'jquery',
264
			'pods-dfv',
265
			'pods-i18n',
266
			'pods-json',
267
			'jquery-qtip2'
268
		), PODS_VERSION, true );
269
270
		wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' );
271
272
		wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '4.8', true );
273
		wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/addon/mode/loadmode.js', array( 'pods-codemirror' ), '4.8', true );
274
		wp_register_script( 'pods-codemirror-overlay', PODS_URL . 'ui/js/codemirror/addon/mode/overlay.js', array( 'pods-codemirror' ), '4.8', true );
275
		wp_register_script( 'pods-codemirror-hints', PODS_URL . 'ui/js/codemirror/addon/mode/show-hint.js', array( 'pods-codemirror' ), '4.8', true );
276
		wp_register_script( 'pods-codemirror-mode-xml', PODS_URL . 'ui/js/codemirror/mode/xml/xml.js', array( 'pods-codemirror' ), '4.8', true );
277
		wp_register_script( 'pods-codemirror-mode-html', PODS_URL . 'ui/js/codemirror/mode/htmlmixed/htmlmixed.js', array( 'pods-codemirror' ), '4.8', true );
278
		wp_register_script( 'pods-codemirror-mode-css', PODS_URL . 'ui/js/codemirror/mode/css/css.js', array( 'pods-codemirror' ), '4.8', true );
279
280
		if ( ! wp_script_is( 'jquery-ui-slideraccess', 'registered' ) ) {
281
			// No need to add dependencies. All managed by jquery-ui-timepicker.
282
			wp_register_script( 'jquery-ui-slideraccess', PODS_URL . 'ui/js/timepicker/jquery-ui-sliderAccess.js', array(), '0.3' );
283
		}
284
285
		if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) {
286
			wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/timepicker/jquery-ui-timepicker-addon.min.js', array(
287
				'jquery',
288
				'jquery-ui-core',
289
				'jquery-ui-datepicker',
290
				'jquery-ui-slider',
291
				'jquery-ui-slideraccess',
292
			), '1.6.3' );
293
		}
294
		if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) {
295
			wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/js/timepicker/jquery-ui-timepicker-addon.min.css', array(), '1.6.3' );
296
		}
297
298
		wp_register_script( 'pods-select2', PODS_URL . "ui/js/selectWoo/selectWoo{$maybe_min}.js", array( 'jquery', 'pods-i18n' ), '1.0.1' );
299
		wp_register_style( 'pods-select2', PODS_URL . "ui/js/selectWoo/selectWoo{$maybe_min}.css", array(), '1.0.1' );
300
301
		$register_handlebars = apply_filters( 'pods_script_register_handlebars', true );
302
303
		if ( is_admin() ) {
304
			$screen = get_current_screen();
305
306
			// Deregister the outdated Pods handlebars script on TEC event screen
307
			if ( $screen && 'tribe_events' === $screen->post_type ) {
308
				$register_handlebars = false;
309
			}
310
		}
311
312
		if ( $register_handlebars ) {
313
			wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' );
314
		}
315
316
		// Marionette dependencies for MV fields
317
		wp_register_script( 'backbone.radio', PODS_URL . 'ui/js/marionette/backbone.radio.js', array( 'backbone' ), '2.0.0', true );
318
		wp_register_script( 'marionette', PODS_URL . 'ui/js/marionette/backbone.marionette.js', array( 'backbone', 'backbone.radio' ), '3.1.0', true );
319
320
		// MV stuff
321
		wp_register_script(
322
			'pods-dfv',
323
			PODS_URL . 'ui/js/pods-dfv/pods-dfv.min.js',
324
			array(
325
				'jquery',
326
				'jquery-ui-core',
327
				'jquery-ui-sortable',
328
				'pods-i18n',
329
				'marionette',
330
				'media-views',
331
				'media-models'
332
			),
333
			PODS_VERSION,
334
			true
335
		);
336
337
		// Check if Pod is a Modal Window
338
		if ( pods_is_modal_window() ) {
339
340
			function add_classes_to_body_class( $classes ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
341
				$classes .= 'pods-modal-window';
342
343
				return $classes;
344
			}
345
346
			add_filter( 'body_class', 'add_classes_to_body_class' );
347
			add_filter( 'admin_body_class', 'add_classes_to_body_class' );
348
		}
349
350
		// As of 2.7 we combine styles to just three .css files
351
		wp_register_style( 'pods-styles', PODS_URL . 'ui/styles/dist/pods.css', array(), PODS_VERSION );
352
		wp_register_style( 'pods-wizard', PODS_URL . 'ui/styles/dist/pods-wizard.css', array(), PODS_VERSION );
353
		wp_register_style( 'pods-form', PODS_URL . 'ui/styles/dist/pods-form.css', array(), PODS_VERSION );
354
355
	}
356
357
	/**
358
	 * Register internal Post Types
359
	 */
360
	public function register_pods() {
361
362
		$args = array(
363
			'label'           => 'Pods',
364
			'labels'          => array( 'singular_name' => 'Pod' ),
365
			'public'          => false,
366
			'can_export'      => false,
367
			'query_var'       => false,
368
			'rewrite'         => false,
369
			'capability_type' => 'pods_pod',
370
			'has_archive'     => false,
371
			'hierarchical'    => false,
372
			'supports'        => array( 'title', 'author' ),
373
			'menu_icon'       => 'dashicons-pods'
374
		);
375
376
		$args = self::object_label_fix( $args, 'post_type' );
377
378
		register_post_type( '_pods_pod', apply_filters( 'pods_internal_register_post_type_pod', $args ) );
379
380
		$args = array(
381
			'label'           => 'Pod Fields',
382
			'labels'          => array( 'singular_name' => 'Pod Field' ),
383
			'public'          => false,
384
			'can_export'      => false,
385
			'query_var'       => false,
386
			'rewrite'         => false,
387
			'capability_type' => 'pods_pod',
388
			'has_archive'     => false,
389
			'hierarchical'    => true,
390
			'supports'        => array( 'title', 'editor', 'author' ),
391
			'menu_icon'       => 'dashicons-pods'
392
		);
393
394
		$args = self::object_label_fix( $args, 'post_type' );
395
396
		register_post_type( '_pods_field', apply_filters( 'pods_internal_register_post_type_field', $args ) );
397
	}
398
399
	/**
400
	 * Include Admin
401
	 */
402
	public function admin_init() {
403
404
		self::$admin = pods_admin();
405
	}
406
407
	/**
408
	 * Register Post Types and Taxonomies
409
	 */
410
	public function setup_content_types( $force = false ) {
411
412
		if ( empty( self::$version ) ) {
413
			return;
414
		}
415
416
        require_once( PODS_DIR . 'classes/PodsRESTHandlers.php' );
417
        require_once( PODS_DIR . 'classes/PodsRESTFields.php' );
418
419
		$post_types = PodsMeta::$post_types;
420
		$taxonomies = PodsMeta::$taxonomies;
421
422
		$existing_post_types = get_post_types();
423
		$existing_taxonomies = get_taxonomies();
424
425
		$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
426
427
		$cpt_positions = array();
428
429
		if ( empty( $pods_cpt_ct ) && ( ! empty( $post_types ) || ! empty( $taxonomies ) ) ) {
430
			$force = true;
431
		} elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['post_types'] ) && ! empty( $post_types ) ) {
432
			$force = true;
433
		} elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['taxonomies'] ) && ! empty( $taxonomies ) ) {
434
			$force = true;
435
		}
436
437
		if ( false === $pods_cpt_ct || $force ) {
438
			/**
439
			 * @var WP_Query
440
			 */
441
			global $wp_query;
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...
442
443
			$reserved_query_vars = array(
444
				'post_type',
445
				'taxonomy',
446
				'output'
447
			);
448
449
			if ( is_object( $wp_query ) ) {
450
				$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
451
			}
452
453
			$pods_cpt_ct = array(
454
				'post_types' => array(),
455
				'taxonomies' => array()
456
			);
457
458
			$pods_post_types      = $pods_taxonomies = array();
459
			$supported_post_types = $supported_taxonomies = array();
460
461
			$post_format_post_types = array();
462
463
			foreach ( $post_types as $post_type ) {
464 View Code Duplication
				if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
465
					// Post type was setup already
466
					continue;
467
				} elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) {
468
					// Post type exists already
469
470
					continue;
471
				} elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) {
472
					// Post type was setup and exists already, but we aren't forcing it to be setup again
473
					continue;
474
				}
475
476
				$post_type['options']['name'] = $post_type['name'];
477
				$post_type                    = array_merge( $post_type, (array) $post_type['options'] );
478
479
				$post_type_name = pods_v_sanitized( 'name', $post_type );
480
481
				// Labels
482
				$cpt_label    = esc_html( pods_v( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'name', $post_type ) ) ), true ) );
483
				$cpt_singular = esc_html( pods_v( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'label', $post_type, $post_type_name, null, true ) ) ), true ) );
484
485
				$cpt_labels                          = array();
486
				$cpt_labels['name']                  = $cpt_label;
487
				$cpt_labels['singular_name']         = $cpt_singular;
488
				$cpt_labels['menu_name']             = pods_v( 'menu_name', $post_type, '', true );
489
				$cpt_labels['name_admin_bar']        = pods_v( 'name_admin_bar', $post_type, '', true );
490
				$cpt_labels['add_new']               = pods_v( 'label_add_new', $post_type, '', true );
491
				$cpt_labels['add_new_item']          = pods_v( 'label_add_new_item', $post_type, '', true );
492
				$cpt_labels['new_item']              = pods_v( 'label_new_item', $post_type, '', true );
493
				$cpt_labels['edit']                  = pods_v( 'label_edit', $post_type, '', true );
494
				$cpt_labels['edit_item']             = pods_v( 'label_edit_item', $post_type, '', true );
495
				$cpt_labels['view']                  = pods_v( 'label_view', $post_type, '', true );
496
				$cpt_labels['view_item']             = pods_v( 'label_view_item', $post_type, '', true );
497
				$cpt_labels['view_items']            = pods_v( 'label_view_items', $post_type, '', true );
498
				$cpt_labels['all_items']             = pods_v( 'label_all_items', $post_type, '', true );
499
				$cpt_labels['search_items']          = pods_v( 'label_search_items', $post_type, '', true );
500
				$cpt_labels['not_found']             = pods_v( 'label_not_found', $post_type, '', true );
501
				$cpt_labels['not_found_in_trash']    = pods_v( 'label_not_found_in_trash', $post_type, '', true );
502
				$cpt_labels['parent']                = pods_v( 'label_parent', $post_type, '', true );
503
				$cpt_labels['parent_item_colon']     = pods_v( 'label_parent_item_colon', $post_type, '', true );
504
				$cpt_labels['archives']              = pods_v( 'label_archives', $post_type, '', true );
505
				$cpt_labels['attributes']            = pods_v( 'label_attributes', $post_type, '', true );
506
				$cpt_labels['insert_into_item']      = pods_v( 'label_insert_into_item', $post_type, '', true );
507
				$cpt_labels['uploaded_to_this_item'] = pods_v( 'label_uploaded_to_this_item', $post_type, '', true );
508
				$cpt_labels['featured_image']        = pods_v( 'label_featured_image', $post_type, '', true );
509
				$cpt_labels['set_featured_image']    = pods_v( 'label_set_featured_image', $post_type, '', true );
510
				$cpt_labels['remove_featured_image'] = pods_v( 'label_remove_featured_image', $post_type, '', true );
511
				$cpt_labels['use_featured_image']    = pods_v( 'label_use_featured_image', $post_type, '', true );
512
				$cpt_labels['filter_items_list']     = pods_v( 'label_filter_items_list', $post_type, '', true );
513
				$cpt_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $post_type, '', true );
514
				$cpt_labels['items_list']            = pods_v( 'label_items_list', $post_type, '', true );
515
516
				// Supported
517
				$cpt_supported = array(
518
					'title'           => (boolean) pods_v( 'supports_title', $post_type, false ),
519
					'editor'          => (boolean) pods_v( 'supports_editor', $post_type, false ),
520
					'author'          => (boolean) pods_v( 'supports_author', $post_type, false ),
521
					'thumbnail'       => (boolean) pods_v( 'supports_thumbnail', $post_type, false ),
522
					'excerpt'         => (boolean) pods_v( 'supports_excerpt', $post_type, false ),
523
					'trackbacks'      => (boolean) pods_v( 'supports_trackbacks', $post_type, false ),
524
					'custom-fields'   => (boolean) pods_v( 'supports_custom_fields', $post_type, false ),
525
					'comments'        => (boolean) pods_v( 'supports_comments', $post_type, false ),
526
					'revisions'       => (boolean) pods_v( 'supports_revisions', $post_type, false ),
527
					'page-attributes' => (boolean) pods_v( 'supports_page_attributes', $post_type, false ),
528
					'post-formats'    => (boolean) pods_v( 'supports_post_formats', $post_type, false )
529
				);
530
531
				// Custom Supported
532
				$cpt_supported_custom = pods_v_sanitized( 'supports_custom', $post_type, '' );
533
534
				if ( ! empty( $cpt_supported_custom ) ) {
535
					$cpt_supported_custom = explode( ',', $cpt_supported_custom );
536
					$cpt_supported_custom = array_filter( array_unique( $cpt_supported_custom ) );
537
538
					foreach ( $cpt_supported_custom as $cpt_support ) {
539
						$cpt_supported[ $cpt_support ] = true;
540
					}
541
				}
542
543
				// Genesis Support
544
				if ( function_exists( 'genesis' ) ) {
545
					$cpt_supported['genesis-seo']             = (boolean) pods_var( 'supports_genesis_seo', $post_type, false );
546
					$cpt_supported['genesis-layouts']         = (boolean) pods_var( 'supports_genesis_layouts', $post_type, false );
547
					$cpt_supported['genesis-simple-sidebars'] = (boolean) pods_var( 'supports_genesis_simple_sidebars', $post_type, false );
548
				}
549
550
				// YARPP Support
551
				if ( defined( 'YARPP_VERSION' ) ) {
552
					$cpt_supported['yarpp_support'] = (boolean) pods_var( 'supports_yarpp_support', $post_type, false );
553
				}
554
555
				// Jetpack Support
556
				if ( class_exists( 'Jetpack' ) ) {
557
					$cpt_supported['supports_jetpack_publicize'] = (boolean) pods_var( 'supports_jetpack_publicize', $post_type, false );
558
					$cpt_supported['supports_jetpack_markdown']  = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false );
559
				}
560
561
				$cpt_supports = array();
562
563
				foreach ( $cpt_supported as $cpt_support => $supported ) {
564
					if ( true === $supported ) {
565
						$cpt_supports[] = $cpt_support;
566
567
						if ( 'post-formats' === $cpt_support ) {
568
							$post_format_post_types[] = $post_type_name;
569
						}
570
					}
571
				}
572
573
				if ( empty( $cpt_supports ) ) {
574
					$cpt_supports = false;
575
				}
576
577
				// Rewrite
578
				$cpt_rewrite       = (boolean) pods_var( 'rewrite', $post_type, true );
579
				$cpt_rewrite_array = array(
580
					'slug'       => pods_var( 'rewrite_custom_slug', $post_type, str_replace( '_', '-', $post_type_name ), null, true ),
581
					'with_front' => (boolean) pods_var( 'rewrite_with_front', $post_type, true ),
582
					'feeds'      => (boolean) pods_var( 'rewrite_feeds', $post_type, (boolean) pods_var( 'has_archive', $post_type, false ) ),
583
					'pages'      => (boolean) pods_var( 'rewrite_pages', $post_type, true )
584
				);
585
586
				if ( false !== $cpt_rewrite ) {
587
					$cpt_rewrite = $cpt_rewrite_array;
588
				}
589
590
				$capability_type = pods_var( 'capability_type', $post_type, 'post' );
591
592
				if ( 'custom' == $capability_type ) {
593
					$capability_type = pods_var( 'capability_type_custom', $post_type, 'post' );
594
				}
595
596
				$show_in_menu = (boolean) pods_var( 'show_in_menu', $post_type, true );
597
598
				if ( $show_in_menu && 0 < strlen( pods_var_raw( 'menu_location_custom', $post_type ) ) ) {
599
					$show_in_menu = pods_var_raw( 'menu_location_custom', $post_type );
600
				}
601
602
				$menu_icon = pods_var( 'menu_icon', $post_type, null, null, true );
603
604
				if ( ! empty( $menu_icon ) ) {
605
					$menu_icon = pods_evaluate_tags( $menu_icon );
606
				}
607
608
				// Register Post Type
609
				$pods_post_types[ $post_type_name ] = array(
610
					'label'               => $cpt_label,
611
					'labels'              => $cpt_labels,
612
					'description'         => esc_html( pods_var_raw( 'description', $post_type ) ),
613
					'public'              => (boolean) pods_var( 'public', $post_type, true ),
614
					'publicly_queryable'  => (boolean) pods_var( 'publicly_queryable', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
615
					'exclude_from_search' => (boolean) pods_var( 'exclude_from_search', $post_type, ( (boolean) pods_var( 'public', $post_type, true ) ? false : true ) ),
616
					'show_ui'             => (boolean) pods_var( 'show_ui', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
617
					'show_in_menu'        => $show_in_menu,
618
					'show_in_nav_menus'   => (boolean) pods_var( 'show_in_nav_menus', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
619
					'show_in_admin_bar'   => (boolean) pods_var( 'show_in_admin_bar', $post_type, (boolean) pods_var( 'show_in_menu', $post_type, true ) ),
620
					'menu_position'       => (int) pods_var( 'menu_position', $post_type, 0, null, true ),
621
					'menu_icon'           => $menu_icon,
622
					'capability_type'     => $capability_type,
623
					//'capabilities' => $cpt_capabilities,
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
624
					'map_meta_cap'        => (boolean) pods_var( 'capability_type_extra', $post_type, true ),
625
					'hierarchical'        => (boolean) pods_var( 'hierarchical', $post_type, false ),
626
					'supports'            => $cpt_supports,
627
					//'register_meta_box_cb' => array($this, 'manage_meta_box'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
628
					//'permalink_epmask' => EP_PERMALINK,
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
629
					'has_archive'         => pods_v( 'has_archive_slug', $post_type, (boolean) pods_v( 'has_archive', $post_type, false ), true ),
630
					'rewrite'             => $cpt_rewrite,
631
					'query_var'           => ( false !== (boolean) pods_var( 'query_var', $post_type, true ) ? pods_var( 'query_var_string', $post_type, $post_type_name, null, true ) : false ),
632
					'can_export'          => (boolean) pods_var( 'can_export', $post_type, true )
633
				);
634
635
				// REST API
636
				$rest_enabled = (boolean) pods_v( 'rest_enable', $post_type, false );
637
638 View Code Duplication
				if ( $rest_enabled ) {
639
					$rest_base = sanitize_title( pods_v( 'rest_base', $post_type, $post_type_name ) );
640
641
					$pods_post_types[ $post_type_name ]['show_in_rest']          = true;
642
					$pods_post_types[ $post_type_name ]['rest_base']             = $rest_base;
643
					$pods_post_types[ $post_type_name ]['rest_controller_class'] = 'WP_REST_Posts_Controller';
644
				}
645
646
				// YARPP doesn't use 'supports' array option (yet)
647
				if ( ! empty( $cpt_supports['yarpp_support'] ) ) {
648
					$pods_post_types[ $post_type_name ]['yarpp_support'] = true;
649
				}
650
651
				// Prevent reserved query_var issues
652
				if ( in_array( $pods_post_types[ $post_type_name ]['query_var'], $reserved_query_vars ) ) {
653
					$pods_post_types[ $post_type_name ]['query_var'] = 'post_type_' . $pods_post_types[ $post_type_name ]['query_var'];
654
				}
655
656
				if ( 25 == $pods_post_types[ $post_type_name ]['menu_position'] ) {
657
					$pods_post_types[ $post_type_name ]['menu_position'] ++;
658
				}
659
660
				if ( $pods_post_types[ $post_type_name ]['menu_position'] < 1 || in_array( $pods_post_types[ $post_type_name ]['menu_position'], $cpt_positions ) ) {
661
					unset( $pods_post_types[ $post_type_name ]['menu_position'] );
662
				} else {
663
					$cpt_positions[] = $pods_post_types[ $post_type_name ]['menu_position'];
664
665
					// This would be nice if WP supported floats in menu_position
666
					// $pods_post_types[ $post_type_name ][ 'menu_position' ] = $pods_post_types[ $post_type_name ][ 'menu_position' ] . '.1';
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...
667
				}
668
669
				// Taxonomies
670
				$cpt_taxonomies = array();
671
				$_taxonomies    = get_taxonomies();
672
				$_taxonomies    = array_merge_recursive( $_taxonomies, $pods_taxonomies );
673
				$ignore         = array( 'nav_menu', 'link_category', 'post_format' );
674
675 View Code Duplication
				foreach ( $_taxonomies as $taxonomy => $label ) {
676
					if ( in_array( $taxonomy, $ignore ) ) {
677
						continue;
678
					}
679
680
					if ( false !== (boolean) pods_var( 'built_in_taxonomies_' . $taxonomy, $post_type, false ) ) {
681
						$cpt_taxonomies[] = $taxonomy;
682
683
						if ( isset( $supported_post_types[ $taxonomy ] ) && ! in_array( $post_type_name, $supported_post_types[ $taxonomy ] ) ) {
684
							$supported_post_types[ $taxonomy ][] = $post_type_name;
685
						}
686
					}
687
				}
688
689
				if ( isset( $supported_taxonomies[ $post_type_name ] ) ) {
690
					$supported_taxonomies[ $post_type_name ] = array_merge( (array) $supported_taxonomies[ $post_type_name ], $cpt_taxonomies );
691
				} else {
692
					$supported_taxonomies[ $post_type_name ] = $cpt_taxonomies;
693
				}
694
			}
695
696
			foreach ( $taxonomies as $taxonomy ) {
697 View Code Duplication
				if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) {
698
					// Taxonomy was setup already
699
					continue;
700
				} elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) {
701
					// Taxonomy exists already
702
703
					continue;
704
				} elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) {
705
					// Taxonomy was setup and exists already, but we aren't forcing it to be setup again
706
					continue;
707
				}
708
709
				$taxonomy['options']['name'] = $taxonomy['name'];
710
				$taxonomy                    = array_merge( $taxonomy, (array) $taxonomy['options'] );
711
712
				$taxonomy_name = pods_var( 'name', $taxonomy );
713
714
				// Labels
715
				$ct_label    = esc_html( pods_v( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'name', $taxonomy ) ) ), true ) );
716
				$ct_singular = esc_html( pods_v( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'label', $taxonomy, pods_v( 'name', $taxonomy ), null, true ) ) ), true ) );
717
718
				$ct_labels                               = array();
719
				$ct_labels['name']                       = $ct_label;
720
				$ct_labels['singular_name']              = $ct_singular;
721
				$ct_labels['menu_name']                  = pods_v( 'menu_name', $taxonomy, '', true );
722
				$ct_labels['search_items']               = pods_v( 'label_search_items', $taxonomy, '', true );
723
				$ct_labels['popular_items']              = pods_v( 'label_popular_items', $taxonomy, '', true );
724
				$ct_labels['all_items']                  = pods_v( 'label_all_items', $taxonomy, '', true );
725
				$ct_labels['parent_item']                = pods_v( 'label_parent_item', $taxonomy, '', true );
726
				$ct_labels['parent_item_colon']          = pods_v( 'label_parent_item_colon', $taxonomy, '', true );
727
				$ct_labels['edit_item']                  = pods_v( 'label_edit_item', $taxonomy, '', true );
728
				$ct_labels['update_item']                = pods_v( 'label_update_item', $taxonomy, '', true );
729
				$ct_labels['view_item']                  = pods_v( 'label_view_item', $taxonomy, '', true );
730
				$ct_labels['add_new_item']               = pods_v( 'label_add_new_item', $taxonomy, '', true );
731
				$ct_labels['new_item_name']              = pods_v( 'label_new_item_name', $taxonomy, '', true );
732
				$ct_labels['separate_items_with_commas'] = pods_v( 'label_separate_items_with_commas', $taxonomy, '', true );
733
				$ct_labels['add_or_remove_items']        = pods_v( 'label_add_or_remove_items', $taxonomy, '', true );
734
				$ct_labels['choose_from_most_used']      = pods_v( 'label_choose_from_the_most_used', $taxonomy, '', true );
735
				$ct_labels['not_found']                  = pods_v( 'label_not_found', $taxonomy, '', true );
736
				$ct_labels['no_terms']                   = pods_v( 'label_no_terms', $taxonomy, '', true );
737
				$ct_labels['items_list']                 = pods_v( 'label_items_list', $taxonomy, '', true );
738
				$ct_labels['items_list_navigation']      = pods_v( 'label_items_list_navigation', $taxonomy, '', true );
739
740
				// Rewrite
741
				$ct_rewrite       = (boolean) pods_var( 'rewrite', $taxonomy, true );
742
				$ct_rewrite_array = array(
743
					'slug'         => pods_var( 'rewrite_custom_slug', $taxonomy, str_replace( '_', '-', $taxonomy_name ), null, true ),
744
					'with_front'   => (boolean) pods_var( 'rewrite_with_front', $taxonomy, true ),
745
					'hierarchical' => (boolean) pods_var( 'rewrite_hierarchical', $taxonomy, (boolean) pods_var( 'hierarchical', $taxonomy, false ) )
746
				);
747
748
				if ( false !== $ct_rewrite ) {
749
					$ct_rewrite = $ct_rewrite_array;
750
				}
751
752
				/**
753
				 * Default tax capabilities
754
				 * @see https://codex.wordpress.org/Function_Reference/register_taxonomy
755
				 */
756
				$capability_type = pods_var( 'capability_type', $taxonomy, 'default' );
757
				$tax_capabilities = array();
758
759
				if ( 'custom' == $capability_type ) {
760
					$capability_type = pods_var( 'capability_type_custom', $taxonomy, 'default' );
761
					if ( ! empty( $capability_type ) && 'default' != $capability_type ) {
762
						$capability_type .=  '_term';
763
						$capability_type_plural =  $capability_type . 's';
764
						$tax_capabilities = array(
765
							// Singular
766
							'edit_term'   => 'edit_' . $capability_type,
767
							'delete_term' => 'delete_' . $capability_type,
768
							'assign_term' => 'assign_' . $capability_type,
769
							// Plural
770
							'manage_terms' => 'manage_' . $capability_type_plural,
771
							'edit_terms'   => 'edit_' . $capability_type_plural,
772
							'delete_terms' => 'delete_' . $capability_type_plural,
773
							'assign_terms' => 'assign_' . $capability_type_plural,
774
						);
775
					}
776
				}
777
778
				// Register Taxonomy
779
				$pods_taxonomies[ $taxonomy_name ] = array(
780
					'label'                 => $ct_label,
781
					'labels'                => $ct_labels,
782
					'public'                => (boolean) pods_var( 'public', $taxonomy, true ),
783
					'show_ui'               => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
784
					'show_in_menu'          => (boolean) pods_var( 'show_in_menu', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
785
					'show_in_nav_menus'     => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
786
					'show_tagcloud'         => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
787
					'show_tagcloud_in_edit' => (boolean) pods_var( 'show_tagcloud_in_edit', $taxonomy, (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ) ),
788
					'show_in_quick_edit'    => (boolean) pods_var( 'show_in_quick_edit', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
789
					'hierarchical'          => (boolean) pods_var( 'hierarchical', $taxonomy, false ),
790
					//'capability_type'       => $capability_type,
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
791
					'capabilities'          => $tax_capabilities,
792
					//'map_meta_cap'          => (boolean) pods_var( 'capability_type_extra', $taxonomy, true ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
793
					'update_count_callback' => pods_var( 'update_count_callback', $taxonomy, null, null, true ),
794
					'query_var'             => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ),
795
					'rewrite'               => $ct_rewrite,
796
					'show_admin_column'     => (boolean) pods_var( 'show_admin_column', $taxonomy, false ),
797
					'sort'                  => (boolean) pods_var( 'sort', $taxonomy, false ),
798
				);
799
800
				if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) {
801
					$pods_taxonomies[ $taxonomy_name ]['query_var'] = pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true );
802
				};
803
804
				// Prevent reserved query_var issues
805
				if ( in_array( $pods_taxonomies[ $taxonomy_name ]['query_var'], $reserved_query_vars ) ) {
806
					$pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var'];
807
				}
808
809
				// REST API
810
				$rest_enabled = (boolean) pods_v( 'rest_enable', $taxonomy, false );
811
812 View Code Duplication
				if ( $rest_enabled ) {
813
					$rest_base = sanitize_title( pods_v( 'rest_base', $taxonomy, $taxonomy_name ) );
814
815
					$pods_taxonomies[ $taxonomy_name ]['show_in_rest']          = true;
816
					$pods_taxonomies[ $taxonomy_name ]['rest_base']             = $rest_base;
817
					$pods_taxonomies[ $taxonomy_name ]['rest_controller_class'] = 'WP_REST_Terms_Controller';
818
				}
819
820
				// Integration for Single Value Taxonomy UI
821
				if ( function_exists( 'tax_single_value_meta_box' ) ) {
822
					$pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false );
823
					$pods_taxonomies[ $taxonomy_name ]['required']     = (boolean) pods_var( 'single_value_required', $taxonomy, false );
824
				}
825
826
				// Post Types
827
				$ct_post_types = array();
828
				$_post_types   = get_post_types();
829
				$_post_types   = array_merge_recursive( $_post_types, $pods_post_types );
830
				$ignore        = array( 'revision' );
831
832 View Code Duplication
				foreach ( $_post_types as $post_type => $options ) {
833
					if ( in_array( $post_type, $ignore ) ) {
834
						continue;
835
					}
836
837
					if ( false !== (boolean) pods_var( 'built_in_post_types_' . $post_type, $taxonomy, false ) ) {
838
						$ct_post_types[] = $post_type;
839
840
						if ( isset( $supported_taxonomies[ $post_type ] ) && ! in_array( $taxonomy_name, $supported_taxonomies[ $post_type ] ) ) {
841
							$supported_taxonomies[ $post_type ][] = $taxonomy_name;
842
						}
843
					}
844
				}
845
846
				if ( isset( $supported_post_types[ $taxonomy_name ] ) ) {
847
					$supported_post_types[ $taxonomy_name ] = array_merge( $supported_post_types[ $taxonomy_name ], $ct_post_types );
848
				} else {
849
					$supported_post_types[ $taxonomy_name ] = $ct_post_types;
850
				}
851
			}
852
853
			$pods_post_types = apply_filters( 'pods_wp_post_types', $pods_post_types );
854
			$pods_taxonomies = apply_filters( 'pods_wp_taxonomies', $pods_taxonomies );
855
856
			$supported_post_types = apply_filters( 'pods_wp_supported_post_types', $supported_post_types );
857
			$supported_taxonomies = apply_filters( 'pods_wp_supported_taxonomies', $supported_taxonomies );
858
859
			foreach ( $pods_taxonomies as $taxonomy => $options ) {
860
				$ct_post_types = null;
861
862
				if ( isset( $supported_post_types[ $taxonomy ] ) && ! empty( $supported_post_types[ $taxonomy ] ) ) {
863
					$ct_post_types = $supported_post_types[ $taxonomy ];
864
				}
865
866
				$pods_cpt_ct['taxonomies'][ $taxonomy ] = array(
867
					'post_types' => $ct_post_types,
868
					'options'    => $options
869
				);
870
			}
871
872
			foreach ( $pods_post_types as $post_type => $options ) {
873
				if ( isset( $supported_taxonomies[ $post_type ] ) && ! empty( $supported_taxonomies[ $post_type ] ) ) {
874
					$options['taxonomies'] = $supported_taxonomies[ $post_type ];
875
				}
876
877
				$pods_cpt_ct['post_types'][ $post_type ] = $options;
878
			}
879
880
			$pods_cpt_ct['post_format_post_types'] = $post_format_post_types;
881
882
			pods_transient_set( 'pods_wp_cpt_ct', $pods_cpt_ct );
883
		}
884
885
		foreach ( $pods_cpt_ct['taxonomies'] as $taxonomy => $options ) {
886
			if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy, self::$content_types_registered['taxonomies'] ) ) {
887
				continue;
888
			}
889
890
			$ct_post_types = $options['post_types'];
891
			$options       = $options['options'];
892
893
			$options = self::object_label_fix( $options, 'taxonomy' );
894
895
			/**
896
			 * Hide tagcloud compatibility
897
			 * @todo check https://core.trac.wordpress.org/ticket/36964
898
			 * @see wp-admin/edit-tags.php L389
899
			 */
900
			if ( true != (boolean) pods_var( 'show_tagcloud_in_edit', $options, (boolean) pods_var( 'show_tagcloud', $options, true ) ) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
901
				$options['labels']['popular_items'] = null;
902
			}
903
904
			// Max length for taxonomies are 32 characters
905
			$taxonomy = substr( $taxonomy, 0, 32 );
906
907
			// i18n compatibility for plugins that override it
908 View Code Duplication
			if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) {
909
				$options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' );
910
			}
911
912
			/**
913
			 * Allow filtering of taxonomy options per taxonomy.
914
			 *
915
			 * @param array  $options       Taxonomy options
916
			 * @param string $taxonomy      Taxonomy name
917
			 * @param array  $ct_post_types Associated Post Types
918
			 */
919
			$options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy, $ct_post_types );
920
921
			/**
922
			 * Allow filtering of taxonomy options.
923
			 *
924
			 * @param array  $options       Taxonomy options
925
			 * @param string $taxonomy      Taxonomy name
926
			 * @param array  $ct_post_types Associated post types
927
			 */
928
			$options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy, $ct_post_types );
929
930 View Code Duplication
			if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
931
				pods_debug( array( 'register_taxonomy', compact( 'taxonomy', 'ct_post_types', 'options' ) ) );
932
			}
933
934
			register_taxonomy( $taxonomy, $ct_post_types, $options );
935
936
			if ( ! empty( $options['show_in_rest'] ) ) {
937
				new PodsRESTFields( $taxonomy );
938
			}
939
940
			if ( ! isset( self::$content_types_registered['taxonomies'] ) ) {
941
				self::$content_types_registered['taxonomies'] = array();
942
			}
943
944
			self::$content_types_registered['taxonomies'][] = $taxonomy;
945
		}
946
947
		foreach ( $pods_cpt_ct['post_types'] as $post_type => $options ) {
948
			if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type, self::$content_types_registered['post_types'] ) ) {
949
				continue;
950
			}
951
952
			$options = self::object_label_fix( $options, 'post_type' );
953
954
			// Max length for post types are 20 characters
955
			$post_type = substr( $post_type, 0, 20 );
956
957
			// i18n compatibility for plugins that override it
958 View Code Duplication
			if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) {
959
				$options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' );
960
			}
961
962
			/**
963
			 * Allow filtering of post type options per post type.
964
			 *
965
			 * @param array  $options   Post type options
966
			 * @param string $post_type Post type name
967
			 */
968
			$options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type );
969
970
			/**
971
			 * Allow filtering of post type options.
972
			 *
973
			 * @param array  $options   Post type options
974
			 * @param string $post_type Post type name
975
			 */
976
			$options = apply_filters( 'pods_register_post_type', $options, $post_type );
977
978 View Code Duplication
			if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
979
				pods_debug( array( 'register_post_type', compact( 'post_type', 'options' ) ) );
980
			}
981
982
			register_post_type( $post_type, $options );
983
984
			// Register post format taxonomy for this post type
985
			if ( isset( $pods_cpt_ct['post_format_post_types'] ) && in_array( $post_type, $pods_cpt_ct['post_format_post_types'], true ) ) {
986
				register_taxonomy_for_object_type( 'post_format', $post_type );
987
			}
988
989
			if ( ! empty( $options['show_in_rest'] ) ) {
990
				new PodsRESTFields( $post_type );
991
			}
992
993
			if ( ! isset( self::$content_types_registered['post_types'] ) ) {
994
				self::$content_types_registered['post_types'] = array();
995
			}
996
997
			self::$content_types_registered['post_types'][] = $post_type;
998
		}
999
1000
		// Handle existing post types / taxonomies settings (just REST for now)
1001
		global $wp_post_types, $wp_taxonomies;
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...
1002
1003
		$post_type_names = wp_list_pluck( $post_types, 'name', 'id' );
1004
		$taxonomy_names = wp_list_pluck( $taxonomies, 'name', 'id' );
1005
1006 View Code Duplication
		foreach ( $existing_post_types as $post_type_name => $post_type_name_again ) {
1007
			if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type_name, self::$content_types_registered['post_types'] ) ) {
1008
				// Post type already registered / setup by Pods
1009
				continue;
1010
			}
1011
1012
			$pod_id = array_search( $post_type_name, $post_type_names, true );
1013
1014
			if ( ! $pod_id ) {
1015
				// Post type not a pod
1016
				continue;
1017
			}
1018
1019
			$pod = $post_types[ $pod_id ];
1020
1021
			// REST API
1022
			$rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1023
1024
			if ( $rest_enabled ) {
1025
				if ( empty( $wp_post_types[ $post_type_name ]->show_in_rest ) ) {
1026
					$rest_base = sanitize_title( pods_v( 'rest_base', $pod['options'], pods_v( 'rest_base', $wp_post_types[ $post_type_name ] ), true ) );
1027
1028
					$wp_post_types[ $post_type_name ]->show_in_rest          = true;
1029
					$wp_post_types[ $post_type_name ]->rest_base             = $rest_base;
1030
					$wp_post_types[ $post_type_name ]->rest_controller_class = 'WP_REST_Posts_Controller';
1031
				}
1032
1033
				new PodsRESTFields( $post_type_name );
1034
			}
1035
		}
1036
1037 View Code Duplication
		foreach ( $existing_taxonomies as $taxonomy_name => $taxonomy_name_again ) {
1038
			if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy_name, self::$content_types_registered['taxonomies'] ) ) {
1039
				// Taxonomy already registered / setup by Pods
1040
				continue;
1041
			}
1042
1043
			$pod_id = array_search( $taxonomy_name, $taxonomy_names, true );
1044
1045
			if ( ! $pod_id ) {
1046
				// Taxonomy not a pod
1047
				continue;
1048
			}
1049
1050
			$pod = $taxonomies[ $pod_id ];
1051
1052
			// REST API
1053
			$rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1054
1055
			if ( $rest_enabled ) {
1056
				if ( empty( $wp_taxonomies[ $taxonomy_name ]->show_in_rest ) ) {
1057
					$rest_base = sanitize_title( pods_v( 'rest_base', $pod['options'], pods_v( 'rest_base', $wp_taxonomies[ $taxonomy_name ] ), true ) );
1058
1059
					$wp_taxonomies[ $taxonomy_name ]->show_in_rest          = true;
1060
					$wp_taxonomies[ $taxonomy_name ]->rest_base             = $rest_base;
1061
					$wp_taxonomies[ $taxonomy_name ]->rest_controller_class = 'WP_REST_Terms_Controller';
1062
				}
1063
1064
				new PodsRESTFields( $taxonomy_name );
1065
			}
1066
		}
1067
1068 View Code Duplication
		if ( ! empty( PodsMeta::$user ) ) {
1069
			$pod = current( PodsMeta::$user );
1070
1071
			$rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1072
1073
			if ( $rest_enabled ) {
1074
				new PodsRESTFields( $pod['name'] );
1075
			}
1076
		}
1077
1078 View Code Duplication
		if ( ! empty( PodsMeta::$media ) ) {
1079
			$pod = current( PodsMeta::$media );
1080
1081
			$rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1082
1083
			if ( $rest_enabled ) {
1084
				new PodsRESTFields( $pod['name'] );
1085
			}
1086
		}
1087
1088
	}
1089
1090
	/**
1091
	 * Check if we need to flush WordPress rewrite rules
1092
	 * This gets run during 'init' action late in the game to give other plugins time to register their rewrite rules
1093
	 */
1094
	public function flush_rewrite_rules() {
1095
1096
		$flush = (int) pods_transient_get( 'pods_flush_rewrites' );
1097
1098
		if ( 1 === $flush ) {
1099
			/**
1100
			 * @var $wp_rewrite WP_Rewrite
1101
			 */
1102
			global $wp_rewrite;
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...
1103
			$wp_rewrite->flush_rules();
1104
			$wp_rewrite->init();
1105
1106
			pods_transient_set( 'pods_flush_rewrites', 0 );
1107
		}
1108
	}
1109
1110
	/**
1111
	 * Update Post Type messages
1112
	 *
1113
	 * @param array $messages
1114
	 *
1115
	 * @return array
1116
	 * @since 2.0.2
1117
	 */
1118
	public function setup_updated_messages( $messages ) {
1119
1120
		global $post, $post_ID;
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...
1121
1122
		$post_types          = PodsMeta::$post_types;
1123
		$existing_post_types = get_post_types();
1124
1125
		$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
1126
1127
		if ( empty( $pods_cpt_ct ) || empty( $post_types ) ) {
1128
			return $messages;
1129
		}
1130
1131
		/**
1132
		 * Use get_preview_post_link function added in 4.4, which eventually applies preview_post_link filter
1133
		 * Before 4.4, this filter is defined in wp-admin/includes/meta-boxes.php, $post parameter added in 4.0
1134
		 * there wasn't post parameter back in 3.8
1135
		 * Let's add $post in the filter as it won't hurt anyway.
1136
		 * @since 2.6.8.1
1137
		*/
1138
		$preview_post_link = function_exists( 'get_preview_post_link' )
1139
									? get_preview_post_link( $post )
1140
									: apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ), $post );
1141
1142
		foreach ( $post_types as $post_type ) {
1143
			if ( ! isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
1144
				continue;
1145
			}
1146
1147
			$labels = self::object_label_fix( $pods_cpt_ct['post_types'][ $post_type['name'] ], 'post_type' );
1148
			$labels = $labels['labels'];
1149
1150
			$messages[ $post_type['name'] ] = array(
1151
				1  => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ),
1152
				2  => __( 'Custom field updated.', 'pods' ),
1153
				3  => __( 'Custom field deleted.', 'pods' ),
1154
				4  => sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] ),
1155
				/* translators: %s: date and time of the revision */
1156
				5  => isset( $_GET['revision'] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels['singular_name'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
1157
				6  => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ),
1158
				7  => sprintf( __( '%s saved.', 'pods' ), $labels['singular_name'] ),
1159
				8  => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( $preview_post_link ), $labels['singular_name'] ),
1160
				9  => sprintf( __( '%s scheduled for: <strong>%s</strong>. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], // translators: Publish box date format, see http://php.net/date
1161
					date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $labels['singular_name'] ),
1162
				10 => sprintf( __( '%s draft updated. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( $preview_post_link ), $labels['singular_name'] )
1163
			);
1164
1165
			if ( false === (boolean) $pods_cpt_ct['post_types'][ $post_type['name'] ]['public'] ) {
1166
				$messages[ $post_type['name'] ][1]  = sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] );
1167
				$messages[ $post_type['name'] ][6]  = sprintf( __( '%s published.', 'pods' ), $labels['singular_name'] );
1168
				$messages[ $post_type['name'] ][8]  = sprintf( __( '%s submitted.', 'pods' ), $labels['singular_name'] );
1169
				$messages[ $post_type['name'] ][9]  = sprintf( __( '%s scheduled for: <strong>%1$s</strong>.', 'pods' ), $labels['singular_name'], // translators: Publish box date format, see http://php.net/date
1170
					date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) );
1171
				$messages[ $post_type['name'] ][10] = sprintf( __( '%s draft updated.', 'pods' ), $labels['singular_name'] );
1172
			}
1173
		}
1174
1175
		return $messages;
1176
	}
1177
1178
	/**
1179
	 * @param        $args
1180
	 * @param string $type
1181
	 *
1182
	 * @return array
1183
	 */
1184
	public static function object_label_fix( $args, $type = 'post_type' ) {
1185
1186
		if ( empty( $args ) || ! is_array( $args ) ) {
1187
			$args = array();
1188
		}
1189
1190
		if ( ! isset( $args['labels'] ) || ! is_array( $args['labels'] ) ) {
1191
			$args['labels'] = array();
1192
		}
1193
1194
		$label          = pods_v( 'name', $args['labels'], pods_v( 'label', $args, __( 'Items', 'pods' ), true ), true );
1195
		$singular_label = pods_v( 'singular_name', $args['labels'], pods_v( 'label_singular', $args, __( 'Item', 'pods' ), true ), true );
1196
1197
		$labels = $args['labels'];
1198
1199
		$labels['name']          = $label;
1200
		$labels['singular_name'] = $singular_label;
1201
1202
		if ( 'post_type' == $type ) {
1203
			$labels['menu_name']             = pods_v( 'menu_name', $labels, $label, true );
1204
			$labels['name_admin_bar']        = pods_v( 'name_admin_bar', $labels, $singular_label, true );
1205
			$labels['add_new']               = pods_v( 'add_new', $labels, __( 'Add New', 'pods' ), true );
1206
			$labels['add_new_item']          = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1207
			$labels['new_item']              = pods_v( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), true );
1208
			$labels['edit']                  = pods_v( 'edit', $labels, __( 'Edit', 'pods' ), true );
1209
			$labels['edit_item']             = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1210
			$labels['view']                  = pods_v( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1211
			$labels['view_item']             = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1212
			$labels['view_items']            = pods_v( 'view_items', $labels, sprintf( __( 'View %s', 'pods' ), $label ), true );
1213
			$labels['all_items']             = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1214
			$labels['search_items']          = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1215
			$labels['not_found']             = pods_v( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), true );
1216
			$labels['not_found_in_trash']    = pods_v( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), true );
1217
			$labels['parent']                = pods_v( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1218
			$labels['parent_item_colon']     = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), true );
1219
			$labels['featured_image']        = pods_v( 'featured_image', $labels, __( 'Featured Image', 'pods' ), true );
1220
			$labels['set_featured_image']    = pods_v( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), true );
1221
			$labels['remove_featured_image'] = pods_v( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), true );
1222
			$labels['use_featured_image']    = pods_v( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), true );
1223
			$labels['archives']              = pods_v( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), true );
1224
			$labels['attributes']            = pods_v( 'attributes', $labels, sprintf( __( '%s Attributes', 'pods' ), $singular_label ), true );
1225
			$labels['insert_into_item']      = pods_v( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), true );
1226
			$labels['uploaded_to_this_item'] = pods_v( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), true );
1227
			$labels['filter_items_list']     = pods_v( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), true );
1228
			$labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1229
			$labels['items_list']            = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1230
		} elseif ( 'taxonomy' == $type ) {
1231
			$labels['menu_name']                  = pods_v( 'menu_name', $labels, $label, true );
1232
			$labels['search_items']               = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1233
			$labels['popular_items']              = pods_v( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), true );
1234
			$labels['all_items']                  = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1235
			$labels['parent_item']                = pods_v( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1236
			$labels['parent_item_colon']          = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), true );
1237
			$labels['edit_item']                  = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1238
			$labels['view_item']                  = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1239
			$labels['update_item']                = pods_v( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), true );
1240
			$labels['add_new_item']               = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1241
			$labels['new_item_name']              = pods_v( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), true );
1242
			$labels['separate_items_with_commas'] = pods_v( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), true );
1243
			$labels['add_or_remove_items']        = pods_v( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), true );
1244
			$labels['choose_from_most_used']      = pods_v( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), true );
1245
			$labels['not_found']                  = pods_v( 'not_found', $labels, sprintf( __( 'No %s found.', 'pods' ), $label ), true );
1246
			$labels['no_terms']                   = pods_v( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), true );
1247
			$labels['items_list_navigation']      = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1248
			$labels['items_list']                 = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1249
		}
1250
1251
		$args['labels'] = $labels;
1252
1253
		return $args;
1254
	}
1255
1256
	/**
1257
	 * Activate and Install
1258
	 */
1259
	public function activate_install() {
1260
1261
		register_activation_hook( PODS_DIR . 'init.php', array( $this, 'activate' ) );
1262
		register_deactivation_hook( PODS_DIR . 'init.php', array( $this, 'deactivate' ) );
1263
1264
		add_action( 'wpmu_new_blog', array( $this, 'new_blog' ), 10, 6 );
1265
1266
		if ( empty( self::$version ) || version_compare( self::$version, PODS_VERSION, '<' ) || version_compare( self::$version, PODS_DB_VERSION, '<=' ) || self::$upgrade_needed ) {
1267
			$this->setup();
1268
		} elseif ( self::$version !== PODS_VERSION ) {
1269
			delete_option( 'pods_framework_version' );
1270
			add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
1271
1272
			self::$version = PODS_VERSION;
1273
1274
			pods_api()->cache_flush_pods();
1275
		}
1276
1277
	}
1278
1279
	/**
1280
	 *
1281
	 */
1282
	public function activate() {
1283
1284
		global $wpdb;
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...
1285
1286
		if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && 1 == $_GET['networkwide'] ) {
1287
			$_blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `{$wpdb->blogs}`" );
1288
1289
			foreach ( $_blog_ids as $_blog_id ) {
1290
				$this->setup( $_blog_id );
1291
			}
1292
		} else {
1293
			$this->setup();
1294
		}
1295
	}
1296
1297
	/**
1298
	 *
1299
	 */
1300
	public function deactivate() {
1301
1302
		pods_api()->cache_flush_pods();
1303
1304
	}
1305
1306
	/**
1307
	 *
1308
	 */
1309
	public function needs_upgrade( $current = null, $last = null ) {
1310
1311
		if ( null === $current ) {
1312
			$current = self::$version;
1313
		}
1314
1315
		if ( null === $last ) {
1316
			$last = self::$version_last;
1317
		}
1318
1319
		$upgrade_needed = false;
1320
1321
		if ( ! empty( $current ) ) {
1322
			foreach ( self::$upgrades as $old_version => $new_version ) {
1323
				/*if ( '2.1.0' == $new_version && ( is_developer() ) )
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
1324
					continue;*/
1325
1326
				if ( version_compare( $last, $old_version, '>=' ) && version_compare( $last, $new_version, '<' ) && version_compare( $current, $new_version, '>=' ) && 1 != self::$upgraded ) {
1327
					$upgrade_needed = true;
1328
1329
					break;
1330
				}
1331
			}
1332
		}
1333
1334
		return $upgrade_needed;
1335
	}
1336
1337
	/**
1338
	 * @param $_blog_id
1339
	 * @param $user_id
1340
	 * @param $domain
1341
	 * @param $path
1342
	 * @param $site_id
1343
	 * @param $meta
1344
	 */
1345
	public function new_blog( $_blog_id, $user_id, $domain, $path, $site_id, $meta ) {
1346
1347
		if ( function_exists( 'is_multisite' ) && is_multisite() && is_plugin_active_for_network( basename( PODS_DIR ) . '/init.php' ) ) {
1348
			$this->setup( $_blog_id );
1349
		}
1350
	}
1351
1352
	/**
1353
	 * @param null $_blog_id
1354
	 */
1355
	public function setup( $_blog_id = null ) {
1356
1357
		global $wpdb;
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...
1358
1359
		// Switch DB table prefixes
1360 View Code Duplication
		if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) {
1361
			switch_to_blog( pods_absint( $_blog_id ) );
1362
		} else {
1363
			$_blog_id = null;
1364
		}
1365
1366
		// Setup DB tables
1367
		$pods_version      = get_option( 'pods_framework_version' );
1368
		$pods_version_last = get_option( 'pods_framework_version_last' );
1369
1370
		// Install Pods
1371
		if ( empty( $pods_version ) ) {
1372
			pods_upgrade()->install( $_blog_id );
1373
1374
			$old_version = get_option( 'pods_version' );
1375
1376
			if ( ! empty( $old_version ) ) {
1377
				if ( false === strpos( $old_version, '.' ) ) {
1378
					$old_version = pods_version_to_point( $old_version );
1379
				}
1380
1381
				delete_option( 'pods_framework_version_last' );
1382
				add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
1383
1384
				self::$version_last = $old_version;
1385
			}
1386
		} // Upgrade Wizard needed
1387
		elseif ( $this->needs_upgrade( $pods_version, $pods_version_last ) ) {
1388
			// Do not do anything
1389
			return;
1390
		} // Update Pods and run any required DB updates
1391
		elseif ( version_compare( $pods_version, PODS_VERSION, '<=' ) ) {
1392
			if ( false !== apply_filters( 'pods_update_run', null, PODS_VERSION, $pods_version, $_blog_id ) && ! isset( $_GET['pods_bypass_update'] ) ) {
1393
				do_action( 'pods_update', PODS_VERSION, $pods_version, $_blog_id );
1394
1395
				// Update 2.0 alpha / beta sites
1396
				if ( version_compare( '2.0.0-a-1', $pods_version, '<=' ) && version_compare( $pods_version, '2.0.0-b-15', '<=' ) ) {
1397
					include( PODS_DIR . 'sql/update-2.0-beta.php' );
1398
				}
1399
1400
				if ( version_compare( $pods_version, PODS_DB_VERSION, '<=' ) ) {
1401
					include( PODS_DIR . 'sql/update.php' );
1402
				}
1403
1404
				do_action( 'pods_update_post', PODS_VERSION, $pods_version, $_blog_id );
1405
			}
1406
1407
			delete_option( 'pods_framework_version_last' );
1408
			add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
1409
1410
			self::$version_last = $pods_version;
1411
		}
1412
1413
		delete_option( 'pods_framework_version' );
1414
		add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
1415
1416
		delete_option( 'pods_framework_db_version' );
1417
		add_option( 'pods_framework_db_version', PODS_DB_VERSION, '', 'yes' );
1418
1419
		self::$version = PODS_VERSION;
1420
		self::$db_version = PODS_DB_VERSION;
1421
1422
		pods_api()->cache_flush_pods();
1423
1424
		// Restore DB table prefix (if switched)
1425
		if ( null !== $_blog_id ) {
1426
			restore_current_blog();
1427
		}
1428
1429
	}
1430
1431
	/**
1432
	 * @param null $_blog_id
1433
	 */
1434
	public function reset( $_blog_id = null ) {
1435
1436
		global $wpdb;
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...
1437
1438
		// Switch DB table prefixes
1439 View Code Duplication
		if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) {
1440
			switch_to_blog( pods_absint( $_blog_id ) );
1441
		} else {
1442
			$_blog_id = null;
1443
		}
1444
1445
		$api = pods_api();
1446
1447
		$pods = $api->load_pods( array( 'names_ids' => true, 'table_info' => false ) );
1448
1449
		foreach ( $pods as $pod_id => $pod_label ) {
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...
1450
			$api->delete_pod( array( 'id' => $pod_id ) );
1451
		}
1452
1453
		$templates = $api->load_templates();
1454
1455
		foreach ( $templates as $template ) {
1456
			$api->delete_template( array( 'id' => $template['id'] ) );
1457
		}
1458
1459
		$pages = $api->load_pages();
1460
1461
		foreach ( $pages as $page ) {
1462
			$api->delete_page( array( 'id' => $page['id'] ) );
1463
		}
1464
1465
		$helpers = $api->load_helpers();
1466
1467
		foreach ( $helpers as $helper ) {
1468
			$api->delete_helper( array( 'id' => $helper['id'] ) );
1469
		}
1470
1471
		$tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pods%'", ARRAY_N );
1472
1473
		if ( ! empty( $tables ) ) {
1474
			foreach ( $tables as $table ) {
1475
				$table = $table[0];
1476
1477
				pods_query( "DROP TABLE `{$table}`", false );
1478
			}
1479
		}
1480
1481
		// Remove any orphans
1482
		$wpdb->query( "
1483
                DELETE `p`, `pm`
1484
                FROM `{$wpdb->posts}` AS `p`
1485
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1486
                    ON `pm`.`post_id` = `p`.`ID`
1487
                WHERE
1488
                    `p`.`post_type` LIKE '_pods_%'
1489
            " );
1490
1491
		delete_option( 'pods_framework_version' );
1492
		delete_option( 'pods_framework_db_version' );
1493
		delete_option( 'pods_framework_upgrade_2_0' );
1494
		delete_option( 'pods_framework_upgraded_1_x' );
1495
1496
		// @todo Make sure all entries are being cleaned and do something about the pods_framework_upgrade_{version} dynamic entries created by PodsUpgrade
1497
		delete_option( 'pods_framework_upgrade_2_0_0' );
1498
		delete_option( 'pods_framework_upgrade_2_0_sister_ids' );
1499
		delete_option( 'pods_framework_version_last' );
1500
1501
		delete_option( 'pods_component_settings' );
1502
1503
		$api->cache_flush_pods();
1504
1505
		pods_transient_clear( 'pods_flush_rewrites' );
1506
1507
		self::$version = '';
1508
1509
		// Restore DB table prefix (if switched)
1510
		if ( null !== $_blog_id ) {
1511
			restore_current_blog();
1512
		}
1513
	}
1514
1515
	public function run() {
1516
1517
		static $ran;
1518
1519
		if ( ! empty( $ran ) ) {
1520
			return;
1521
		}
1522
1523
		$ran = true;
1524
1525
		$this->load_i18n();
1526
1527
		if ( ! did_action( 'plugins_loaded' ) ) {
1528
			add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 );
1529
		} else {
1530
			$this->load_components();
1531
		}
1532
1533
		if ( ! did_action( 'setup_theme' ) ) {
1534
			add_action( 'setup_theme', array( $this, 'load_meta' ), 14 );
1535
		} else {
1536
			$this->load_meta();
1537
		}
1538
1539
		if ( ! did_action( 'init' ) ) {
1540
			add_action( 'init', array( $this, 'core' ), 11 );
1541
			add_action( 'init', array( $this, 'setup_content_types' ), 11 );
1542
1543
			if ( is_admin() ) {
1544
				add_action( 'init', array( $this, 'admin_init' ), 12 );
1545
			}
1546
		} else {
1547
			$this->core();
1548
			$this->setup_content_types();
1549
1550
			if ( is_admin() ) {
1551
				$this->admin_init();
1552
			}
1553
		}
1554
1555
		add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1556
		add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1557
		add_action( 'login_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1558
1559
		add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
1560
		add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
1561
1562
		// Register widgets
1563
		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
1564
1565
		// Show admin bar links
1566
		add_action( 'admin_bar_menu', array( $this, 'admin_bar_links' ), 81 );
1567
1568
	}
1569
1570
	/**
1571
	 * Delete Attachments from relationships
1572
	 *
1573
	 * @param int $_ID
1574
	 */
1575
	public function delete_attachment( $_ID ) {
1576
1577
		global $wpdb;
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...
1578
1579
		$_ID = (int) $_ID;
1580
1581
		do_action( 'pods_delete_attachment', $_ID );
1582
1583
		$file_types = "'" . implode( "', '", PodsForm::file_field_types() ) . "'";
1584
1585
		if ( ! pods_tableless() ) {
1586
			$sql = "
1587
                DELETE `rel`
1588
                FROM `@wp_podsrel` AS `rel`
1589
                LEFT JOIN `{$wpdb->posts}` AS `p`
1590
                    ON
1591
                        `p`.`post_type` = '_pods_field'
1592
                        AND ( `p`.`ID` = `rel`.`field_id` OR `p`.`ID` = `rel`.`related_field_id` )
1593
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1594
                    ON
1595
                        `pm`.`post_id` = `p`.`ID`
1596
                        AND `pm`.`meta_key` = 'type'
1597
                        AND `pm`.`meta_value` IN ( {$file_types} )
1598
                WHERE
1599
                    `p`.`ID` IS NOT NULL
1600
                    AND `pm`.`meta_id` IS NOT NULL
1601
                    AND `rel`.`item_id` = {$_ID}";
1602
1603
			pods_query( $sql, false );
1604
		}
1605
1606
		// Post Meta
1607 View Code Duplication
		if ( ! empty( PodsMeta::$post_types ) ) {
1608
			$sql = "
1609
                DELETE `rel`
1610
                FROM `@wp_postmeta` AS `rel`
1611
                LEFT JOIN `{$wpdb->posts}` AS `p`
1612
                    ON
1613
                        `p`.`post_type` = '_pods_field'
1614
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1615
                    ON
1616
                        `pm`.`post_id` = `p`.`ID`
1617
                        AND `pm`.`meta_key` = 'type'
1618
                        AND `pm`.`meta_value` IN ( {$file_types} )
1619
                WHERE
1620
                    `p`.`ID` IS NOT NULL
1621
                    AND `pm`.`meta_id` IS NOT NULL
1622
                    AND `rel`.`meta_key` = `p`.`post_name`
1623
                    AND `rel`.`meta_value` = '{$_ID}'";
1624
1625
			pods_query( $sql, false );
1626
		}
1627
1628
		// User Meta
1629 View Code Duplication
		if ( ! empty( PodsMeta::$user ) ) {
1630
			$sql = "
1631
                DELETE `rel`
1632
                FROM `@wp_usermeta` AS `rel`
1633
                LEFT JOIN `{$wpdb->posts}` AS `p`
1634
                    ON
1635
                        `p`.`post_type` = '_pods_field'
1636
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1637
                    ON
1638
                        `pm`.`post_id` = `p`.`ID`
1639
                        AND `pm`.`meta_key` = 'type'
1640
                        AND `pm`.`meta_value` IN ( {$file_types} )
1641
                WHERE
1642
                    `p`.`ID` IS NOT NULL
1643
                    AND `pm`.`meta_id` IS NOT NULL
1644
                    AND `rel`.`meta_key` = `p`.`post_name`
1645
                    AND `rel`.`meta_value` = '{$_ID}'";
1646
1647
			pods_query( $sql, false );
1648
		}
1649
1650
		// Comment Meta
1651 View Code Duplication
		if ( ! empty( PodsMeta::$comment ) ) {
1652
			$sql = "
1653
                DELETE `rel`
1654
                FROM `@wp_commentmeta` AS `rel`
1655
                LEFT JOIN `{$wpdb->posts}` AS `p`
1656
                    ON
1657
                        `p`.`post_type` = '_pods_field'
1658
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1659
                    ON
1660
                        `pm`.`post_id` = `p`.`ID`
1661
                        AND `pm`.`meta_key` = 'type'
1662
                        AND `pm`.`meta_value` IN ( {$file_types} )
1663
                WHERE
1664
                    `p`.`ID` IS NOT NULL
1665
                    AND `pm`.`meta_id` IS NOT NULL
1666
                    AND `rel`.`meta_key` = `p`.`post_name`
1667
                    AND `rel`.`meta_value` = '{$_ID}'";
1668
1669
			pods_query( $sql, false );
1670
		}
1671
	}
1672
1673
	/**
1674
	 * Register widgets for Pods
1675
	 */
1676
	public function register_widgets() {
1677
1678
		$widgets = array(
1679
			'PodsWidgetSingle',
1680
			'PodsWidgetList',
1681
			'PodsWidgetField',
1682
			'PodsWidgetForm',
1683
			'PodsWidgetView'
1684
		);
1685
1686
		foreach ( $widgets as $widget ) {
1687
			if ( ! file_exists( PODS_DIR . 'classes/widgets/' . $widget . '.php' ) ) {
1688
				continue;
1689
			}
1690
1691
			require_once PODS_DIR . 'classes/widgets/' . $widget . '.php';
1692
1693
			register_widget( $widget );
1694
		}
1695
	}
1696
1697
	/**
1698
	 * Add Admin Bar links
1699
	 */
1700
	public function admin_bar_links() {
1701
1702
		global $wp_admin_bar, $pods;
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...
1703
1704
		if ( ! is_user_logged_in() || ! is_admin_bar_showing() ) {
1705
			return;
1706
		}
1707
1708
		$all_pods = pods_api()->load_pods( array( 'type' => 'pod', 'fields' => false, 'table_info' => false ) );
1709
1710
		// Add New item links for all pods
1711
		foreach ( $all_pods as $pod ) {
0 ignored issues
show
Bug introduced by
The expression $all_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...
1712
			if ( 0 == $pod['options']['show_in_menu'] ) {
1713
				continue;
1714
			}
1715
1716
			if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod['name'] ) ) ) {
1717
				continue;
1718
			}
1719
1720
			$singular_label = pods_var_raw( 'label_singular', $pod['options'], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), null, true ), null, true );
1721
1722
			$wp_admin_bar->add_node( array(
1723
				'id'     => 'new-pod-' . $pod['name'],
1724
				'title'  => $singular_label,
1725
				'parent' => 'new-content',
1726
				'href'   => admin_url( 'admin.php?page=pods-manage-' . $pod['name'] . '&action=add' )
1727
			) );
1728
		}
1729
1730
		// Add edit link if we're on a pods page
1731
		if ( is_object( $pods ) && ! is_wp_error( $pods ) && ! empty( $pods->id ) && isset( $pods->pod_data ) && ! empty( $pods->pod_data ) && 'pod' == $pods->pod_data['type'] ) {
1732
			$pod = $pods->pod_data;
1733
1734
			if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
1735
				$singular_label = pods_var_raw( 'label_singular', $pod['options'], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), null, true ), null, true );
1736
1737
				$wp_admin_bar->add_node( array(
1738
					'title' => sprintf( __( 'Edit %s', 'pods' ), $singular_label ),
1739
					'id'    => 'edit-pod',
1740
					'href'  => admin_url( 'admin.php?page=pods-manage-' . $pod['name'] . '&action=edit&id=' . $pods->id() )
1741
				) );
1742
			}
1743
		}
1744
1745
	}
1746
1747
	/**
1748
	 * Add REST API support to post type and taxonomy objects.
1749
	 *
1750
	 * @uses  "init"
1751
	 *
1752
	 * @since 2.5.6
1753
	 */
1754
	public function add_rest_support() {
1755
1756
		if ( empty( self::$version ) ) {
1757
			return;
1758
		}
1759
1760
		static $rest_support_added;
1761
1762
		if ( ! function_exists( 'register_rest_field' ) ) {
1763
			return;
1764
		}
1765
1766
		include_once( PODS_DIR . 'classes/rest/PodsRESTFields.php' );
1767
		include_once( PODS_DIR . 'classes/rest/PodsRESTHandlers.php' );
1768
1769
		$rest_bases = pods_transient_get( 'pods_rest_bases' );
1770
1771
		if ( empty( $rest_bases ) ) {
1772
	        $pods = pods_api()->load_pods( array( 'type' => array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ), 'fields' => false, 'table_info' => false ) );
1773
1774
			$rest_bases = array();
1775
1776
			if ( ! empty( $pods ) && is_array( $pods ) ) {
1777
				foreach ( $pods as $pod ) {
1778
					$type = $pod['type'];
1779
1780
					if ( in_array( $type, array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ) ) ) {
1781
						if ( $pod && PodsRESTHandlers::pod_extends_core_route( $pod ) ) {
0 ignored issues
show
Bug introduced by
The method pod_extends_core_route() does not seem to exist on object<PodsRESTHandlers>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1782
							$rest_bases[ $pod['name'] ] = array(
1783
								'type' => $type,
1784
								'base' => sanitize_title( pods_v( 'rest_base', $pod['options'], $pod['name'] ) ),
1785
							);
1786
						}
1787
					}
1788
				}
1789
			}
1790
1791
			if ( empty( $rest_bases ) ) {
1792
				$rest_bases = 'none';
1793
			}
1794
1795
			pods_transient_set( 'pods_rest_bases', $rest_bases );
1796
		}
1797
1798
		if ( empty( $rest_support_added ) && ! empty( $rest_bases ) && 'none' !== $rest_bases ) {
1799
			foreach ( $rest_bases as $pod_name => $pod_info ) {
1800
				$pod_type  = $pod_info['type'];
1801
				$rest_base = $pod_info['base'];
1802
1803
				if ( 'post_type' == $pod_type ) {
1804
					PodsRESTHandlers::post_type_rest_support( $pod_name, $rest_base );
0 ignored issues
show
Bug introduced by
The method post_type_rest_support() does not seem to exist on object<PodsRESTHandlers>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1805
				} elseif ( 'taxonomy' == $pod_type ) {
1806
					PodsRESTHandlers::taxonomy_rest_support( $pod_name, $rest_base );
0 ignored issues
show
Bug introduced by
The method taxonomy_rest_support() does not seem to exist on object<PodsRESTHandlers>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1807
				}
1808
1809
				new PodsRESTFields( $pod_name );
1810
			}
1811
1812
			$rest_support_added = true;
1813
		}
1814
1815
	}
1816
}
1817