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

PodsInit::delete_attachment()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 97
Code Lines 33

Duplication

Lines 60
Ratio 61.86 %

Importance

Changes 0
Metric Value
cc 5
eloc 33
c 0
b 0
f 0
nc 16
nop 1
dl 60
loc 97
rs 8.183

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
		$register_handlebars = apply_filters( 'pods_script_register_handlebars', true );
307
308
		if ( is_admin() ) {
309
			$screen = get_current_screen();
310
311
			// Deregister the outdated Pods handlebars script on TEC event screen
312
			if ( $screen && 'tribe_events' === $screen->post_type ) {
313
				$register_handlebars = false;
314
			}
315
		}
316
317
		if ( $register_handlebars ) {
318
			wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' );
319
		}
320
321
		// Marionette dependencies for MV fields
322
		wp_register_script( 'backbone.radio', PODS_URL . 'ui/js/marionette/backbone.radio.js', array( 'backbone' ), '2.0.0', true );
323
		wp_register_script( 'marionette', PODS_URL . 'ui/js/marionette/backbone.marionette.js', array( 'backbone', 'backbone.radio' ), '3.1.0', true );
324
325
		// MV stuff
326
		wp_register_script(
327
			'pods-dfv',
328
			PODS_URL . 'ui/js/pods-dfv/pods-dfv.min.js',
329
			array(
330
				'jquery',
331
				'jquery-ui-core',
332
				'jquery-ui-sortable',
333
				'pods-i18n',
334
				'marionette',
335
				'media-views',
336
				'media-models'
337
			),
338
			PODS_VERSION,
339
			true
340
		);
341
342
		wp_register_style( 'pods-dfv-list', PODS_URL . 'ui/css/pods-dfv-list.css', array(), PODS_VERSION );
343
344
	}
345
346
	/**
347
	 * Register internal Post Types
348
	 */
349
	public function register_pods() {
350
351
		$args = array(
352
			'label'           => 'Pods',
353
			'labels'          => array( 'singular_name' => 'Pod' ),
354
			'public'          => false,
355
			'can_export'      => false,
356
			'query_var'       => false,
357
			'rewrite'         => false,
358
			'capability_type' => 'pods_pod',
359
			'has_archive'     => false,
360
			'hierarchical'    => false,
361
			'supports'        => array( 'title', 'author' ),
362
			'menu_icon'       => 'dashicons-pods'
363
		);
364
365
		$args = self::object_label_fix( $args, 'post_type' );
366
367
		register_post_type( '_pods_pod', apply_filters( 'pods_internal_register_post_type_pod', $args ) );
368
369
		$args = array(
370
			'label'           => 'Pod Fields',
371
			'labels'          => array( 'singular_name' => 'Pod Field' ),
372
			'public'          => false,
373
			'can_export'      => false,
374
			'query_var'       => false,
375
			'rewrite'         => false,
376
			'capability_type' => 'pods_pod',
377
			'has_archive'     => false,
378
			'hierarchical'    => true,
379
			'supports'        => array( 'title', 'editor', 'author' ),
380
			'menu_icon'       => 'dashicons-pods'
381
		);
382
383
		$args = self::object_label_fix( $args, 'post_type' );
384
385
		register_post_type( '_pods_field', apply_filters( 'pods_internal_register_post_type_field', $args ) );
386
	}
387
388
	/**
389
	 * Include Admin
390
	 */
391
	public function admin_init() {
392
393
		self::$admin = pods_admin();
394
	}
395
396
	/**
397
	 * Register Post Types and Taxonomies
398
	 */
399
	public function setup_content_types( $force = false ) {
400
401
		if ( empty( self::$version ) ) {
402
			return;
403
		}
404
405
		$post_types = PodsMeta::$post_types;
406
		$taxonomies = PodsMeta::$taxonomies;
407
408
		$existing_post_types = get_post_types();
409
		$existing_taxonomies = get_taxonomies();
410
411
		$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
412
413
		$cpt_positions = array();
414
415
		if ( empty( $pods_cpt_ct ) && ( ! empty( $post_types ) || ! empty( $taxonomies ) ) ) {
416
			$force = true;
417
		} elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['post_types'] ) && ! empty( $post_types ) ) {
418
			$force = true;
419
		} elseif ( ! empty( $pods_cpt_ct ) && empty( $pods_cpt_ct['taxonomies'] ) && ! empty( $taxonomies ) ) {
420
			$force = true;
421
		}
422
423
		if ( false === $pods_cpt_ct || $force ) {
424
			/**
425
			 * @var WP_Query
426
			 */
427
			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...
428
429
			$reserved_query_vars = array(
430
				'post_type',
431
				'taxonomy',
432
				'output'
433
			);
434
435
			if ( is_object( $wp_query ) ) {
436
				$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
437
			}
438
439
			$pods_cpt_ct = array(
440
				'post_types' => array(),
441
				'taxonomies' => array()
442
			);
443
444
			$pods_post_types      = $pods_taxonomies = array();
445
			$supported_post_types = $supported_taxonomies = array();
446
447
			$post_format_post_types = array();
448
449
			foreach ( $post_types as $post_type ) {
450
				// Post Type exists already
451 View Code Duplication
				if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
452
					continue;
453
				} elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) {
454
					continue;
455
				} elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) {
456
					continue;
457
				}
458
459
				$post_type['options']['name'] = $post_type['name'];
460
				$post_type                    = array_merge( $post_type, (array) $post_type['options'] );
461
462
				$post_type_name = pods_v_sanitized( 'name', $post_type );
463
464
				// Labels
465
				$cpt_label    = esc_html( pods_v( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'name', $post_type ) ) ), true ) );
466
				$cpt_singular = esc_html( pods_v( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'label', $post_type, $post_type_name, null, true ) ) ), true ) );
467
468
				$cpt_labels                          = array();
469
				$cpt_labels['name']                  = $cpt_label;
470
				$cpt_labels['singular_name']         = $cpt_singular;
471
				$cpt_labels['menu_name']             = pods_v( 'menu_name', $post_type, '', true );
472
				$cpt_labels['name_admin_bar']        = pods_v( 'name_admin_bar', $post_type, '', true );
473
				$cpt_labels['add_new']               = pods_v( 'label_add_new', $post_type, '', true );
474
				$cpt_labels['add_new_item']          = pods_v( 'label_add_new_item', $post_type, '', true );
475
				$cpt_labels['new_item']              = pods_v( 'label_new_item', $post_type, '', true );
476
				$cpt_labels['edit']                  = pods_v( 'label_edit', $post_type, '', true );
477
				$cpt_labels['edit_item']             = pods_v( 'label_edit_item', $post_type, '', true );
478
				$cpt_labels['view']                  = pods_v( 'label_view', $post_type, '', true );
479
				$cpt_labels['view_item']             = pods_v( 'label_view_item', $post_type, '', true );
480
				$cpt_labels['view_items']            = pods_v( 'label_view_items', $post_type, '', true );
481
				$cpt_labels['all_items']             = pods_v( 'label_all_items', $post_type, '', true );
482
				$cpt_labels['search_items']          = pods_v( 'label_search_items', $post_type, '', true );
483
				$cpt_labels['not_found']             = pods_v( 'label_not_found', $post_type, '', true );
484
				$cpt_labels['not_found_in_trash']    = pods_v( 'label_not_found_in_trash', $post_type, '', true );
485
				$cpt_labels['parent']                = pods_v( 'label_parent', $post_type, '', true );
486
				$cpt_labels['parent_item_colon']     = pods_v( 'label_parent_item_colon', $post_type, '', true );
487
				$cpt_labels['archives']              = pods_v( 'label_archives', $post_type, '', true );
488
				$cpt_labels['attributes']            = pods_v( 'label_attributes', $post_type, '', true );
489
				$cpt_labels['insert_into_item']      = pods_v( 'label_insert_into_item', $post_type, '', true );
490
				$cpt_labels['uploaded_to_this_item'] = pods_v( 'label_uploaded_to_this_item', $post_type, '', true );
491
				$cpt_labels['featured_image']        = pods_v( 'label_featured_image', $post_type, '', true );
492
				$cpt_labels['set_featured_image']    = pods_v( 'label_set_featured_image', $post_type, '', true );
493
				$cpt_labels['remove_featured_image'] = pods_v( 'label_remove_featured_image', $post_type, '', true );
494
				$cpt_labels['use_featured_image']    = pods_v( 'label_use_featured_image', $post_type, '', true );
495
				$cpt_labels['filter_items_list']     = pods_v( 'label_filter_items_list', $post_type, '', true );
496
				$cpt_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $post_type, '', true );
497
				$cpt_labels['items_list']            = pods_v( 'label_items_list', $post_type, '', true );
498
499
				// Supported
500
				$cpt_supported = array(
501
					'title'           => (boolean) pods_v( 'supports_title', $post_type, false ),
502
					'editor'          => (boolean) pods_v( 'supports_editor', $post_type, false ),
503
					'author'          => (boolean) pods_v( 'supports_author', $post_type, false ),
504
					'thumbnail'       => (boolean) pods_v( 'supports_thumbnail', $post_type, false ),
505
					'excerpt'         => (boolean) pods_v( 'supports_excerpt', $post_type, false ),
506
					'trackbacks'      => (boolean) pods_v( 'supports_trackbacks', $post_type, false ),
507
					'custom-fields'   => (boolean) pods_v( 'supports_custom_fields', $post_type, false ),
508
					'comments'        => (boolean) pods_v( 'supports_comments', $post_type, false ),
509
					'revisions'       => (boolean) pods_v( 'supports_revisions', $post_type, false ),
510
					'page-attributes' => (boolean) pods_v( 'supports_page_attributes', $post_type, false ),
511
					'post-formats'    => (boolean) pods_v( 'supports_post_formats', $post_type, false )
512
				);
513
514
				// Custom Supported
515
				$cpt_supported_custom = pods_v_sanitized( 'supports_custom', $post_type, '' );
516
517
				if ( ! empty( $cpt_supported_custom ) ) {
518
					$cpt_supported_custom = explode( ',', $cpt_supported_custom );
519
					$cpt_supported_custom = array_filter( array_unique( $cpt_supported_custom ) );
520
521
					foreach ( $cpt_supported_custom as $cpt_support ) {
522
						$cpt_supported[ $cpt_support ] = true;
523
					}
524
				}
525
526
				// Genesis Support
527
				if ( function_exists( 'genesis' ) ) {
528
					$cpt_supported['genesis-seo']             = (boolean) pods_var( 'supports_genesis_seo', $post_type, false );
529
					$cpt_supported['genesis-layouts']         = (boolean) pods_var( 'supports_genesis_layouts', $post_type, false );
530
					$cpt_supported['genesis-simple-sidebars'] = (boolean) pods_var( 'supports_genesis_simple_sidebars', $post_type, false );
531
				}
532
533
				// YARPP Support
534
				if ( defined( 'YARPP_VERSION' ) ) {
535
					$cpt_supported['yarpp_support'] = (boolean) pods_var( 'supports_yarpp_support', $post_type, false );
536
				}
537
538
				// Jetpack Support
539
				if ( class_exists( 'Jetpack' ) ) {
540
					$cpt_supported['supports_jetpack_publicize'] = (boolean) pods_var( 'supports_jetpack_publicize', $post_type, false );
541
					$cpt_supported['supports_jetpack_markdown']  = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false );
542
				}
543
544
				// WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :(
545
				$cpt_supports = array();
546
547
				if ( ! pods_version_check( 'wp', '3.5' ) ) {
548
					$cpt_supports = array( '_bug_fix_pre_35' );
549
				}
550
551
				foreach ( $cpt_supported as $cpt_support => $supported ) {
552
					if ( true === $supported ) {
553
						$cpt_supports[] = $cpt_support;
554
555
						if ( 'post-formats' === $cpt_support ) {
556
							$post_format_post_types[] = $post_type_name;
557
						}
558
					}
559
				}
560
561
				if ( empty( $cpt_supports ) && pods_version_check( 'wp', '3.5' ) ) {
562
					$cpt_supports = false;
563
				}
564
565
				// Rewrite
566
				$cpt_rewrite       = (boolean) pods_var( 'rewrite', $post_type, true );
567
				$cpt_rewrite_array = array(
568
					'slug'       => pods_var( 'rewrite_custom_slug', $post_type, str_replace( '_', '-', $post_type_name ), null, true ),
569
					'with_front' => (boolean) pods_var( 'rewrite_with_front', $post_type, true ),
570
					'feeds'      => (boolean) pods_var( 'rewrite_feeds', $post_type, (boolean) pods_var( 'has_archive', $post_type, false ) ),
571
					'pages'      => (boolean) pods_var( 'rewrite_pages', $post_type, true )
572
				);
573
574
				if ( false !== $cpt_rewrite ) {
575
					$cpt_rewrite = $cpt_rewrite_array;
576
				}
577
578
				$capability_type = pods_var( 'capability_type', $post_type, 'post' );
579
580
				if ( 'custom' == $capability_type ) {
581
					$capability_type = pods_var( 'capability_type_custom', $post_type, 'post' );
582
				}
583
584
				$show_in_menu = (boolean) pods_var( 'show_in_menu', $post_type, true );
585
586
				if ( $show_in_menu && 0 < strlen( pods_var_raw( 'menu_location_custom', $post_type ) ) ) {
587
					$show_in_menu = pods_var_raw( 'menu_location_custom', $post_type );
588
				}
589
590
				$menu_icon = pods_var( 'menu_icon', $post_type, null, null, true );
591
592
				if ( ! empty( $menu_icon ) ) {
593
					$menu_icon = pods_evaluate_tags( $menu_icon );
594
				}
595
596
				// Register Post Type
597
				$pods_post_types[ $post_type_name ] = array(
598
					'label'               => $cpt_label,
599
					'labels'              => $cpt_labels,
600
					'description'         => esc_html( pods_var_raw( 'description', $post_type ) ),
601
					'public'              => (boolean) pods_var( 'public', $post_type, true ),
602
					'publicly_queryable'  => (boolean) pods_var( 'publicly_queryable', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
603
					'exclude_from_search' => (boolean) pods_var( 'exclude_from_search', $post_type, ( (boolean) pods_var( 'public', $post_type, true ) ? false : true ) ),
604
					'show_ui'             => (boolean) pods_var( 'show_ui', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
605
					'show_in_menu'        => $show_in_menu,
606
					'show_in_nav_menus'   => (boolean) pods_var( 'show_in_nav_menus', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
607
					'show_in_admin_bar'   => (boolean) pods_var( 'show_in_admin_bar', $post_type, (boolean) pods_var( 'show_in_menu', $post_type, true ) ),
608
					'menu_position'       => (int) pods_var( 'menu_position', $post_type, 0, null, true ),
609
					'menu_icon'           => $menu_icon,
610
					'capability_type'     => $capability_type,
611
					//'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...
612
					'map_meta_cap'        => (boolean) pods_var( 'capability_type_extra', $post_type, true ),
613
					'hierarchical'        => (boolean) pods_var( 'hierarchical', $post_type, false ),
614
					'supports'            => $cpt_supports,
615
					//'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...
616
					//'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...
617
					'has_archive'         => pods_v( 'has_archive_slug', $post_type, (boolean) pods_v( 'has_archive', $post_type, false ), true ),
618
					'rewrite'             => $cpt_rewrite,
619
					'query_var'           => ( false !== (boolean) pods_var( 'query_var', $post_type, true ) ? pods_var( 'query_var_string', $post_type, $post_type_name, null, true ) : false ),
620
					'can_export'          => (boolean) pods_var( 'can_export', $post_type, true )
621
				);
622
623
				// YARPP doesn't use 'supports' array option (yet)
624
				if ( ! empty( $cpt_supports['yarpp_support'] ) ) {
625
					$pods_post_types[ $post_type_name ]['yarpp_support'] = true;
626
				}
627
628
				// Prevent reserved query_var issues
629
				if ( in_array( $pods_post_types[ $post_type_name ]['query_var'], $reserved_query_vars ) ) {
630
					$pods_post_types[ $post_type_name ]['query_var'] = 'post_type_' . $pods_post_types[ $post_type_name ]['query_var'];
631
				}
632
633
				if ( 25 == $pods_post_types[ $post_type_name ]['menu_position'] ) {
634
					$pods_post_types[ $post_type_name ]['menu_position'] ++;
635
				}
636
637
				if ( $pods_post_types[ $post_type_name ]['menu_position'] < 1 || in_array( $pods_post_types[ $post_type_name ]['menu_position'], $cpt_positions ) ) {
638
					unset( $pods_post_types[ $post_type_name ]['menu_position'] );
639
				} else {
640
					$cpt_positions[] = $pods_post_types[ $post_type_name ]['menu_position'];
641
642
					// This would be nice if WP supported floats in menu_position
643
					// $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...
644
				}
645
646
				// Taxonomies
647
				$cpt_taxonomies = array();
648
				$_taxonomies    = get_taxonomies();
649
				$_taxonomies    = array_merge_recursive( $_taxonomies, $pods_taxonomies );
650
				$ignore         = array( 'nav_menu', 'link_category', 'post_format' );
651
652 View Code Duplication
				foreach ( $_taxonomies as $taxonomy => $label ) {
653
					if ( in_array( $taxonomy, $ignore ) ) {
654
						continue;
655
					}
656
657
					if ( false !== (boolean) pods_var( 'built_in_taxonomies_' . $taxonomy, $post_type, false ) ) {
658
						$cpt_taxonomies[] = $taxonomy;
659
660
						if ( isset( $supported_post_types[ $taxonomy ] ) && ! in_array( $post_type_name, $supported_post_types[ $taxonomy ] ) ) {
661
							$supported_post_types[ $taxonomy ][] = $post_type_name;
662
						}
663
					}
664
				}
665
666
				if ( isset( $supported_taxonomies[ $post_type_name ] ) ) {
667
					$supported_taxonomies[ $post_type_name ] = array_merge( (array) $supported_taxonomies[ $post_type_name ], $cpt_taxonomies );
668
				} else {
669
					$supported_taxonomies[ $post_type_name ] = $cpt_taxonomies;
670
				}
671
			}
672
673
			foreach ( $taxonomies as $taxonomy ) {
674
				// Taxonomy Type exists already
675 View Code Duplication
				if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) {
676
					continue;
677
				} elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) {
678
					continue;
679
				} elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) {
680
					continue;
681
				}
682
683
				$taxonomy['options']['name'] = $taxonomy['name'];
684
				$taxonomy                    = array_merge( $taxonomy, (array) $taxonomy['options'] );
685
686
				$taxonomy_name = pods_var( 'name', $taxonomy );
687
688
				// Labels
689
				$ct_label    = esc_html( pods_v( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'name', $taxonomy ) ) ), true ) );
690
				$ct_singular = esc_html( pods_v( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'label', $taxonomy, pods_v( 'name', $taxonomy ), null, true ) ) ), true ) );
691
692
				$ct_labels                               = array();
693
				$ct_labels['name']                       = $ct_label;
694
				$ct_labels['singular_name']              = $ct_singular;
695
				$ct_labels['menu_name']                  = pods_v( 'menu_name', $taxonomy, '', true );
696
				$ct_labels['search_items']               = pods_v( 'label_search_items', $taxonomy, '', true );
697
				$ct_labels['popular_items']              = pods_v( 'label_popular_items', $taxonomy, '', true );
698
				$ct_labels['all_items']                  = pods_v( 'label_all_items', $taxonomy, '', true );
699
				$ct_labels['parent_item']                = pods_v( 'label_parent_item', $taxonomy, '', true );
700
				$ct_labels['parent_item_colon']          = pods_v( 'label_parent_item_colon', $taxonomy, '', true );
701
				$ct_labels['edit_item']                  = pods_v( 'label_edit_item', $taxonomy, '', true );
702
				$ct_labels['update_item']                = pods_v( 'label_update_item', $taxonomy, '', true );
703
				$ct_labels['view_item']                  = pods_v( 'label_view_item', $taxonomy, '', true );
704
				$ct_labels['add_new_item']               = pods_v( 'label_add_new_item', $taxonomy, '', true );
705
				$ct_labels['new_item_name']              = pods_v( 'label_new_item_name', $taxonomy, '', true );
706
				$ct_labels['separate_items_with_commas'] = pods_v( 'label_separate_items_with_commas', $taxonomy, '', true );
707
				$ct_labels['add_or_remove_items']        = pods_v( 'label_add_or_remove_items', $taxonomy, '', true );
708
				$ct_labels['choose_from_most_used']      = pods_v( 'label_choose_from_the_most_used', $taxonomy, '', true );
709
				$ct_labels['not_found']                  = pods_v( 'label_not_found', $taxonomy, '', true );
710
				$ct_labels['no_terms']                   = pods_v( 'label_no_terms', $taxonomy, '', true );
711
				$ct_labels['items_list']                 = pods_v( 'label_items_list', $taxonomy, '', true );
712
				$ct_labels['items_list_navigation']      = pods_v( 'label_items_list_navigation', $taxonomy, '', true );
713
714
				// Rewrite
715
				$ct_rewrite       = (boolean) pods_var( 'rewrite', $taxonomy, true );
716
				$ct_rewrite_array = array(
717
					'slug'         => pods_var( 'rewrite_custom_slug', $taxonomy, str_replace( '_', '-', $taxonomy_name ), null, true ),
718
					'with_front'   => (boolean) pods_var( 'rewrite_with_front', $taxonomy, true ),
719
					'hierarchical' => (boolean) pods_var( 'rewrite_hierarchical', $taxonomy, (boolean) pods_var( 'hierarchical', $taxonomy, false ) )
720
				);
721
722
				if ( false !== $ct_rewrite ) {
723
					$ct_rewrite = $ct_rewrite_array;
724
				}
725
726
				/**
727
				 * Default tax capabilities
728
				 * @see https://codex.wordpress.org/Function_Reference/register_taxonomy
729
				 */
730
				$capability_type = pods_var( 'capability_type', $taxonomy, 'default' );
731
				$tax_capabilities = array();
732
733
				if ( 'custom' == $capability_type ) {
734
					$capability_type = pods_var( 'capability_type_custom', $taxonomy, 'default' );
735
					if ( ! empty( $capability_type ) && 'default' != $capability_type ) {
736
						$capability_type .=  '_term';
737
						$capability_type_plural =  $capability_type . 's';
738
						$tax_capabilities = array(
739
							// Singular
740
							'edit_term'   => 'edit_' . $capability_type,
741
							'delete_term' => 'delete_' . $capability_type,
742
							'assign_term' => 'assign_' . $capability_type,
743
							// Plural
744
							'manage_terms' => 'manage_' . $capability_type_plural,
745
							'edit_terms'   => 'edit_' . $capability_type_plural,
746
							'delete_terms' => 'delete_' . $capability_type_plural,
747
							'assign_terms' => 'assign_' . $capability_type_plural,
748
						);
749
					}
750
				}
751
752
				// Register Taxonomy
753
				$pods_taxonomies[ $taxonomy_name ] = array(
754
					'label'                 => $ct_label,
755
					'labels'                => $ct_labels,
756
					'public'                => (boolean) pods_var( 'public', $taxonomy, true ),
757
					'show_ui'               => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
758
					'show_in_menu'          => (boolean) pods_var( 'show_in_menu', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
759
					'show_in_nav_menus'     => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
760
					'show_tagcloud'         => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
761
					'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 ) ) ) ),
762
					'show_in_quick_edit'    => (boolean) pods_var( 'show_in_quick_edit', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
763
					'hierarchical'          => (boolean) pods_var( 'hierarchical', $taxonomy, false ),
764
					//'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...
765
					'capabilities'          => $tax_capabilities,
766
					//'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...
767
					'update_count_callback' => pods_var( 'update_count_callback', $taxonomy, null, null, true ),
768
					'query_var'             => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ),
769
					'rewrite'               => $ct_rewrite,
770
					'show_admin_column'     => (boolean) pods_var( 'show_admin_column', $taxonomy, false ),
771
					'sort'                  => (boolean) pods_var( 'sort', $taxonomy, false ),
772
				);
773
774
				if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) {
775
					$pods_taxonomies[ $taxonomy_name ]['query_var'] = pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true );
776
				};
777
778
				// Prevent reserved query_var issues
779
				if ( in_array( $pods_taxonomies[ $taxonomy_name ]['query_var'], $reserved_query_vars ) ) {
780
					$pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var'];
781
				}
782
783
				// Integration for Single Value Taxonomy UI
784
				if ( function_exists( 'tax_single_value_meta_box' ) ) {
785
					$pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false );
786
					$pods_taxonomies[ $taxonomy_name ]['required']     = (boolean) pods_var( 'single_value_required', $taxonomy, false );
787
				}
788
789
				// Post Types
790
				$ct_post_types = array();
791
				$_post_types   = get_post_types();
792
				$_post_types   = array_merge_recursive( $_post_types, $pods_post_types );
793
				$ignore        = array( 'revision' );
794
795 View Code Duplication
				foreach ( $_post_types as $post_type => $options ) {
796
					if ( in_array( $post_type, $ignore ) ) {
797
						continue;
798
					}
799
800
					if ( false !== (boolean) pods_var( 'built_in_post_types_' . $post_type, $taxonomy, false ) ) {
801
						$ct_post_types[] = $post_type;
802
803
						if ( isset( $supported_taxonomies[ $post_type ] ) && ! in_array( $taxonomy_name, $supported_taxonomies[ $post_type ] ) ) {
804
							$supported_taxonomies[ $post_type ][] = $taxonomy_name;
805
						}
806
					}
807
				}
808
809
				if ( isset( $supported_post_types[ $taxonomy_name ] ) ) {
810
					$supported_post_types[ $taxonomy_name ] = array_merge( $supported_post_types[ $taxonomy_name ], $ct_post_types );
811
				} else {
812
					$supported_post_types[ $taxonomy_name ] = $ct_post_types;
813
				}
814
			}
815
816
			$pods_post_types = apply_filters( 'pods_wp_post_types', $pods_post_types );
817
			$pods_taxonomies = apply_filters( 'pods_wp_taxonomies', $pods_taxonomies );
818
819
			$supported_post_types = apply_filters( 'pods_wp_supported_post_types', $supported_post_types );
820
			$supported_taxonomies = apply_filters( 'pods_wp_supported_taxonomies', $supported_taxonomies );
821
822
			foreach ( $pods_taxonomies as $taxonomy => $options ) {
823
				$ct_post_types = null;
824
825
				if ( isset( $supported_post_types[ $taxonomy ] ) && ! empty( $supported_post_types[ $taxonomy ] ) ) {
826
					$ct_post_types = $supported_post_types[ $taxonomy ];
827
				}
828
829
				$pods_cpt_ct['taxonomies'][ $taxonomy ] = array(
830
					'post_types' => $ct_post_types,
831
					'options'    => $options
832
				);
833
			}
834
835
			foreach ( $pods_post_types as $post_type => $options ) {
836
				if ( isset( $supported_taxonomies[ $post_type ] ) && ! empty( $supported_taxonomies[ $post_type ] ) ) {
837
					$options['taxonomies'] = $supported_taxonomies[ $post_type ];
838
				}
839
840
				$pods_cpt_ct['post_types'][ $post_type ] = $options;
841
			}
842
843
			$pods_cpt_ct['post_format_post_types'] = $post_format_post_types;
844
845
			pods_transient_set( 'pods_wp_cpt_ct', $pods_cpt_ct );
846
		}
847
848
		foreach ( $pods_cpt_ct['taxonomies'] as $taxonomy => $options ) {
849
			if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy, self::$content_types_registered['taxonomies'] ) ) {
850
				continue;
851
			}
852
853
			$ct_post_types = $options['post_types'];
854
			$options       = $options['options'];
855
856
			$options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy );
857
			$options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy );
858
859
			$options = self::object_label_fix( $options, 'taxonomy' );
860
861
			/**
862
			 * Hide tagcloud compatibility
863
			 * @todo check https://core.trac.wordpress.org/ticket/36964
864
			 * @see wp-admin/edit-tags.php L389
865
			 */
866
			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...
867
				$options['labels']['popular_items'] = null;
868
			}
869
870
			// Max length for taxonomies are 32 characters
871
			$taxonomy = substr( $taxonomy, 0, 32 );
872
873
			// i18n compatibility for plugins that override it
874 View Code Duplication
			if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) {
875
				$options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' );
876
			}
877
878 View Code Duplication
			if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
879
				pods_debug( array( $taxonomy, $ct_post_types, $options ) );
880
			}
881
882
			register_taxonomy( $taxonomy, $ct_post_types, $options );
883
884
			if ( ! isset( self::$content_types_registered['taxonomies'] ) ) {
885
				self::$content_types_registered['taxonomies'] = array();
886
			}
887
888
			self::$content_types_registered['taxonomies'][] = $taxonomy;
889
		}
890
891
		foreach ( $pods_cpt_ct['post_types'] as $post_type => $options ) {
892
			if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type, self::$content_types_registered['post_types'] ) ) {
893
				continue;
894
			}
895
896
			$options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type );
897
			$options = apply_filters( 'pods_register_post_type', $options, $post_type );
898
899
			$options = self::object_label_fix( $options, 'post_type' );
900
901
			// Max length for post types are 20 characters
902
			$post_type = substr( $post_type, 0, 20 );
903
904
			// i18n compatibility for plugins that override it
905 View Code Duplication
			if ( is_array( $options['rewrite'] ) && isset( $options['rewrite']['slug'] ) && ! empty( $options['rewrite']['slug'] ) ) {
906
				$options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' );
907
			}
908
909 View Code Duplication
			if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
910
				pods_debug( array( $post_type, $options ) );
911
			}
912
913
			register_post_type( $post_type, $options );
914
915
			// Register post format taxonomy for this post type
916
			if ( isset( $pods_cpt_ct['post_format_post_types'] ) && in_array( $post_type, $pods_cpt_ct['post_format_post_types'], true ) ) {
917
				register_taxonomy_for_object_type( 'post_format', $post_type );
918
			}
919
920
			if ( ! isset( self::$content_types_registered['post_types'] ) ) {
921
				self::$content_types_registered['post_types'] = array();
922
			}
923
924
			self::$content_types_registered['post_types'][] = $post_type;
925
		}
926
927
	}
928
929
	/**
930
	 * Check if we need to flush WordPress rewrite rules
931
	 * This gets run during 'init' action late in the game to give other plugins time to register their rewrite rules
932
	 */
933
	public function flush_rewrite_rules() {
934
935
		$flush = (int) pods_transient_get( 'pods_flush_rewrites' );
936
937
		if ( 1 === $flush ) {
938
			/**
939
			 * @var $wp_rewrite WP_Rewrite
940
			 */
941
			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...
942
			$wp_rewrite->flush_rules();
943
			$wp_rewrite->init();
944
945
			pods_transient_set( 'pods_flush_rewrites', 0 );
946
		}
947
	}
948
949
	/**
950
	 * Update Post Type messages
951
	 *
952
	 * @param array $messages
953
	 *
954
	 * @return array
955
	 * @since 2.0.2
956
	 */
957
	public function setup_updated_messages( $messages ) {
958
959
		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...
960
961
		$post_types          = PodsMeta::$post_types;
962
		$existing_post_types = get_post_types();
963
964
		$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
965
966
		if ( empty( $pods_cpt_ct ) || empty( $post_types ) ) {
967
			return $messages;
968
		}
969
970
		/**
971
		 * Use get_preview_post_link function added in 4.4, which eventually applies preview_post_link filter
972
		 * Before 4.4, this filter is defined in wp-admin/includes/meta-boxes.php, $post parameter added in 4.0
973
		 * there wasn't post parameter back in 3.8
974
		 * Let's add $post in the filter as it won't hurt anyway.
975
		 * @since 2.6.8.1
976
		*/
977
		$preview_post_link = function_exists( 'get_preview_post_link' )
978
									? get_preview_post_link( $post )
979
									: apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ), $post );
980
981
		foreach ( $post_types as $post_type ) {
982
			if ( ! isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
983
				continue;
984
			}
985
986
			$labels = self::object_label_fix( $pods_cpt_ct['post_types'][ $post_type['name'] ], 'post_type' );
987
			$labels = $labels['labels'];
988
989
			$messages[ $post_type['name'] ] = array(
990
				1  => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ),
991
				2  => __( 'Custom field updated.', 'pods' ),
992
				3  => __( 'Custom field deleted.', 'pods' ),
993
				4  => sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] ),
994
				/* translators: %s: date and time of the revision */
995
				5  => isset( $_GET['revision'] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels['singular_name'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
996
				6  => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels['singular_name'], esc_url( get_permalink( $post_ID ) ), $labels['view_item'] ),
997
				7  => sprintf( __( '%s saved.', 'pods' ), $labels['singular_name'] ),
998
				8  => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels['singular_name'], esc_url( $preview_post_link ), $labels['singular_name'] ),
999
				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
1000
					date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $labels['singular_name'] ),
1001
				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'] )
1002
			);
1003
1004
			if ( false === (boolean) $pods_cpt_ct['post_types'][ $post_type['name'] ]['public'] ) {
1005
				$messages[ $post_type['name'] ][1]  = sprintf( __( '%s updated.', 'pods' ), $labels['singular_name'] );
1006
				$messages[ $post_type['name'] ][6]  = sprintf( __( '%s published.', 'pods' ), $labels['singular_name'] );
1007
				$messages[ $post_type['name'] ][8]  = sprintf( __( '%s submitted.', 'pods' ), $labels['singular_name'] );
1008
				$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
1009
					date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) );
1010
				$messages[ $post_type['name'] ][10] = sprintf( __( '%s draft updated.', 'pods' ), $labels['singular_name'] );
1011
			}
1012
		}
1013
1014
		return $messages;
1015
	}
1016
1017
	/**
1018
	 * @param        $args
1019
	 * @param string $type
1020
	 *
1021
	 * @return array
1022
	 */
1023
	public static function object_label_fix( $args, $type = 'post_type' ) {
1024
1025
		if ( empty( $args ) || ! is_array( $args ) ) {
1026
			$args = array();
1027
		}
1028
1029
		if ( ! isset( $args['labels'] ) || ! is_array( $args['labels'] ) ) {
1030
			$args['labels'] = array();
1031
		}
1032
1033
		$label          = pods_v( 'name', $args['labels'], pods_v( 'label', $args, __( 'Items', 'pods' ), true ), true );
1034
		$singular_label = pods_v( 'singular_name', $args['labels'], pods_v( 'label_singular', $args, __( 'Item', 'pods' ), true ), true );
1035
1036
		$labels = $args['labels'];
1037
1038
		$labels['name']          = $label;
1039
		$labels['singular_name'] = $singular_label;
1040
1041
		if ( 'post_type' == $type ) {
1042
			$labels['menu_name']             = pods_v( 'menu_name', $labels, $label, true );
1043
			$labels['name_admin_bar']        = pods_v( 'name_admin_bar', $labels, $singular_label, true );
1044
			$labels['add_new']               = pods_v( 'add_new', $labels, __( 'Add New', 'pods' ), true );
1045
			$labels['add_new_item']          = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1046
			$labels['new_item']              = pods_v( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), true );
1047
			$labels['edit']                  = pods_v( 'edit', $labels, __( 'Edit', 'pods' ), true );
1048
			$labels['edit_item']             = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1049
			$labels['view']                  = pods_v( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1050
			$labels['view_item']             = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1051
			$labels['view_items']            = pods_v( 'view_items', $labels, sprintf( __( 'View %s', 'pods' ), $label ), true );
1052
			$labels['all_items']             = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1053
			$labels['search_items']          = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1054
			$labels['not_found']             = pods_v( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), true );
1055
			$labels['not_found_in_trash']    = pods_v( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), true );
1056
			$labels['parent']                = pods_v( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1057
			$labels['parent_item_colon']     = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), true );
1058
			$labels['featured_image']        = pods_v( 'featured_image', $labels, __( 'Featured Image', 'pods' ), true );
1059
			$labels['set_featured_image']    = pods_v( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), true );
1060
			$labels['remove_featured_image'] = pods_v( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), true );
1061
			$labels['use_featured_image']    = pods_v( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), true );
1062
			$labels['archives']              = pods_v( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), true );
1063
			$labels['attributes']            = pods_v( 'attributes', $labels, sprintf( __( '%s Attributes', 'pods' ), $singular_label ), true );
1064
			$labels['insert_into_item']      = pods_v( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), true );
1065
			$labels['uploaded_to_this_item'] = pods_v( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), true );
1066
			$labels['filter_items_list']     = pods_v( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), true );
1067
			$labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1068
			$labels['items_list']            = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1069
		} elseif ( 'taxonomy' == $type ) {
1070
			$labels['menu_name']                  = pods_v( 'menu_name', $labels, $label, true );
1071
			$labels['search_items']               = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1072
			$labels['popular_items']              = pods_v( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), true );
1073
			$labels['all_items']                  = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1074
			$labels['parent_item']                = pods_v( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1075
			$labels['parent_item_colon']          = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), true );
1076
			$labels['edit_item']                  = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1077
			$labels['view_item']                  = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1078
			$labels['update_item']                = pods_v( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), true );
1079
			$labels['add_new_item']               = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1080
			$labels['new_item_name']              = pods_v( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), true );
1081
			$labels['separate_items_with_commas'] = pods_v( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), true );
1082
			$labels['add_or_remove_items']        = pods_v( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), true );
1083
			$labels['choose_from_most_used']      = pods_v( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), true );
1084
			$labels['not_found']                  = pods_v( 'not_found', $labels, sprintf( __( 'No %s found.', 'pods' ), $label ), true );
1085
			$labels['no_terms']                   = pods_v( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), true );
1086
			$labels['items_list_navigation']      = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1087
			$labels['items_list']                 = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1088
		}
1089
1090
		$args['labels'] = $labels;
1091
1092
		return $args;
1093
	}
1094
1095
	/**
1096
	 * Activate and Install
1097
	 */
1098
	public function activate_install() {
1099
1100
		register_activation_hook( PODS_DIR . 'init.php', array( $this, 'activate' ) );
1101
		register_deactivation_hook( PODS_DIR . 'init.php', array( $this, 'deactivate' ) );
1102
1103
		add_action( 'wpmu_new_blog', array( $this, 'new_blog' ), 10, 6 );
1104
1105
		if ( empty( self::$version ) || version_compare( self::$version, PODS_VERSION, '<' ) || version_compare( self::$version, PODS_DB_VERSION, '<=' ) || self::$upgrade_needed ) {
1106
			$this->setup();
1107
		} elseif ( self::$version !== PODS_VERSION ) {
1108
			delete_option( 'pods_framework_version' );
1109
			add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
1110
1111
			self::$version = PODS_VERSION;
1112
1113
			pods_api()->cache_flush_pods();
1114
		}
1115
1116
	}
1117
1118
	/**
1119
	 *
1120
	 */
1121
	public function activate() {
1122
1123
		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...
1124
1125
		if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && 1 == $_GET['networkwide'] ) {
1126
			$_blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `{$wpdb->blogs}`" );
1127
1128
			foreach ( $_blog_ids as $_blog_id ) {
1129
				$this->setup( $_blog_id );
1130
			}
1131
		} else {
1132
			$this->setup();
1133
		}
1134
	}
1135
1136
	/**
1137
	 *
1138
	 */
1139
	public function deactivate() {
1140
1141
		pods_api()->cache_flush_pods();
1142
1143
	}
1144
1145
	/**
1146
	 *
1147
	 */
1148
	public function needs_upgrade( $current = null, $last = null ) {
1149
1150
		if ( null === $current ) {
1151
			$current = self::$version;
1152
		}
1153
1154
		if ( null === $last ) {
1155
			$last = self::$version_last;
1156
		}
1157
1158
		$upgrade_needed = false;
1159
1160
		if ( ! empty( $current ) ) {
1161
			foreach ( self::$upgrades as $old_version => $new_version ) {
1162
				/*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...
1163
					continue;*/
1164
1165
				if ( version_compare( $last, $old_version, '>=' ) && version_compare( $last, $new_version, '<' ) && version_compare( $current, $new_version, '>=' ) && 1 != self::$upgraded ) {
1166
					$upgrade_needed = true;
1167
1168
					break;
1169
				}
1170
			}
1171
		}
1172
1173
		return $upgrade_needed;
1174
	}
1175
1176
	/**
1177
	 * @param $_blog_id
1178
	 * @param $user_id
1179
	 * @param $domain
1180
	 * @param $path
1181
	 * @param $site_id
1182
	 * @param $meta
1183
	 */
1184
	public function new_blog( $_blog_id, $user_id, $domain, $path, $site_id, $meta ) {
1185
1186
		if ( function_exists( 'is_multisite' ) && is_multisite() && is_plugin_active_for_network( basename( PODS_DIR ) . '/init.php' ) ) {
1187
			$this->setup( $_blog_id );
1188
		}
1189
	}
1190
1191
	/**
1192
	 * @param null $_blog_id
1193
	 */
1194
	public function setup( $_blog_id = null ) {
1195
1196
		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...
1197
1198
		// Switch DB table prefixes
1199 View Code Duplication
		if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) {
1200
			switch_to_blog( pods_absint( $_blog_id ) );
1201
		} else {
1202
			$_blog_id = null;
1203
		}
1204
1205
		// Setup DB tables
1206
		$pods_version      = get_option( 'pods_framework_version' );
1207
		$pods_version_last = get_option( 'pods_framework_version_last' );
1208
1209
		// Install Pods
1210
		if ( empty( $pods_version ) ) {
1211
			pods_upgrade()->install( $_blog_id );
1212
1213
			$old_version = get_option( 'pods_version' );
1214
1215
			if ( ! empty( $old_version ) ) {
1216
				if ( false === strpos( $old_version, '.' ) ) {
1217
					$old_version = pods_version_to_point( $old_version );
1218
				}
1219
1220
				delete_option( 'pods_framework_version_last' );
1221
				add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
1222
1223
				self::$version_last = $old_version;
1224
			}
1225
		} // Upgrade Wizard needed
1226
		elseif ( $this->needs_upgrade( $pods_version, $pods_version_last ) ) {
1227
			// Do not do anything
1228
			return;
1229
		} // Update Pods and run any required DB updates
1230
		elseif ( version_compare( $pods_version, PODS_VERSION, '<=' ) ) {
1231
			if ( false !== apply_filters( 'pods_update_run', null, PODS_VERSION, $pods_version, $_blog_id ) && ! isset( $_GET['pods_bypass_update'] ) ) {
1232
				do_action( 'pods_update', PODS_VERSION, $pods_version, $_blog_id );
1233
1234
				// Update 2.0 alpha / beta sites
1235
				if ( version_compare( '2.0.0-a-1', $pods_version, '<=' ) && version_compare( $pods_version, '2.0.0-b-15', '<=' ) ) {
1236
					include( PODS_DIR . 'sql/update-2.0-beta.php' );
1237
				}
1238
1239
				if ( version_compare( $pods_version, PODS_DB_VERSION, '<=' ) ) {
1240
					include( PODS_DIR . 'sql/update.php' );
1241
				}
1242
1243
				do_action( 'pods_update_post', PODS_VERSION, $pods_version, $_blog_id );
1244
			}
1245
1246
			delete_option( 'pods_framework_version_last' );
1247
			add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
1248
1249
			self::$version_last = $pods_version;
1250
		}
1251
1252
		delete_option( 'pods_framework_version' );
1253
		add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
1254
1255
		delete_option( 'pods_framework_db_version' );
1256
		add_option( 'pods_framework_db_version', PODS_DB_VERSION, '', 'yes' );
1257
1258
		self::$version = PODS_VERSION;
1259
		self::$db_version = PODS_DB_VERSION;
1260
1261
		pods_api()->cache_flush_pods();
1262
1263
		// Restore DB table prefix (if switched)
1264
		if ( null !== $_blog_id ) {
1265
			restore_current_blog();
1266
		}
1267
1268
	}
1269
1270
	/**
1271
	 * @param null $_blog_id
1272
	 */
1273
	public function reset( $_blog_id = null ) {
1274
1275
		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...
1276
1277
		// Switch DB table prefixes
1278 View Code Duplication
		if ( null !== $_blog_id && $_blog_id != $wpdb->blogid ) {
1279
			switch_to_blog( pods_absint( $_blog_id ) );
1280
		} else {
1281
			$_blog_id = null;
1282
		}
1283
1284
		$api = pods_api();
1285
1286
		$pods = $api->load_pods( array( 'names_ids' => true, 'table_info' => false ) );
1287
1288
		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...
1289
			$api->delete_pod( array( 'id' => $pod_id ) );
1290
		}
1291
1292
		$templates = $api->load_templates();
1293
1294
		foreach ( $templates as $template ) {
1295
			$api->delete_template( array( 'id' => $template['id'] ) );
1296
		}
1297
1298
		$pages = $api->load_pages();
1299
1300
		foreach ( $pages as $page ) {
1301
			$api->delete_page( array( 'id' => $page['id'] ) );
1302
		}
1303
1304
		$helpers = $api->load_helpers();
1305
1306
		foreach ( $helpers as $helper ) {
1307
			$api->delete_helper( array( 'id' => $helper['id'] ) );
1308
		}
1309
1310
		$tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pods%'", ARRAY_N );
1311
1312
		if ( ! empty( $tables ) ) {
1313
			foreach ( $tables as $table ) {
1314
				$table = $table[0];
1315
1316
				pods_query( "DROP TABLE `{$table}`", false );
1317
			}
1318
		}
1319
1320
		// Remove any orphans
1321
		$wpdb->query( "
1322
                DELETE `p`, `pm`
1323
                FROM `{$wpdb->posts}` AS `p`
1324
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1325
                    ON `pm`.`post_id` = `p`.`ID`
1326
                WHERE
1327
                    `p`.`post_type` LIKE '_pods_%'
1328
            " );
1329
1330
		delete_option( 'pods_framework_version' );
1331
		delete_option( 'pods_framework_db_version' );
1332
		delete_option( 'pods_framework_upgrade_2_0' );
1333
		delete_option( 'pods_framework_upgraded_1_x' );
1334
1335
		// @todo Make sure all entries are being cleaned and do something about the pods_framework_upgrade_{version} dynamic entries created by PodsUpgrade
1336
		delete_option( 'pods_framework_upgrade_2_0_0' );
1337
		delete_option( 'pods_framework_upgrade_2_0_sister_ids' );
1338
		delete_option( 'pods_framework_version_last' );
1339
1340
		delete_option( 'pods_component_settings' );
1341
1342
		$api->cache_flush_pods();
1343
1344
		pods_transient_clear( 'pods_flush_rewrites' );
1345
1346
		self::$version = '';
1347
1348
		// Restore DB table prefix (if switched)
1349
		if ( null !== $_blog_id ) {
1350
			restore_current_blog();
1351
		}
1352
	}
1353
1354
	public function run() {
1355
1356
		static $ran;
1357
1358
		if ( ! empty( $ran ) ) {
1359
			return;
1360
		}
1361
1362
		$ran = true;
1363
1364
		$this->load_i18n();
1365
1366
		if ( ! did_action( 'plugins_loaded' ) ) {
1367
			add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 );
1368
		} else {
1369
			$this->load_components();
1370
		}
1371
1372
		if ( ! did_action( 'setup_theme' ) ) {
1373
			add_action( 'setup_theme', array( $this, 'load_meta' ), 14 );
1374
		} else {
1375
			$this->load_meta();
1376
		}
1377
1378
		if ( ! did_action( 'init' ) ) {
1379
			add_action( 'init', array( $this, 'core' ), 11 );
1380
			add_action( 'init', array( $this, 'add_rest_support' ), 12 );
1381
			add_action( 'init', array( $this, 'setup_content_types' ), 11 );
1382
1383
			if ( is_admin() ) {
1384
				add_action( 'init', array( $this, 'admin_init' ), 12 );
1385
			}
1386
		} else {
1387
			$this->core();
1388
			$this->add_rest_support();
1389
			$this->setup_content_types();
1390
1391
			if ( is_admin() ) {
1392
				$this->admin_init();
1393
			}
1394
		}
1395
1396
		add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1397
		add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1398
		add_action( 'login_enqueue_scripts', array( $this, 'register_assets' ), 15 );
1399
1400
		add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
1401
		add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
1402
1403
		// Register widgets
1404
		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
1405
1406
		// Show admin bar links
1407
		add_action( 'admin_bar_menu', array( $this, 'admin_bar_links' ), 81 );
1408
1409
	}
1410
1411
	/**
1412
	 * Delete Attachments from relationships
1413
	 *
1414
	 * @param int $_ID
1415
	 */
1416
	public function delete_attachment( $_ID ) {
1417
1418
		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...
1419
1420
		$_ID = (int) $_ID;
1421
1422
		do_action( 'pods_delete_attachment', $_ID );
1423
1424
		$file_types = "'" . implode( "', '", PodsForm::file_field_types() ) . "'";
1425
1426
		if ( ! pods_tableless() ) {
1427
			$sql = "
1428
                DELETE `rel`
1429
                FROM `@wp_podsrel` AS `rel`
1430
                LEFT JOIN `{$wpdb->posts}` AS `p`
1431
                    ON
1432
                        `p`.`post_type` = '_pods_field'
1433
                        AND ( `p`.`ID` = `rel`.`field_id` OR `p`.`ID` = `rel`.`related_field_id` )
1434
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1435
                    ON
1436
                        `pm`.`post_id` = `p`.`ID`
1437
                        AND `pm`.`meta_key` = 'type'
1438
                        AND `pm`.`meta_value` IN ( {$file_types} )
1439
                WHERE
1440
                    `p`.`ID` IS NOT NULL
1441
                    AND `pm`.`meta_id` IS NOT NULL
1442
                    AND `rel`.`item_id` = {$_ID}";
1443
1444
			pods_query( $sql, false );
1445
		}
1446
1447
		// Post Meta
1448 View Code Duplication
		if ( ! empty( PodsMeta::$post_types ) ) {
1449
			$sql = "
1450
                DELETE `rel`
1451
                FROM `@wp_postmeta` AS `rel`
1452
                LEFT JOIN `{$wpdb->posts}` AS `p`
1453
                    ON
1454
                        `p`.`post_type` = '_pods_field'
1455
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1456
                    ON
1457
                        `pm`.`post_id` = `p`.`ID`
1458
                        AND `pm`.`meta_key` = 'type'
1459
                        AND `pm`.`meta_value` IN ( {$file_types} )
1460
                WHERE
1461
                    `p`.`ID` IS NOT NULL
1462
                    AND `pm`.`meta_id` IS NOT NULL
1463
                    AND `rel`.`meta_key` = `p`.`post_name`
1464
                    AND `rel`.`meta_value` = '{$_ID}'";
1465
1466
			pods_query( $sql, false );
1467
		}
1468
1469
		// User Meta
1470 View Code Duplication
		if ( ! empty( PodsMeta::$user ) ) {
1471
			$sql = "
1472
                DELETE `rel`
1473
                FROM `@wp_usermeta` AS `rel`
1474
                LEFT JOIN `{$wpdb->posts}` AS `p`
1475
                    ON
1476
                        `p`.`post_type` = '_pods_field'
1477
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1478
                    ON
1479
                        `pm`.`post_id` = `p`.`ID`
1480
                        AND `pm`.`meta_key` = 'type'
1481
                        AND `pm`.`meta_value` IN ( {$file_types} )
1482
                WHERE
1483
                    `p`.`ID` IS NOT NULL
1484
                    AND `pm`.`meta_id` IS NOT NULL
1485
                    AND `rel`.`meta_key` = `p`.`post_name`
1486
                    AND `rel`.`meta_value` = '{$_ID}'";
1487
1488
			pods_query( $sql, false );
1489
		}
1490
1491
		// Comment Meta
1492 View Code Duplication
		if ( ! empty( PodsMeta::$comment ) ) {
1493
			$sql = "
1494
                DELETE `rel`
1495
                FROM `@wp_commentmeta` AS `rel`
1496
                LEFT JOIN `{$wpdb->posts}` AS `p`
1497
                    ON
1498
                        `p`.`post_type` = '_pods_field'
1499
                LEFT JOIN `{$wpdb->postmeta}` AS `pm`
1500
                    ON
1501
                        `pm`.`post_id` = `p`.`ID`
1502
                        AND `pm`.`meta_key` = 'type'
1503
                        AND `pm`.`meta_value` IN ( {$file_types} )
1504
                WHERE
1505
                    `p`.`ID` IS NOT NULL
1506
                    AND `pm`.`meta_id` IS NOT NULL
1507
                    AND `rel`.`meta_key` = `p`.`post_name`
1508
                    AND `rel`.`meta_value` = '{$_ID}'";
1509
1510
			pods_query( $sql, false );
1511
		}
1512
	}
1513
1514
	/**
1515
	 * Register widgets for Pods
1516
	 */
1517
	public function register_widgets() {
1518
1519
		$widgets = array(
1520
			'PodsWidgetSingle',
1521
			'PodsWidgetList',
1522
			'PodsWidgetField',
1523
			'PodsWidgetForm',
1524
			'PodsWidgetView'
1525
		);
1526
1527
		foreach ( $widgets as $widget ) {
1528
			if ( ! file_exists( PODS_DIR . 'classes/widgets/' . $widget . '.php' ) ) {
1529
				continue;
1530
			}
1531
1532
			require_once PODS_DIR . 'classes/widgets/' . $widget . '.php';
1533
1534
			register_widget( $widget );
1535
		}
1536
	}
1537
1538
	/**
1539
	 * Add Admin Bar links
1540
	 */
1541
	public function admin_bar_links() {
1542
1543
		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...
1544
1545
		if ( ! is_user_logged_in() || ! is_admin_bar_showing() ) {
1546
			return;
1547
		}
1548
1549
		$all_pods = pods_api()->load_pods( array( 'type' => 'pod', 'fields' => false, 'table_info' => false ) );
1550
1551
		// Add New item links for all pods
1552
		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...
1553
			if ( 0 == $pod['options']['show_in_menu'] ) {
1554
				continue;
1555
			}
1556
1557
			if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod['name'] ) ) ) {
1558
				continue;
1559
			}
1560
1561
			$singular_label = pods_var_raw( 'label_singular', $pod['options'], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), null, true ), null, true );
1562
1563
			$wp_admin_bar->add_node( array(
1564
				'id'     => 'new-pod-' . $pod['name'],
1565
				'title'  => $singular_label,
1566
				'parent' => 'new-content',
1567
				'href'   => admin_url( 'admin.php?page=pods-manage-' . $pod['name'] . '&action=add' )
1568
			) );
1569
		}
1570
1571
		// Add edit link if we're on a pods page
1572
		if ( is_object( $pods ) && ! is_wp_error( $pods ) && ! empty( $pods->id ) && isset( $pods->pod_data ) && ! empty( $pods->pod_data ) && 'pod' == $pods->pod_data['type'] ) {
1573
			$pod = $pods->pod_data;
1574
1575
			if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
1576
				$singular_label = pods_var_raw( 'label_singular', $pod['options'], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), null, true ), null, true );
1577
1578
				$wp_admin_bar->add_node( array(
1579
					'title' => sprintf( __( 'Edit %s', 'pods' ), $singular_label ),
1580
					'id'    => 'edit-pod',
1581
					'href'  => admin_url( 'admin.php?page=pods-manage-' . $pod['name'] . '&action=edit&id=' . $pods->id() )
1582
				) );
1583
			}
1584
		}
1585
1586
	}
1587
1588
	/**
1589
	 * Add REST API support to post type and taxonomy objects.
1590
	 *
1591
	 * @uses  "init"
1592
	 *
1593
	 * @since 2.5.6
1594
	 */
1595
	public function add_rest_support() {
1596
1597
		if ( empty( self::$version ) ) {
1598
			return;
1599
		}
1600
1601
		static $rest_support_added;
1602
1603
		if ( ! function_exists( 'register_rest_field' ) ) {
1604
			return;
1605
		}
1606
1607
		include_once( PODS_DIR . 'classes/PodsRESTFields.php' );
1608
		include_once( PODS_DIR . 'classes/PodsRESTHandlers.php' );
1609
1610
		$rest_bases = pods_transient_get( 'pods_rest_bases' );
1611
1612
		if ( empty( $rest_bases ) ) {
1613
	        $pods = pods_api()->load_pods( array( 'type' => array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ), 'fields' => false, 'table_info' => false ) );
1614
1615
			$rest_bases = array();
1616
1617
			if ( ! empty( $pods ) && is_array( $pods ) ) {
1618
				foreach ( $pods as $pod ) {
1619
					$type = $pod['type'];
1620
1621
					if ( in_array( $type, array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ) ) ) {
1622
						if ( $pod && PodsRESTHandlers::pod_extends_core_route( $pod ) ) {
1623
							$rest_bases[ $pod['name'] ] = array(
1624
								'type' => $type,
1625
								'base' => sanitize_title( pods_v( 'rest_base', $pod['options'], $pod['name'] ) ),
1626
							);
1627
						}
1628
					}
1629
				}
1630
			}
1631
1632
			if ( empty( $rest_bases ) ) {
1633
				$rest_bases = 'none';
1634
			}
1635
1636
			pods_transient_set( 'pods_rest_bases', $rest_bases );
1637
		}
1638
1639
		if ( empty( $rest_support_added ) && ! empty( $rest_bases ) && 'none' !== $rest_bases ) {
1640
			foreach ( $rest_bases as $pod_name => $pod_info ) {
1641
				$pod_type  = $pod_info['type'];
1642
				$rest_base = $pod_info['base'];
1643
1644
				if ( 'post_type' == $pod_type ) {
1645
					PodsRESTHandlers::post_type_rest_support( $pod_name, $rest_base );
1646
				} elseif ( 'taxonomy' == $pod_type ) {
1647
					PodsRESTHandlers::taxonomy_rest_support( $pod_name, $rest_base );
1648
				}
1649
1650
				new PodsRESTFields( $pod_name );
1651
			}
1652
1653
			$rest_support_added = true;
1654
		}
1655
1656
	}
1657
}
1658