Completed
Push — 2.x ( 971a6c...befcfa )
by Scott Kingsley
08:24 queued 03:02
created

PodsInit::object_label_fix()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 71
Code Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 59
nc 12
nop 2
dl 0
loc 71
rs 6.7968
c 0
b 0
f 0

How to fix   Long Method   

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
		if ( ! wp_style_is( 'jquery-ui', 'registered' ) ) {
255
			wp_register_style( 'jquery-ui', PODS_URL . 'ui/css/smoothness/jquery-ui.custom.css', array(), '1.8.16' );
256
		}
257
258
		wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' );
259
260
		if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) {
261
			wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' );
262
		}
263
264
		if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) {
265
			wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' );
266
		}
267
268
		wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array(
269
			'jquery',
270
			'pods-dfv',
271
			'pods-i18n',
272
			'pods-json',
273
			'jquery-qtip2'
274
		), PODS_VERSION, true );
275
276
		wp_register_style( 'pods-form', PODS_URL . 'ui/css/pods-form.css', array(), PODS_VERSION );
277
278
		wp_register_style( 'pods-cleditor', PODS_URL . 'ui/css/jquery.cleditor.css', array(), '1.3.0' );
279
		wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' );
280
281
		wp_register_style( 'pods-codemirror', PODS_URL . 'ui/css/codemirror.css', array(), '4.8' );
282
		wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '4.8', true );
283
		wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/addon/mode/loadmode.js', array( 'pods-codemirror' ), '4.8', true );
284
		wp_register_script( 'pods-codemirror-overlay', PODS_URL . 'ui/js/codemirror/addon/mode/overlay.js', array( 'pods-codemirror' ), '4.8', true );
285
		wp_register_script( 'pods-codemirror-hints', PODS_URL . 'ui/js/codemirror/addon/mode/show-hint.js', array( 'pods-codemirror' ), '4.8', true );
286
		wp_register_script( 'pods-codemirror-mode-xml', PODS_URL . 'ui/js/codemirror/mode/xml/xml.js', array( 'pods-codemirror' ), '4.8', true );
287
		wp_register_script( 'pods-codemirror-mode-html', PODS_URL . 'ui/js/codemirror/mode/htmlmixed/htmlmixed.js', array( 'pods-codemirror' ), '4.8', true );
288
		wp_register_script( 'pods-codemirror-mode-css', PODS_URL . 'ui/js/codemirror/mode/css/css.js', array( 'pods-codemirror' ), '4.8', true );
289
290
		if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) {
291
			wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/css/jquery.ui.timepicker.css', array(), '1.1.1' );
292
		}
293
294
		if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) {
295
			wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/jquery.ui.timepicker.min.js', array(
296
				'jquery',
297
				'jquery-ui-core',
298
				'jquery-ui-datepicker',
299
				'jquery-ui-slider'
300
			), '1.1.1' );
301
		}
302
303
		wp_register_style( 'pods-select2', PODS_URL . 'ui/js/select2/select2.min.css', array(), '4.0.3' );
304
		wp_register_script( 'pods-select2', PODS_URL . 'ui/js/select2/select2.min.js', array( 'jquery', 'pods-i18n' ), '4.0.3' );
305
306
		wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' );
307
308
		// Marionette dependencies for MV fields
309
		wp_register_script( 'backbone.radio', PODS_URL . 'ui/js/marionette/backbone.radio.js', array( 'backbone' ), '2.0.0', true );
310
		wp_register_script( 'marionette', PODS_URL . 'ui/js/marionette/backbone.marionette.js', array( 'backbone', 'backbone.radio' ), '3.1.0', true );
311
312
		// MV stuff
313
		wp_register_script(
314
			'pods-dfv',
315
			PODS_URL . 'ui/js/pods-dfv/pods-dfv.min.js',
316
			array(
317
				'jquery',
318
				'jquery-ui-core',
319
				'jquery-ui-sortable',
320
				'pods-i18n',
321
				'marionette',
322
				'media-views',
323
				'media-models'
324
			),
325
			PODS_VERSION,
326
			true
327
		);
328
		wp_register_style( 'pods-dfv-list', PODS_URL . 'ui/css/pods-dfv-list.css', array(), PODS_VERSION );
329
	}
330
331
	/**
332
	 * Register internal Post Types
333
	 */
334
	public function register_pods() {
335
336
		$args = array(
337
			'label'           => 'Pods',
338
			'labels'          => array( 'singular_name' => 'Pod' ),
339
			'public'          => false,
340
			'can_export'      => false,
341
			'query_var'       => false,
342
			'rewrite'         => false,
343
			'capability_type' => 'pods_pod',
344
			'has_archive'     => false,
345
			'hierarchical'    => false,
346
			'supports'        => array( 'title', 'author' ),
347
			'menu_icon'       => 'dashicons-pods'
348
		);
349
350
		$args = self::object_label_fix( $args, 'post_type' );
351
352
		register_post_type( '_pods_pod', apply_filters( 'pods_internal_register_post_type_pod', $args ) );
353
354
		$args = array(
355
			'label'           => 'Pod Fields',
356
			'labels'          => array( 'singular_name' => 'Pod Field' ),
357
			'public'          => false,
358
			'can_export'      => false,
359
			'query_var'       => false,
360
			'rewrite'         => false,
361
			'capability_type' => 'pods_pod',
362
			'has_archive'     => false,
363
			'hierarchical'    => true,
364
			'supports'        => array( 'title', 'editor', 'author' ),
365
			'menu_icon'       => 'dashicons-pods'
366
		);
367
368
		$args = self::object_label_fix( $args, 'post_type' );
369
370
		register_post_type( '_pods_field', apply_filters( 'pods_internal_register_post_type_field', $args ) );
371
	}
372
373
	/**
374
	 * Include Admin
375
	 */
376
	public function admin_init() {
377
378
		self::$admin = pods_admin();
379
	}
380
381
	/**
382
	 * Register Post Types and Taxonomies
383
	 */
384
	public function setup_content_types( $force = false ) {
385
386
		if ( empty( self::$version ) ) {
387
			return;
388
		}
389
390
		$post_types = PodsMeta::$post_types;
391
		$taxonomies = PodsMeta::$taxonomies;
392
393
		$existing_post_types = get_post_types();
394
		$existing_taxonomies = get_taxonomies();
395
396
		$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
397
398
		$cpt_positions = array();
399
400
		if ( empty( $pods_cpt_ct ) && ( ! empty( $post_types ) || ! empty( $taxonomies ) ) ) {
401
			$force = true;
402
		} elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['post_types'] ) && ! empty( $post_types ) ) {
403
			$force = true;
404
		} elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['taxonomies'] ) && ! empty( $taxonomies ) ) {
405
			$force = true;
406
		}
407
408
		if ( false === $pods_cpt_ct || $force ) {
409
			/**
410
			 * @var WP_Query
411
			 */
412
			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...
413
414
			$reserved_query_vars = array(
415
				'post_type',
416
				'taxonomy',
417
				'output'
418
			);
419
420
			if ( is_object( $wp_query ) ) {
421
				$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
422
			}
423
424
			$pods_cpt_ct = array(
425
				'post_types' => array(),
426
				'taxonomies' => array()
427
			);
428
429
			$pods_post_types      = $pods_taxonomies = array();
430
			$supported_post_types = $supported_taxonomies = array();
431
432
			foreach ( $post_types as $post_type ) {
433
				// Post Type exists already
434 View Code Duplication
				if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
435
					continue;
436
				} elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) {
437
					continue;
438
				} elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) {
439
					continue;
440
				}
441
442
				$post_type['options']['name'] = $post_type['name'];
443
				$post_type                    = array_merge( $post_type, (array) $post_type['options'] );
444
445
				$post_type_name = pods_v_sanitized( 'name', $post_type );
446
447
				// Labels
448
				$cpt_label    = esc_html( pods_v( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'name', $post_type ) ) ), true ) );
449
				$cpt_singular = esc_html( pods_v( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'label', $post_type, $post_type_name, null, true ) ) ), true ) );
450
451
				$cpt_labels                          = array();
452
				$cpt_labels['name']                  = $cpt_label;
453
				$cpt_labels['singular_name']         = $cpt_singular;
454
				$cpt_labels['menu_name']             = pods_v( 'menu_name', $post_type, '', true );
455
				$cpt_labels['name_admin_bar']        = pods_v( 'name_admin_bar', $post_type, '', true );
456
				$cpt_labels['add_new']               = pods_v( 'label_add_new', $post_type, '', true );
457
				$cpt_labels['add_new_item']          = pods_v( 'label_add_new_item', $post_type, '', true );
458
				$cpt_labels['new_item']              = pods_v( 'label_new_item', $post_type, '', true );
459
				$cpt_labels['edit']                  = pods_v( 'label_edit', $post_type, '', true );
460
				$cpt_labels['edit_item']             = pods_v( 'label_edit_item', $post_type, '', true );
461
				$cpt_labels['view']                  = pods_v( 'label_view', $post_type, '', true );
462
				$cpt_labels['view_item']             = pods_v( 'label_view_item', $post_type, '', true );
463
				$cpt_labels['view_items']            = pods_v( 'label_view_items', $post_type, '', true );
464
				$cpt_labels['all_items']             = pods_v( 'label_all_items', $post_type, '', true );
465
				$cpt_labels['search_items']          = pods_v( 'label_search_items', $post_type, '', true );
466
				$cpt_labels['not_found']             = pods_v( 'label_not_found', $post_type, '', true );
467
				$cpt_labels['not_found_in_trash']    = pods_v( 'label_not_found_in_trash', $post_type, '', true );
468
				$cpt_labels['parent']                = pods_v( 'label_parent', $post_type, '', true );
469
				$cpt_labels['parent_item_colon']     = pods_v( 'label_parent_item_colon', $post_type, '', true );
470
				$cpt_labels['archives']              = pods_v( 'label_archives', $post_type, '', true );
471
				$cpt_labels['attributes']            = pods_v( 'label_attributes', $post_type, '', true );
472
				$cpt_labels['insert_into_item']      = pods_v( 'label_insert_into_item', $post_type, '', true );
473
				$cpt_labels['uploaded_to_this_item'] = pods_v( 'label_uploaded_to_this_item', $post_type, '', true );
474
				$cpt_labels['featured_image']        = pods_v( 'label_featured_image', $post_type, '', true );
475
				$cpt_labels['set_featured_image']    = pods_v( 'label_set_featured_image', $post_type, '', true );
476
				$cpt_labels['remove_featured_image'] = pods_v( 'label_remove_featured_image', $post_type, '', true );
477
				$cpt_labels['use_featured_image']    = pods_v( 'label_use_featured_image', $post_type, '', true );
478
				$cpt_labels['filter_items_list']     = pods_v( 'label_filter_items_list', $post_type, '', true );
479
				$cpt_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $post_type, '', true );
480
				$cpt_labels['items_list']            = pods_v( 'label_items_list', $post_type, '', true );
481
482
				// Supported
483
				$cpt_supported = array(
484
					'title'           => (boolean) pods_v( 'supports_title', $post_type, false ),
485
					'editor'          => (boolean) pods_v( 'supports_editor', $post_type, false ),
486
					'author'          => (boolean) pods_v( 'supports_author', $post_type, false ),
487
					'thumbnail'       => (boolean) pods_v( 'supports_thumbnail', $post_type, false ),
488
					'excerpt'         => (boolean) pods_v( 'supports_excerpt', $post_type, false ),
489
					'trackbacks'      => (boolean) pods_v( 'supports_trackbacks', $post_type, false ),
490
					'custom-fields'   => (boolean) pods_v( 'supports_custom_fields', $post_type, false ),
491
					'comments'        => (boolean) pods_v( 'supports_comments', $post_type, false ),
492
					'revisions'       => (boolean) pods_v( 'supports_revisions', $post_type, false ),
493
					'page-attributes' => (boolean) pods_v( 'supports_page_attributes', $post_type, false ),
494
					'post-formats'    => (boolean) pods_v( 'supports_post_formats', $post_type, false )
495
				);
496
497
				// Custom Supported
498
				$cpt_supported_custom = pods_v_sanitized( 'supports_custom', $post_type, '' );
499
500
				if ( ! empty( $cpt_supported_custom ) ) {
501
					$cpt_supported_custom = explode( ',', $cpt_supported_custom );
502
					$cpt_supported_custom = array_filter( array_unique( $cpt_supported_custom ) );
503
504
					foreach ( $cpt_supported_custom as $cpt_support ) {
505
						$cpt_supported[ $cpt_support ] = true;
506
					}
507
				}
508
509
				// Genesis Support
510
				if ( function_exists( 'genesis' ) ) {
511
					$cpt_supported['genesis-seo']             = (boolean) pods_var( 'supports_genesis_seo', $post_type, false );
512
					$cpt_supported['genesis-layouts']         = (boolean) pods_var( 'supports_genesis_layouts', $post_type, false );
513
					$cpt_supported['genesis-simple-sidebars'] = (boolean) pods_var( 'supports_genesis_simple_sidebars', $post_type, false );
514
				}
515
516
				// YARPP Support
517
				if ( defined( 'YARPP_VERSION' ) ) {
518
					$cpt_supported['yarpp_support'] = (boolean) pods_var( 'supports_yarpp_support', $post_type, false );
519
				}
520
521
				// Jetpack Support
522
				if ( class_exists( 'Jetpack' ) ) {
523
					$cpt_supported['supports_jetpack_publicize'] = (boolean) pods_var( 'supports_jetpack_publicize', $post_type, false );
524
					$cpt_supported['supports_jetpack_markdown']  = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false );
525
				}
526
527
				// WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :(
528
				$cpt_supports = array();
529
530
				if ( ! pods_version_check( 'wp', '3.5' ) ) {
531
					$cpt_supports = array( '_bug_fix_pre_35' );
532
				}
533
534
				foreach ( $cpt_supported as $cpt_support => $supported ) {
535
					if ( true === $supported ) {
536
						$cpt_supports[] = $cpt_support;
537
					}
538
				}
539
540
				if ( empty( $cpt_supports ) && pods_version_check( 'wp', '3.5' ) ) {
541
					$cpt_supports = false;
542
				}
543
544
				// Rewrite
545
				$cpt_rewrite       = (boolean) pods_var( 'rewrite', $post_type, true );
546
				$cpt_rewrite_array = array(
547
					'slug'       => pods_var( 'rewrite_custom_slug', $post_type, str_replace( '_', '-', $post_type_name ), null, true ),
548
					'with_front' => (boolean) pods_var( 'rewrite_with_front', $post_type, true ),
549
					'feeds'      => (boolean) pods_var( 'rewrite_feeds', $post_type, (boolean) pods_var( 'has_archive', $post_type, false ) ),
550
					'pages'      => (boolean) pods_var( 'rewrite_pages', $post_type, true )
551
				);
552
553
				if ( false !== $cpt_rewrite ) {
554
					$cpt_rewrite = $cpt_rewrite_array;
555
				}
556
557
				$capability_type = pods_var( 'capability_type', $post_type, 'post' );
558
559
				if ( 'custom' == $capability_type ) {
560
					$capability_type = pods_var( 'capability_type_custom', $post_type, 'post' );
561
				}
562
563
				$show_in_menu = (boolean) pods_var( 'show_in_menu', $post_type, true );
564
565
				if ( $show_in_menu && 0 < strlen( pods_var_raw( 'menu_location_custom', $post_type ) ) ) {
566
					$show_in_menu = pods_var_raw( 'menu_location_custom', $post_type );
567
				}
568
569
				$menu_icon = pods_var( 'menu_icon', $post_type, null, null, true );
570
571
				if ( ! empty( $menu_icon ) ) {
572
					$menu_icon = pods_evaluate_tags( $menu_icon );
573
				}
574
575
				// Register Post Type
576
				$pods_post_types[ $post_type_name ] = array(
577
					'label'               => $cpt_label,
578
					'labels'              => $cpt_labels,
579
					'description'         => esc_html( pods_var_raw( 'description', $post_type ) ),
580
					'public'              => (boolean) pods_var( 'public', $post_type, true ),
581
					'publicly_queryable'  => (boolean) pods_var( 'publicly_queryable', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
582
					'exclude_from_search' => (boolean) pods_var( 'exclude_from_search', $post_type, ( (boolean) pods_var( 'public', $post_type, true ) ? false : true ) ),
583
					'show_ui'             => (boolean) pods_var( 'show_ui', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
584
					'show_in_menu'        => $show_in_menu,
585
					'show_in_nav_menus'   => (boolean) pods_var( 'show_in_nav_menus', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
586
					'show_in_admin_bar'   => (boolean) pods_var( 'show_in_admin_bar', $post_type, (boolean) pods_var( 'show_in_menu', $post_type, true ) ),
587
					'menu_position'       => (int) pods_var( 'menu_position', $post_type, 0, null, true ),
588
					'menu_icon'           => $menu_icon,
589
					'capability_type'     => $capability_type,
590
					//'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...
591
					'map_meta_cap'        => (boolean) pods_var( 'capability_type_extra', $post_type, true ),
592
					'hierarchical'        => (boolean) pods_var( 'hierarchical', $post_type, false ),
593
					'supports'            => $cpt_supports,
594
					//'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...
595
					//'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...
596
					'has_archive'         => pods_v( 'has_archive_slug', $post_type, (boolean) pods_v( 'has_archive', $post_type, false ), true ),
597
					'rewrite'             => $cpt_rewrite,
598
					'query_var'           => ( false !== (boolean) pods_var( 'query_var', $post_type, true ) ? pods_var( 'query_var_string', $post_type, $post_type_name, null, true ) : false ),
599
					'can_export'          => (boolean) pods_var( 'can_export', $post_type, true )
600
				);
601
602
				// YARPP doesn't use 'supports' array option (yet)
603
				if ( ! empty( $cpt_supports['yarpp_support'] ) ) {
604
					$pods_post_types[ $post_type_name ]['yarpp_support'] = true;
605
				}
606
607
				// Prevent reserved query_var issues
608
				if ( in_array( $pods_post_types[ $post_type_name ]['query_var'], $reserved_query_vars ) ) {
609
					$pods_post_types[ $post_type_name ]['query_var'] = 'post_type_' . $pods_post_types[ $post_type_name ]['query_var'];
610
				}
611
612
				if ( 25 == $pods_post_types[ $post_type_name ]['menu_position'] ) {
613
					$pods_post_types[ $post_type_name ]['menu_position'] ++;
614
				}
615
616
				if ( $pods_post_types[ $post_type_name ]['menu_position'] < 1 || in_array( $pods_post_types[ $post_type_name ]['menu_position'], $cpt_positions ) ) {
617
					unset( $pods_post_types[ $post_type_name ]['menu_position'] );
618
				} else {
619
					$cpt_positions[] = $pods_post_types[ $post_type_name ]['menu_position'];
620
621
					// This would be nice if WP supported floats in menu_position
622
					// $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...
623
				}
624
625
				// Taxonomies
626
				$cpt_taxonomies = array();
627
				$_taxonomies    = get_taxonomies();
628
				$_taxonomies    = array_merge_recursive( $_taxonomies, $pods_taxonomies );
629
				$ignore         = array( 'nav_menu', 'link_category', 'post_format' );
630
631 View Code Duplication
				foreach ( $_taxonomies as $taxonomy => $label ) {
632
					if ( in_array( $taxonomy, $ignore ) ) {
633
						continue;
634
					}
635
636
					if ( false !== (boolean) pods_var( 'built_in_taxonomies_' . $taxonomy, $post_type, false ) ) {
637
						$cpt_taxonomies[] = $taxonomy;
638
639
						if ( isset( $supported_post_types[ $taxonomy ] ) && ! in_array( $post_type_name, $supported_post_types[ $taxonomy ] ) ) {
640
							$supported_post_types[ $taxonomy ][] = $post_type_name;
641
						}
642
					}
643
				}
644
645
				if ( isset( $supported_taxonomies[ $post_type_name ] ) ) {
646
					$supported_taxonomies[ $post_type_name ] = array_merge( (array) $supported_taxonomies[ $post_type_name ], $cpt_taxonomies );
647
				} else {
648
					$supported_taxonomies[ $post_type_name ] = $cpt_taxonomies;
649
				}
650
			}
651
652
			foreach ( $taxonomies as $taxonomy ) {
653
				// Taxonomy Type exists already
654 View Code Duplication
				if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) {
655
					continue;
656
				} elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) {
657
					continue;
658
				} elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) {
659
					continue;
660
				}
661
662
				$taxonomy['options']['name'] = $taxonomy['name'];
663
				$taxonomy                    = array_merge( $taxonomy, (array) $taxonomy['options'] );
664
665
				$taxonomy_name = pods_var( 'name', $taxonomy );
666
667
				// Labels
668
				$ct_label    = esc_html( pods_v( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'name', $taxonomy ) ) ), true ) );
669
				$ct_singular = esc_html( pods_v( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'label', $taxonomy, pods_v( 'name', $taxonomy ), null, true ) ) ), true ) );
670
671
				$ct_labels                               = array();
672
				$ct_labels['name']                       = $ct_label;
673
				$ct_labels['singular_name']              = $ct_singular;
674
				$ct_labels['menu_name']                  = pods_v( 'menu_name', $taxonomy, '', true );
675
				$ct_labels['search_items']               = pods_v( 'label_search_items', $taxonomy, '', true );
676
				$ct_labels['popular_items']              = pods_v( 'label_popular_items', $taxonomy, '', true );
677
				$ct_labels['all_items']                  = pods_v( 'label_all_items', $taxonomy, '', true );
678
				$ct_labels['parent_item']                = pods_v( 'label_parent_item', $taxonomy, '', true );
679
				$ct_labels['parent_item_colon']          = pods_v( 'label_parent_item_colon', $taxonomy, '', true );
680
				$ct_labels['edit_item']                  = pods_v( 'label_edit_item', $taxonomy, '', true );
681
				$ct_labels['update_item']                = pods_v( 'label_update_item', $taxonomy, '', true );
682
				$ct_labels['view_item']                  = pods_v( 'label_view_item', $taxonomy, '', true );
683
				$ct_labels['add_new_item']               = pods_v( 'label_add_new_item', $taxonomy, '', true );
684
				$ct_labels['new_item_name']              = pods_v( 'label_new_item_name', $taxonomy, '', true );
685
				$ct_labels['separate_items_with_commas'] = pods_v( 'label_separate_items_with_commas', $taxonomy, '', true );
686
				$ct_labels['add_or_remove_items']        = pods_v( 'label_add_or_remove_items', $taxonomy, '', true );
687
				$ct_labels['choose_from_most_used']      = pods_v( 'label_choose_from_the_most_used', $taxonomy, '', true );
688
				$ct_labels['not_found']                  = pods_v( 'label_not_found', $taxonomy, '', true );
689
				$ct_labels['no_terms']                   = pods_v( 'label_no_terms', $taxonomy, '', true );
690
				$ct_labels['items_list']                 = pods_v( 'label_items_list', $taxonomy, '', true );
691
				$ct_labels['items_list_navigation']      = pods_v( 'label_items_list_navigation', $taxonomy, '', true );
692
693
				// Rewrite
694
				$ct_rewrite       = (boolean) pods_var( 'rewrite', $taxonomy, true );
695
				$ct_rewrite_array = array(
696
					'slug'         => pods_var( 'rewrite_custom_slug', $taxonomy, str_replace( '_', '-', $taxonomy_name ), null, true ),
697
					'with_front'   => (boolean) pods_var( 'rewrite_with_front', $taxonomy, true ),
698
					'hierarchical' => (boolean) pods_var( 'rewrite_hierarchical', $taxonomy, (boolean) pods_var( 'hierarchical', $taxonomy, false ) )
699
				);
700
701
				if ( false !== $ct_rewrite ) {
702
					$ct_rewrite = $ct_rewrite_array;
703
				}
704
705
				/**
706
				 * Default tax capabilities
707
				 * @see https://codex.wordpress.org/Function_Reference/register_taxonomy
708
				 */
709
				$capability_type = pods_var( 'capability_type', $taxonomy, 'default' );
710
				$tax_capabilities = array();
711
712
				if ( 'custom' == $capability_type ) {
713
					$capability_type = pods_var( 'capability_type_custom', $taxonomy, 'default' );
714
					if ( ! empty( $capability_type ) && 'default' != $capability_type ) {
715
						$capability_type .=  '_term';
716
						$capability_type_plural =  $capability_type . 's';
717
						$tax_capabilities = array(
718
							// Singular
719
							'edit_term'   => 'edit_' . $capability_type,
720
							'delete_term' => 'delete_' . $capability_type,
721
							'assign_term' => 'assign_' . $capability_type,
722
							// Plural
723
							'manage_terms' => 'manage_' . $capability_type_plural,
724
							'edit_terms'   => 'edit_' . $capability_type_plural,
725
							'delete_terms' => 'delete_' . $capability_type_plural,
726
							'assign_terms' => 'assign_' . $capability_type_plural,
727
						);
728
					}
729
				}
730
731
				// Register Taxonomy
732
				$pods_taxonomies[ $taxonomy_name ] = array(
733
					'label'                 => $ct_label,
734
					'labels'                => $ct_labels,
735
					'public'                => (boolean) pods_var( 'public', $taxonomy, true ),
736
					'show_ui'               => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
737
					'show_in_menu'          => (boolean) pods_var( 'show_in_menu', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
738
					'show_in_nav_menus'     => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
739
					'show_tagcloud'         => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
740
					'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 ) ) ) ),
741
					'show_in_quick_edit'    => (boolean) pods_var( 'show_in_quick_edit', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
742
					'hierarchical'          => (boolean) pods_var( 'hierarchical', $taxonomy, false ),
743
					//'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...
744
					'capabilities'          => $tax_capabilities,
745
					//'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...
746
					'update_count_callback' => pods_var( 'update_count_callback', $taxonomy, null, null, true ),
747
					'query_var'             => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ),
748
					'rewrite'               => $ct_rewrite,
749
					'show_admin_column'     => (boolean) pods_var( 'show_admin_column', $taxonomy, false ),
750
					'sort'                  => (boolean) pods_var( 'sort', $taxonomy, false ),
751
				);
752
753
				if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) {
754
					$pods_taxonomies[ $taxonomy_name ]['query_var'] = pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true );
755
				};
756
757
				// Prevent reserved query_var issues
758
				if ( in_array( $pods_taxonomies[ $taxonomy_name ]['query_var'], $reserved_query_vars ) ) {
759
					$pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var'];
760
				}
761
762
				// Integration for Single Value Taxonomy UI
763
				if ( function_exists( 'tax_single_value_meta_box' ) ) {
764
					$pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false );
765
					$pods_taxonomies[ $taxonomy_name ]['required']     = (boolean) pods_var( 'single_value_required', $taxonomy, false );
766
				}
767
768
				// Post Types
769
				$ct_post_types = array();
770
				$_post_types   = get_post_types();
771
				$_post_types   = array_merge_recursive( $_post_types, $pods_post_types );
772
				$ignore        = array( 'revision' );
773
774 View Code Duplication
				foreach ( $_post_types as $post_type => $options ) {
775
					if ( in_array( $post_type, $ignore ) ) {
776
						continue;
777
					}
778
779
					if ( false !== (boolean) pods_var( 'built_in_post_types_' . $post_type, $taxonomy, false ) ) {
780
						$ct_post_types[] = $post_type;
781
782
						if ( isset( $supported_taxonomies[ $post_type ] ) && ! in_array( $taxonomy_name, $supported_taxonomies[ $post_type ] ) ) {
783
							$supported_taxonomies[ $post_type ][] = $taxonomy_name;
784
						}
785
					}
786
				}
787
788
				if ( isset( $supported_post_types[ $taxonomy_name ] ) ) {
789
					$supported_post_types[ $taxonomy_name ] = array_merge( $supported_post_types[ $taxonomy_name ], $ct_post_types );
790
				} else {
791
					$supported_post_types[ $taxonomy_name ] = $ct_post_types;
792
				}
793
			}
794
795
			$pods_post_types = apply_filters( 'pods_wp_post_types', $pods_post_types );
796
			$pods_taxonomies = apply_filters( 'pods_wp_taxonomies', $pods_taxonomies );
797
798
			$supported_post_types = apply_filters( 'pods_wp_supported_post_types', $supported_post_types );
799
			$supported_taxonomies = apply_filters( 'pods_wp_supported_taxonomies', $supported_taxonomies );
800
801
			foreach ( $pods_taxonomies as $taxonomy => $options ) {
802
				$ct_post_types = null;
803
804
				if ( isset( $supported_post_types[ $taxonomy ] ) && ! empty( $supported_post_types[ $taxonomy ] ) ) {
805
					$ct_post_types = $supported_post_types[ $taxonomy ];
806
				}
807
808
				$pods_cpt_ct['taxonomies'][ $taxonomy ] = array(
809
					'post_types' => $ct_post_types,
810
					'options'    => $options
811
				);
812
			}
813
814
			foreach ( $pods_post_types as $post_type => $options ) {
815
				if ( isset( $supported_taxonomies[ $post_type ] ) && ! empty( $supported_taxonomies[ $post_type ] ) ) {
816
					$options['taxonomies'] = $supported_taxonomies[ $post_type ];
817
				}
818
819
				$pods_cpt_ct['post_types'][ $post_type ] = $options;
820
			}
821
822
			pods_transient_set( 'pods_wp_cpt_ct', $pods_cpt_ct );
823
		}
824
825
		foreach ( $pods_cpt_ct['taxonomies'] as $taxonomy => $options ) {
826
			if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy, self::$content_types_registered['taxonomies'] ) ) {
827
				continue;
828
			}
829
830
			$ct_post_types = $options['post_types'];
831
			$options       = $options['options'];
832
833
			$options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy );
834
			$options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy );
835
836
			$options = self::object_label_fix( $options, 'taxonomy' );
837
838
			/**
839
			 * Hide tagcloud compatibility
840
			 * @todo check https://core.trac.wordpress.org/ticket/36964
841
			 * @see wp-admin/edit-tags.php L389
842
			 */
843
			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...
844
				$options['labels']['popular_items'] = null;
845
			}
846
847
			// Max length for taxonomies are 32 characters
848
			$taxonomy = substr( $taxonomy, 0, 32 );
849
850
			// i18n compatibility for plugins that override it
851 View Code Duplication
			if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) {
852
				$options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' );
853
			}
854
855 View Code Duplication
			if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
856
				pods_debug( array( $taxonomy, $ct_post_types, $options ) );
857
			}
858
859
			register_taxonomy( $taxonomy, $ct_post_types, $options );
860
861
			if ( ! isset( self::$content_types_registered['taxonomies'] ) ) {
862
				self::$content_types_registered['taxonomies'] = array();
863
			}
864
865
			self::$content_types_registered['taxonomies'][] = $taxonomy;
866
		}
867
868
		foreach ( $pods_cpt_ct['post_types'] as $post_type => $options ) {
869
			if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type, self::$content_types_registered['post_types'] ) ) {
870
				continue;
871
			}
872
873
			$options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type );
874
			$options = apply_filters( 'pods_register_post_type', $options, $post_type );
875
876
			$options = self::object_label_fix( $options, 'post_type' );
877
878
			// Max length for post types are 20 characters
879
			$post_type = substr( $post_type, 0, 20 );
880
881
			// i18n compatibility for plugins that override it
882 View Code Duplication
			if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) {
883
				$options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' );
884
			}
885
886 View Code Duplication
			if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
887
				pods_debug( array( $post_type, $options ) );
888
			}
889
890
			register_post_type( $post_type, $options );
891
892
			if ( ! isset( self::$content_types_registered['post_types'] ) ) {
893
				self::$content_types_registered['post_types'] = array();
894
			}
895
896
			self::$content_types_registered['post_types'][] = $post_type;
897
		}
898
899
	}
900
901
	/**
902
	 * Check if we need to flush WordPress rewrite rules
903
	 * This gets run during 'init' action late in the game to give other plugins time to register their rewrite rules
904
	 */
905
	public function flush_rewrite_rules() {
906
907
		$flush = (int) pods_transient_get( 'pods_flush_rewrites' );
908
909
		if ( 1 === $flush ) {
910
			/**
911
			 * @var $wp_rewrite WP_Rewrite
912
			 */
913
			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...
914
			$wp_rewrite->flush_rules();
915
			$wp_rewrite->init();
916
917
			pods_transient_set( 'pods_flush_rewrites', 0 );
918
		}
919
	}
920
921
	/**
922
	 * Update Post Type messages
923
	 *
924
	 * @param array $messages
925
	 *
926
	 * @return array
927
	 * @since 2.0.2
928
	 */
929
	public function setup_updated_messages( $messages ) {
930
931
		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...
932
933
		$post_types          = PodsMeta::$post_types;
934
		$existing_post_types = get_post_types();
935
936
		$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
937
938
		if ( empty( $pods_cpt_ct ) || empty( $post_types ) ) {
939
			return $messages;
940
		}
941
942
		foreach ( $post_types as $post_type ) {
943
			if ( ! isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
944
				continue;
945
			}
946
947
			$labels = self::object_label_fix( $pods_cpt_ct['post_types'][ $post_type['name'] ], 'post_type' );
948
			$labels = $labels['labels'];
949
950
			$messages[ $post_type['name'] ] = array(
951
				1  => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ),
952
				2  => __( 'Custom field updated.', 'pods' ),
953
				3  => __( 'Custom field deleted.', 'pods' ),
954
				4  => sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] ),
955
				/* translators: %s: date and time of the revision */
956
				5  => isset( $_GET['revision'] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels['singular_name'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
957
				6  => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ),
958
				7  => sprintf( __( '%s saved.', 'pods' ), $labels['singular_name'] ),
959
				8  => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels['singular_name'] ),
960
				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
961
					date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $labels['singular_name'] ),
962
				10 => sprintf( __( '%s draft updated. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels['singular_name'] )
963
			);
964
965
			if ( false === (boolean) $pods_cpt_ct['post_types'][ $post_type['name'] ]['public'] ) {
966
				$messages[ $post_type['name'] ][1]  = sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] );
967
				$messages[ $post_type['name'] ][6]  = sprintf( __( '%s published.', 'pods' ), $labels['singular_name'] );
968
				$messages[ $post_type['name'] ][8]  = sprintf( __( '%s submitted.', 'pods' ), $labels['singular_name'] );
969
				$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
970
					date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) );
971
				$messages[ $post_type['name'] ][10] = sprintf( __( '%s draft updated.', 'pods' ), $labels['singular_name'] );
972
			}
973
		}
974
975
		return $messages;
976
	}
977
978
	/**
979
	 * @param        $args
980
	 * @param string $type
981
	 *
982
	 * @return array
983
	 */
984
	public static function object_label_fix( $args, $type = 'post_type' ) {
985
986
		if ( empty( $args ) || ! is_array( $args ) ) {
987
			$args = array();
988
		}
989
990
		if ( ! isset( $args['labels'] ) || ! is_array( $args['labels'] ) ) {
991
			$args['labels'] = array();
992
		}
993
994
		$label          = pods_v( 'name', $args['labels'], pods_v( 'label', $args, __( 'Items', 'pods' ), true ), true );
995
		$singular_label = pods_v( 'singular_name', $args['labels'], pods_v( 'label_singular', $args, __( 'Item', 'pods' ), true ), true );
996
997
		$labels = $args['labels'];
998
999
		$labels['name']          = $label;
1000
		$labels['singular_name'] = $singular_label;
1001
1002
		if ( 'post_type' == $type ) {
1003
			$labels['menu_name']             = pods_v( 'menu_name', $labels, $label, true );
1004
			$labels['name_admin_bar']        = pods_v( 'name_admin_bar', $labels, $singular_label, true );
1005
			$labels['add_new']               = pods_v( 'add_new', $labels, __( 'Add New', 'pods' ), true );
1006
			$labels['add_new_item']          = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1007
			$labels['new_item']              = pods_v( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), true );
1008
			$labels['edit']                  = pods_v( 'edit', $labels, __( 'Edit', 'pods' ), true );
1009
			$labels['edit_item']             = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1010
			$labels['view']                  = pods_v( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1011
			$labels['view_item']             = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1012
			$labels['view_items']            = pods_v( 'view_items', $labels, sprintf( __( 'View %s', 'pods' ), $label ), true );
1013
			$labels['all_items']             = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1014
			$labels['search_items']          = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1015
			$labels['not_found']             = pods_v( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), true );
1016
			$labels['not_found_in_trash']    = pods_v( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), true );
1017
			$labels['parent']                = pods_v( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1018
			$labels['parent_item_colon']     = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), true );
1019
			$labels['featured_image']        = pods_v( 'featured_image', $labels, __( 'Featured Image', 'pods' ), true );
1020
			$labels['set_featured_image']    = pods_v( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), true );
1021
			$labels['remove_featured_image'] = pods_v( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), true );
1022
			$labels['use_featured_image']    = pods_v( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), true );
1023
			$labels['archives']              = pods_v( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), true );
1024
			$labels['attributes']            = pods_v( 'attributes', $labels, sprintf( __( '%s Attributes', 'pods' ), $singular_label ), true );
1025
			$labels['insert_into_item']      = pods_v( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), true );
1026
			$labels['uploaded_to_this_item'] = pods_v( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), true );
1027
			$labels['filter_items_list']     = pods_v( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), true );
1028
			$labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1029
			$labels['items_list']            = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1030
		} elseif ( 'taxonomy' == $type ) {
1031
			$labels['menu_name']                  = pods_v( 'menu_name', $labels, $label, true );
1032
			$labels['search_items']               = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1033
			$labels['popular_items']              = pods_v( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), true );
1034
			$labels['all_items']                  = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1035
			$labels['parent_item']                = pods_v( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1036
			$labels['parent_item_colon']          = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), true );
1037
			$labels['edit_item']                  = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1038
			$labels['view_item']                  = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1039
			$labels['update_item']                = pods_v( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), true );
1040
			$labels['add_new_item']               = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1041
			$labels['new_item_name']              = pods_v( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), true );
1042
			$labels['separate_items_with_commas'] = pods_v( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), true );
1043
			$labels['add_or_remove_items']        = pods_v( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), true );
1044
			$labels['choose_from_most_used']      = pods_v( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), true );
1045
			$labels['not_found']                  = pods_v( 'not_found', $labels, sprintf( __( 'No %s found.', 'pods' ), $label ), true );
1046
			$labels['no_terms']                   = pods_v( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), true );
1047
			$labels['items_list_navigation']      = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1048
			$labels['items_list']                 = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1049
		}
1050
1051
		$args['labels'] = $labels;
1052
1053
		return $args;
1054
	}
1055
1056
	/**
1057
	 * Activate and Install
1058
	 */
1059
	public function activate_install() {
1060
1061
		register_activation_hook( PODS_DIR . 'init.php', array( $this, 'activate' ) );
1062
		register_deactivation_hook( PODS_DIR . 'init.php', array( $this, 'deactivate' ) );
1063
1064
		add_action( 'wpmu_new_blog', array( $this, 'new_blog' ), 10, 6 );
1065
1066
		if ( empty( self::$version ) || version_compare( self::$version, PODS_VERSION, '<' ) || version_compare( self::$version, PODS_DB_VERSION, '<=' ) || self::$upgrade_needed ) {
1067
			$this->setup();
1068
		} elseif ( self::$version !== PODS_VERSION ) {
1069
			delete_option( 'pods_framework_version' );
1070
			add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
1071
1072
			self::$version = PODS_VERSION;
1073
1074
			pods_api()->cache_flush_pods();
1075
		}
1076
1077
	}
1078
1079
	/**
1080
	 *
1081
	 */
1082
	public function activate() {
1083
1084
		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...
1085
1086
		if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && 1 == $_GET['networkwide'] ) {
1087
			$_blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `{$wpdb->blogs}`" );
1088
1089
			foreach ( $_blog_ids as $_blog_id ) {
1090
				$this->setup( $_blog_id );
1091
			}
1092
		} else {
1093
			$this->setup();
1094
		}
1095
	}
1096
1097
	/**
1098
	 *
1099
	 */
1100
	public function deactivate() {
1101
1102
		pods_api()->cache_flush_pods();
1103
1104
	}
1105
1106
	/**
1107
	 *
1108
	 */
1109
	public function needs_upgrade( $current = null, $last = null ) {
1110
1111
		if ( null === $current ) {
1112
			$current = self::$version;
1113
		}
1114
1115
		if ( null === $last ) {
1116
			$last = self::$version_last;
1117
		}
1118
1119
		$upgrade_needed = false;
1120
1121
		if ( ! empty( $current ) ) {
1122
			foreach ( self::$upgrades as $old_version => $new_version ) {
1123
				/*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...
1124
					continue;*/
1125
1126
				if ( version_compare( $last, $old_version, '>=' ) && version_compare( $last, $new_version, '<' ) && version_compare( $current, $new_version, '>=' ) && 1 != self::$upgraded ) {
1127
					$upgrade_needed = true;
1128
1129
					break;
1130
				}
1131
			}
1132
		}
1133
1134
		return $upgrade_needed;
1135
	}
1136
1137
	/**
1138
	 * @param $_blog_id
1139
	 * @param $user_id
1140
	 * @param $domain
1141
	 * @param $path
1142
	 * @param $site_id
1143
	 * @param $meta
1144
	 */
1145
	public function new_blog( $_blog_id, $user_id, $domain, $path, $site_id, $meta ) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $domain is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $site_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $meta is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1146
1147
		if ( function_exists( 'is_multisite' ) && is_multisite() && is_plugin_active_for_network( basename( PODS_DIR ) . '/init.php' ) ) {
1148
			$this->setup( $_blog_id );
1149
		}
1150
	}
1151
1152
	/**
1153
	 * @param null $_blog_id
1154
	 */
1155
	public function setup( $_blog_id = null ) {
1156
1157
		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...
1158
1159
		// Switch DB table prefixes
1160 View Code Duplication
		if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) {
1161
			switch_to_blog( pods_absint( $_blog_id ) );
1162
		} else {
1163
			$_blog_id = null;
1164
		}
1165
1166
		// Setup DB tables
1167
		$pods_version      = get_option( 'pods_framework_version' );
1168
		$pods_version_last = get_option( 'pods_framework_version_last' );
1169
1170
		// Install Pods
1171
		if ( empty( $pods_version ) ) {
1172
			pods_upgrade()->install( $_blog_id );
1173
1174
			$old_version = get_option( 'pods_version' );
1175
1176
			if ( ! empty( $old_version ) ) {
1177
				if ( false === strpos( $old_version, '.' ) ) {
1178
					$old_version = pods_version_to_point( $old_version );
1179
				}
1180
1181
				delete_option( 'pods_framework_version_last' );
1182
				add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
1183
1184
				self::$version_last = $old_version;
1185
			}
1186
		} // Upgrade Wizard needed
1187
		elseif ( $this->needs_upgrade( $pods_version, $pods_version_last ) ) {
1188
			// Do not do anything
1189
			return;
1190
		} // Update Pods and run any required DB updates
1191
		elseif ( version_compare( $pods_version, PODS_VERSION, '<=' ) ) {
1192
			if ( false !== apply_filters( 'pods_update_run', null, PODS_VERSION, $pods_version, $_blog_id ) && ! isset( $_GET['pods_bypass_update'] ) ) {
1193
				do_action( 'pods_update', PODS_VERSION, $pods_version, $_blog_id );
1194
1195
				// Update 2.0 alpha / beta sites
1196
				if ( version_compare( '2.0.0-a-1', $pods_version, '<=' ) && version_compare( $pods_version, '2.0.0-b-15', '<=' ) ) {
1197
					include( PODS_DIR . 'sql/update-2.0-beta.php' );
1198
				}
1199
1200
				if ( version_compare( $pods_version, PODS_DB_VERSION, '<=' ) ) {
1201
					include( PODS_DIR . 'sql/update.php' );
1202
				}
1203
1204
				do_action( 'pods_update_post', PODS_VERSION, $pods_version, $_blog_id );
1205
			}
1206
1207
			delete_option( 'pods_framework_version_last' );
1208
			add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
1209
1210
			self::$version_last = $pods_version;
1211
		}
1212
1213
		delete_option( 'pods_framework_version' );
1214
		add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
1215
1216
		delete_option( 'pods_framework_db_version' );
1217
		add_option( 'pods_framework_db_version', PODS_DB_VERSION, '', 'yes' );
1218
1219
		self::$version = PODS_VERSION;
1220
		self::$db_version = PODS_DB_VERSION;
1221
1222
		pods_api()->cache_flush_pods();
1223
1224
		// Restore DB table prefix (if switched)
1225
		if ( null !== $_blog_id ) {
1226
			restore_current_blog();
1227
		}
1228
1229
	}
1230
1231
	/**
1232
	 * @param null $_blog_id
1233
	 */
1234
	public function reset( $_blog_id = null ) {
1235
1236
		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...
1237
1238
		// Switch DB table prefixes
1239 View Code Duplication
		if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) {
1240
			switch_to_blog( pods_absint( $_blog_id ) );
1241
		} else {
1242
			$_blog_id = null;
1243
		}
1244
1245
		$api = pods_api();
1246
1247
		$pods = $api->load_pods( array( 'names_ids' => true, 'table_info' => false ) );
1248
1249
		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...
1250
			$api->delete_pod( array( 'id' => $pod_id ) );
1251
		}
1252
1253
		$templates = $api->load_templates();
1254
1255
		foreach ( $templates as $template ) {
1256
			$api->delete_template( array( 'id' => $template['id'] ) );
1257
		}
1258
1259
		$pages = $api->load_pages();
1260
1261
		foreach ( $pages as $page ) {
1262
			$api->delete_page( array( 'id' => $page['id'] ) );
1263
		}
1264
1265
		$helpers = $api->load_helpers();
1266
1267
		foreach ( $helpers as $helper ) {
1268
			$api->delete_helper( array( 'id' => $helper['id'] ) );
1269
		}
1270
1271
		$tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pods%'", ARRAY_N );
1272
1273
		if ( ! empty( $tables ) ) {
1274
			foreach ( $tables as $table ) {
1275
				$table = $table[0];
1276
1277
				pods_query( "DROP TABLE `{$table}`", false );
1278
			}
1279
		}
1280
1281
		// Remove any orphans
1282
		$wpdb->query( "
1283
                DELETE `p`, `pm`
1284
                FROM `{$wpdb->posts}` AS `p`
1285
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1286
                    ON `pm`.`post_id` = `p`.`ID`
1287
                WHERE
1288
                    `p`.`post_type` LIKE '_pods_%'
1289
            " );
1290
1291
		delete_option( 'pods_framework_version' );
1292
		delete_option( 'pods_framework_db_version' );
1293
		delete_option( 'pods_framework_upgrade_2_0' );
1294
		delete_option( 'pods_framework_upgraded_1_x' );
1295
1296
		// @todo Make sure all entries are being cleaned and do something about the pods_framework_upgrade_{version} dynamic entries created by PodsUpgrade
1297
		delete_option( 'pods_framework_upgrade_2_0_0' );
1298
		delete_option( 'pods_framework_upgrade_2_0_sister_ids' );
1299
		delete_option( 'pods_framework_version_last' );
1300
1301
		delete_option( 'pods_component_settings' );
1302
1303
		$api->cache_flush_pods();
1304
1305
		pods_transient_clear( 'pods_flush_rewrites' );
1306
1307
		self::$version = '';
1308
1309
		// Restore DB table prefix (if switched)
1310
		if ( null !== $_blog_id ) {
1311
			restore_current_blog();
1312
		}
1313
	}
1314
1315
	public function run() {
1316
1317
		static $ran;
1318
1319
		if ( ! empty( $ran ) ) {
1320
			return;
1321
		}
1322
1323
		$ran = true;
1324
1325
		$this->load_i18n();
1326
1327
		if ( ! did_action( 'plugins_loaded' ) ) {
1328
			add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 );
1329
		} else {
1330
			$this->load_components();
1331
		}
1332
1333
		if ( ! did_action( 'setup_theme' ) ) {
1334
			add_action( 'setup_theme', array( $this, 'load_meta' ), 14 );
1335
		} else {
1336
			$this->load_meta();
1337
		}
1338
1339
		if ( ! did_action( 'init' ) ) {
1340
			add_action( 'init', array( $this, 'core' ), 11 );
1341
			add_action( 'init', array( $this, 'add_rest_support' ), 12 );
1342
			add_action( 'init', array( $this, 'setup_content_types' ), 11 );
1343
1344
			if ( is_admin() ) {
1345
				add_action( 'init', array( $this, 'admin_init' ), 12 );
1346
			}
1347
		} else {
1348
			$this->core();
1349
			$this->add_rest_support();
1350
			$this->setup_content_types();
1351
1352
			if ( is_admin() ) {
1353
				$this->admin_init();
1354
			}
1355
		}
1356
1357
		add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1358
		add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1359
		add_action( 'login_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1360
1361
		add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
1362
		add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
1363
1364
		// Register widgets
1365
		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
1366
1367
		// Show admin bar links
1368
		add_action( 'admin_bar_menu', array( $this, 'admin_bar_links' ), 81 );
1369
1370
	}
1371
1372
	/**
1373
	 * Delete Attachments from relationships
1374
	 *
1375
	 * @param int $_ID
1376
	 */
1377
	public function delete_attachment( $_ID ) {
1378
1379
		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...
1380
1381
		$_ID = (int) $_ID;
1382
1383
		do_action( 'pods_delete_attachment', $_ID );
1384
1385
		$file_types = "'" . implode( "', '", PodsForm::file_field_types() ) . "'";
1386
1387
		if ( ! pods_tableless() ) {
1388
			$sql = "
1389
                DELETE `rel`
1390
                FROM `@wp_podsrel` AS `rel`
1391
                LEFT JOIN `{$wpdb->posts}` AS `p`
1392
                    ON
1393
                        `p`.`post_type` = '_pods_field'
1394
                        AND ( `p`.`ID` = `rel`.`field_id` OR `p`.`ID` = `rel`.`related_field_id` )
1395
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1396
                    ON
1397
                        `pm`.`post_id` = `p`.`ID`
1398
                        AND `pm`.`meta_key` = 'type'
1399
                        AND `pm`.`meta_value` IN ( {$file_types} )
1400
                WHERE
1401
                    `p`.`ID` IS NOT NULL
1402
                    AND `pm`.`meta_id` IS NOT NULL
1403
                    AND `rel`.`item_id` = {$_ID}";
1404
1405
			pods_query( $sql, false );
1406
		}
1407
1408
		// Post Meta
1409 View Code Duplication
		if ( ! empty( PodsMeta::$post_types ) ) {
1410
			$sql = "
1411
                DELETE `rel`
1412
                FROM `@wp_postmeta` AS `rel`
1413
                LEFT JOIN `{$wpdb->posts}` AS `p`
1414
                    ON
1415
                        `p`.`post_type` = '_pods_field'
1416
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1417
                    ON
1418
                        `pm`.`post_id` = `p`.`ID`
1419
                        AND `pm`.`meta_key` = 'type'
1420
                        AND `pm`.`meta_value` IN ( {$file_types} )
1421
                WHERE
1422
                    `p`.`ID` IS NOT NULL
1423
                    AND `pm`.`meta_id` IS NOT NULL
1424
                    AND `rel`.`meta_key` = `p`.`post_name`
1425
                    AND `rel`.`meta_value` = '{$_ID}'";
1426
1427
			pods_query( $sql, false );
1428
		}
1429
1430
		// User Meta
1431 View Code Duplication
		if ( ! empty( PodsMeta::$user ) ) {
1432
			$sql = "
1433
                DELETE `rel`
1434
                FROM `@wp_usermeta` AS `rel`
1435
                LEFT JOIN `{$wpdb->posts}` AS `p`
1436
                    ON
1437
                        `p`.`post_type` = '_pods_field'
1438
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1439
                    ON
1440
                        `pm`.`post_id` = `p`.`ID`
1441
                        AND `pm`.`meta_key` = 'type'
1442
                        AND `pm`.`meta_value` IN ( {$file_types} )
1443
                WHERE
1444
                    `p`.`ID` IS NOT NULL
1445
                    AND `pm`.`meta_id` IS NOT NULL
1446
                    AND `rel`.`meta_key` = `p`.`post_name`
1447
                    AND `rel`.`meta_value` = '{$_ID}'";
1448
1449
			pods_query( $sql, false );
1450
		}
1451
1452
		// Comment Meta
1453 View Code Duplication
		if ( ! empty( PodsMeta::$comment ) ) {
1454
			$sql = "
1455
                DELETE `rel`
1456
                FROM `@wp_commentmeta` AS `rel`
1457
                LEFT JOIN `{$wpdb->posts}` AS `p`
1458
                    ON
1459
                        `p`.`post_type` = '_pods_field'
1460
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1461
                    ON
1462
                        `pm`.`post_id` = `p`.`ID`
1463
                        AND `pm`.`meta_key` = 'type'
1464
                        AND `pm`.`meta_value` IN ( {$file_types} )
1465
                WHERE
1466
                    `p`.`ID` IS NOT NULL
1467
                    AND `pm`.`meta_id` IS NOT NULL
1468
                    AND `rel`.`meta_key` = `p`.`post_name`
1469
                    AND `rel`.`meta_value` = '{$_ID}'";
1470
1471
			pods_query( $sql, false );
1472
		}
1473
	}
1474
1475
	/**
1476
	 * Register widgets for Pods
1477
	 */
1478
	public function register_widgets() {
1479
1480
		$widgets = array(
1481
			'PodsWidgetSingle',
1482
			'PodsWidgetList',
1483
			'PodsWidgetField',
1484
			'PodsWidgetForm',
1485
			'PodsWidgetView'
1486
		);
1487
1488
		foreach ( $widgets as $widget ) {
1489
			if ( ! file_exists( PODS_DIR . 'classes/widgets/' . $widget . '.php' ) ) {
1490
				continue;
1491
			}
1492
1493
			require_once PODS_DIR . 'classes/widgets/' . $widget . '.php';
1494
1495
			register_widget( $widget );
1496
		}
1497
	}
1498
1499
	/**
1500
	 * Add Admin Bar links
1501
	 */
1502
	public function admin_bar_links() {
1503
1504
		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...
1505
1506
		if ( ! is_user_logged_in() || ! is_admin_bar_showing() ) {
1507
			return;
1508
		}
1509
1510
		$all_pods = pods_api()->load_pods( array( 'type' => 'pod', 'fields' => false, 'table_info' => false ) );
1511
1512
		// Add New item links for all pods
1513
		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...
1514
			if ( 0 == $pod['options']['show_in_menu'] ) {
1515
				continue;
1516
			}
1517
1518
			if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod['name'] ) ) ) {
1519
				continue;
1520
			}
1521
1522
			$singular_label = pods_var_raw( 'label_singular', $pod['options'], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), null, true ), null, true );
1523
1524
			$wp_admin_bar->add_node( array(
1525
				'id'     => 'new-pod-' . $pod['name'],
1526
				'title'  => $singular_label,
1527
				'parent' => 'new-content',
1528
				'href'   => admin_url( 'admin.php?page=pods-manage-' . $pod['name'] . '&action=add' )
1529
			) );
1530
		}
1531
1532
		// Add edit link if we're on a pods page
1533
		if ( is_object( $pods ) && ! is_wp_error( $pods ) && ! empty( $pods->id ) && isset( $pods->pod_data ) && ! empty( $pods->pod_data ) && 'pod' == $pods->pod_data['type'] ) {
1534
			$pod = $pods->pod_data;
1535
1536
			if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
1537
				$singular_label = pods_var_raw( 'label_singular', $pod['options'], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), null, true ), null, true );
1538
1539
				$wp_admin_bar->add_node( array(
1540
					'title' => sprintf( __( 'Edit %s', 'pods' ), $singular_label ),
1541
					'id'    => 'edit-pod',
1542
					'href'  => admin_url( 'admin.php?page=pods-manage-' . $pod['name'] . '&action=edit&id=' . $pods->id() )
1543
				) );
1544
			}
1545
		}
1546
1547
	}
1548
1549
	/**
1550
	 * Add REST API support to post type and taxonomy objects.
1551
	 *
1552
	 * @uses  "init"
1553
	 *
1554
	 * @since 2.5.6
1555
	 */
1556
	public function add_rest_support() {
1557
1558
		if ( empty( self::$version ) ) {
1559
			return;
1560
		}
1561
1562
		static $rest_support_added;
1563
1564
		if ( ! function_exists( 'register_rest_field' ) ) {
1565
			return;
1566
		}
1567
1568
		include_once( PODS_DIR . 'classes/PodsRESTFields.php' );
1569
		include_once( PODS_DIR . 'classes/PodsRESTHandlers.php' );
1570
1571
		$rest_bases = pods_transient_get( 'pods_rest_bases' );
1572
1573
		if ( empty( $rest_bases ) ) {
1574
	        $pods = pods_api()->load_pods( array( 'type' => array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ), 'fields' => false, 'table_info' => false ) );
1575
1576
			$rest_bases = array();
1577
1578
			if ( ! empty( $pods ) && is_array( $pods ) ) {
1579
				foreach ( $pods as $pod ) {
1580
					$type = $pod['type'];
1581
1582
					if ( in_array( $type, array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ) ) ) {
1583
						if ( $pod && PodsRESTHandlers::pod_extends_core_route( $pod ) ) {
1584
							$rest_bases[ $pod['name'] ] = array(
1585
								'type' => $type,
1586
								'base' => sanitize_title( pods_v( 'rest_base', $pod['options'], $pod['name'] ) ),
1587
							);
1588
						}
1589
					}
1590
				}
1591
			}
1592
1593
			if ( empty( $rest_bases ) ) {
1594
				$rest_bases = 'none';
1595
			}
1596
1597
			pods_transient_set( 'pods_rest_bases', $rest_bases );
1598
		}
1599
1600
		if ( empty( $rest_support_added ) && ! empty( $rest_bases ) && 'none' !== $rest_bases ) {
1601
			foreach ( $rest_bases as $pod_name => $pod_info ) {
1602
				$pod_type  = $pod_info['type'];
1603
				$rest_base = $pod_info['base'];
1604
1605
				if ( 'post_type' == $pod_type ) {
1606
					PodsRESTHandlers::post_type_rest_support( $pod_name, $rest_base );
1607
				} elseif ( 'taxonomy' == $pod_type ) {
1608
					PodsRESTHandlers::taxonomy_rest_support( $pod_name, $rest_base );
1609
				}
1610
1611
				new PodsRESTFields( $pod_name );
1612
			}
1613
1614
			$rest_support_added = true;
1615
		}
1616
1617
	}
1618
}
1619