Completed
Push — 2.x ( 54cff4...49c3aa )
by Scott Kingsley
11s
created

general.php ➔ pods_error()   F

Complexity

Conditions 29
Paths 2240

Size

Total Lines 121
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 29
eloc 65
nc 2240
nop 2
dl 0
loc 121
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 95.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

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

Loading history...
2
/**
3
 * @package Pods\Global\Functions\General
4
 */
5
/**
6
 * Standardize queries and error reporting. It replaces @wp_ with $wpdb->prefix.
7
 *
8
 * @see PodsData::query
9
 *
10
 * @param string $sql SQL Query
11
 * @param string $error (optional) The failure message
12
 * @param string $results_error (optional) Throw an error if a records are found
13
 * @param string $no_results_error (optional) Throw an error if no records are found
14
 *
15
 * @return array|bool|mixed|null|void
16
 * @since 2.0
17
 */
18
function pods_query ( $sql, $error = 'Database Error', $results_error = null, $no_results_error = null ) {
19
    $podsdata = pods_data();
20
21
    $sql = apply_filters( 'pods_query_sql', $sql, $error, $results_error, $no_results_error );
22
    $sql = $podsdata->get_sql($sql);
23
24 View Code Duplication
    if ( is_array( $error ) ) {
25
        if ( !is_array( $sql ) )
26
            $sql = array( $sql, $error );
27
28
        $error = 'Database Error';
29
    }
30
31
    if ( 1 == pods_v( 'pods_debug_sql_all', 'get', 0 ) && is_user_logged_in() && pods_is_admin( array( 'pods' ) ) ) {
32
        $debug_sql = $sql;
33
34
        echo '<textarea cols="100" rows="24">';
35
36
        if ( is_array( $debug_sql ) ) {
37
            $debug_sql = print_r( $debug_sql, true );
38
        }
39
40
        echo esc_textarea( $debug_sql );
41
42
        echo '</textarea>';
43
    }
44
45
    return $podsdata->query( $sql, $error, $results_error, $no_results_error );
46
}
47
48
/**
49
 * Standardize filters / actions
50
 *
51
 * @param string $scope Scope of the filter / action (ui for PodsUI, api for PodsAPI, etc..)
52
 * @param string $name Name of filter / action to run
53
 * @param mixed $args (optional) Arguments to send to filter / action
54
 * @param object $obj (optional) Object to reference for filter / action
55
 *
56
 * @return mixed
57
 * @since 2.0
58
 * @todo Need to figure out how to handle $scope = 'pods' for the Pods class
59
 */
60
function pods_do_hook ( $scope, $name, $args = null, $obj = null ) {
61
    // Add filter name
62
    array_unshift( $args, "pods_{$scope}_{$name}" );
63
64
    // Add object
65
    $args[] = $obj;
66
67
    // Run apply_filters and give it all the arguments
68
    $args = call_user_func_array( 'apply_filters', $args );
69
70
    return $args;
71
}
72
73
/**
74
 * Message / Notice handling for Admin UI
75
 *
76
 * @param string $message The notice / error message shown
77
 * @param string $type Message type
78
 *
79
 * @return void
80
 */
81
function pods_message ( $message, $type = null ) {
82
    if ( empty( $type ) || !in_array( $type, array( 'notice', 'error' ) ) )
83
        $type = 'notice';
84
85
    $class = '';
86
87
    if ( 'notice' == $type )
88
        $class = 'updated';
89
    elseif ( 'error' == $type )
90
        $class = 'error';
91
92
    echo '<div id="message" class="' . esc_attr( $class ) . ' fade"><p>' . $message . '</p></div>';
93
}
94
95
$GLOBALS['pods_errors'] = array();
96
97
/**
98
 * Error Handling which throws / displays errors
99
 *
100
 * @param string|array        $error The error message(s) to be thrown / displayed.
101
 * @param object|boolean|null $obj   If $obj->display_errors is set and is set to true it will display errors, if boolean and is set to true it will display errors.
102
 *
103
 * @throws Exception Throws exception for developer-oriented error handling.
104
 *
105
 * @return mixed
106
 *
107
 * @since 2.0
108
 */
109
function pods_error( $error, $obj = null ) {
110
111
	global $pods_errors;
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...
112
113
	$error_mode = 'exception';
114
115
	if ( is_object( $obj ) && isset( $obj->display_errors ) ) {
116
		if ( true === $obj->display_errors ) {
117
			$error_mode = 'exit';
118
		} elseif ( false === $obj->display_errors ) {
119
			$error_mode = 'exception';
120
		} else {
121
			$error_mode = $obj->display_errors;
122
		}
123
	} elseif ( true === $obj ) {
124
		$error_mode = 'exit';
125
	} elseif ( false === $obj ) {
126
		$error_mode = 'exception';
127
	} elseif ( is_string( $obj ) ) {
128
		$error_mode = $obj;
129
	}
130
131
	if ( is_object( $error ) && 'Exception' === get_class( $error ) ) {
132
		$error = $error->getMessage();
133
134
		$error_mode = 'exception';
135
	}
136
137
	/**
138
	 * @var string $error_mode Throw an exception, exit with the message, return false, or return WP_Error
139
	 */
140
	if ( ! in_array( $error_mode, array( 'exception', 'exit', 'false', 'wp_error' ), true ) ) {
141
		$error_mode = 'exception';
142
	}
143
144
	/**
145
	 * Filter the error mode used by pods_error.
146
	 *
147
	 * @param string $error_mode Error mode
148
	 * @param string|array $error Error message(s)
149
	 * @param object|boolean|string|null $obj
150
	 */
151
	$error_mode = apply_filters( 'pods_error_mode', $error_mode, $error, $obj );
152
153
	if ( is_array( $error ) ) {
154
		$error = array_map( 'wp_kses_post', $error );
155
156
		if ( 1 === count( $error ) ) {
157
			$error = current( $error );
158
159
			// Create WP_Error for use later.
160
			$wp_error = new WP_Error( 'pods-error-' . md5( $error ), $error );
161
		} else {
162
			// Create WP_Error for use later.
163
			$wp_error = new WP_Error();
164
165
			foreach ( $error as $error_message ) {
166
				$wp_error->add( 'pods-error-' . md5( $error_message ), $error_message );
167
			}
168
169
			if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
170
				$error = __( 'The following issue occurred:', 'pods' )
171
						 . "\n\n- " . implode( "\n- ", $error );
172
			} else {
173
				$error = __( 'The following issues occurred:', 'pods' )
174
						 . "\n<ul><li>" . implode( "</li>\n<li>", $error ) . "</li></ul>";
175
			}
176
		}
177
	} else {
178
		if ( is_object( $error ) ) {
179
			$error = __( 'An unknown error has occurred', 'pods' );
180
		}
181
182
		$error = wp_kses_post( $error );
183
184
		// Create WP_Error for use later.
185
		$wp_error = new WP_Error( 'pods-error-' . md5( $error ), $error );
186
	}
187
188
	$last_error = $pods_errors;
189
190
	$pods_errors = array();
191
192
	if ( $last_error === $error && 'exception' === $error_mode ) {
193
		$error_mode = 'exit';
194
	}
195
196
	if ( ! empty( $error ) ) {
197
		if ( 'exception' === $error_mode ) {
198
			$exception_bypass = apply_filters( 'pods_error_exception', null, $error );
199
200
			if ( null !== $exception_bypass ) {
201
				return $exception_bypass;
202
			}
203
204
			$pods_errors = $error;
205
206
			set_exception_handler( 'pods_error' );
207
208
			throw new Exception( $error );
209
		} elseif ( 'exit' === $error_mode ) {
210
			$die_bypass = apply_filters( 'pods_error_die', null, $error );
211
212
			if ( null !== $die_bypass ) {
213
				return $die_bypass;
214
			}
215
216
			// die with error
217
			if ( ! defined( 'DOING_AJAX' ) && ! headers_sent() && ( is_admin() || false !== strpos( $_SERVER['REQUEST_URI'], 'wp-comments-post.php' ) ) ) {
218
				wp_die( $error );
219
			} else {
220
				die( sprintf( '<e>%s</e>', $error ) );
0 ignored issues
show
Coding Style Compatibility introduced by
The function pods_error() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
221
			}
222
		} elseif ( 'wp_error' === $error_mode ) {
223
			return $wp_error;
224
		}
225
	}
226
227
	return false;
228
229
}
230
231
/**
232
 * Debug variable used in pods_debug to count the instances debug is used
233
 */
234
global $pods_debug;
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...
235
$pods_debug = 0;
236
/**
237
 * Debugging common issues using this function saves a few lines and is compatible with
238
 *
239
 * @param mixed $debug The error message to be thrown / displayed
240
 * @param boolean $die If set to true, a die() will occur, if set to (int) 2 then a wp_die() will occur
241
 * @param string $prefix
242
 *
243
 * @return void
244
 *
245
 * @since 2.0
246
 */
247
function pods_debug ( $debug = '_null', $die = false, $prefix = '_null' ) {
248
    global $pods_debug;
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...
249
250
    $pods_debug++;
251
252
    ob_start();
253
254
    if ( '_null' !== $prefix )
255
        var_dump( $prefix );
0 ignored issues
show
Security Debugging Code introduced by
var_dump($prefix); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
256
257
    if ( '_null' !== $debug )
258
        var_dump( $debug );
259
    else
260
        var_dump( 'Pods Debug #' . $pods_debug );
261
262
    $debug = ob_get_clean();
263
264
    if ( false === strpos( $debug, "<pre class='xdebug-var-dump'" ) && ( !ini_get( 'xdebug.overload_var_dump' ) && !ini_get( 'html_errors' ) ) ) {
265
        if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX )
266
            $debug = esc_html( $debug );
267
268
        $debug = '<pre>' . $debug . '</pre>';
269
    }
270
271
    $debug = '<e>' . $debug;
272
273
    if ( 2 === $die )
274
        wp_die( $debug );
275
    elseif ( true === $die )
276
        die( $debug );
0 ignored issues
show
Coding Style Compatibility introduced by
The function pods_debug() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
277
278
    echo $debug;
279
}
280
281
/**
282
 * Determine if user has admin access
283
 *
284
 * @param string|array $cap Additional capabilities to check
285
 *
286
 * @return bool Whether user has admin access
287
 *
288
 * @since 2.3.5
289
 */
290
function pods_is_admin ( $cap = null ) {
291
    if ( is_user_logged_in() ) {
292
        $pods_admin_capabilities = array(
293
            'delete_users' // default is_super_admin checks against this
294
        );
295
296
        $pods_admin_capabilities = apply_filters( 'pods_admin_capabilities', $pods_admin_capabilities, $cap );
297
298
        if ( is_multisite() && is_super_admin() )
299
            return apply_filters( 'pods_is_admin', true, $cap, '_super_admin' );
300
301
        if ( empty( $cap ) )
302
            $cap = array();
303
        else
304
            $cap = (array) $cap;
305
306
        $cap = array_unique( array_filter( array_merge( $pods_admin_capabilities, $cap ) ) );
307
308
        foreach ( $cap as $capability ) {
309
            if ( current_user_can( $capability ) )
310
                return apply_filters( 'pods_is_admin', true, $cap, $capability );
311
        }
312
    }
313
314
    return apply_filters( 'pods_is_admin', false, $cap, null );
315
}
316
317
/**
318
 * Determine if Developer Mode is enabled
319
 *
320
 * @return bool Whether Developer Mode is enabled
321
 *
322
 * @since 2.3
323
 */
324
function pods_developer () {
325
    if ( defined( 'PODS_DEVELOPER' ) && PODS_DEVELOPER )
326
        return true;
327
328
    return false;
329
}
330
331
/**
332
 * Determine if Tableless Mode is enabled
333
 *
334
 * @return bool Whether Tableless Mode is enabled
335
 *
336
 * @since 2.3
337
 */
338
function pods_tableless () {
339
    if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
340
        return true;
341
342
    return false;
343
}
344
345
/**
346
 * Determine if Strict Mode is enabled
347
 *
348
 * @param bool $include_debug Whether to include WP_DEBUG in strictness level
349
 *
350
 * @return bool Whether Strict Mode is enabled
351
 *
352
 * @since 2.3.5
353
 */
354
function pods_strict( $include_debug = true ) {
355
356
	if ( defined( 'PODS_STRICT' ) && PODS_STRICT ) {
357
		return true;
358
	}
359
	// @deprecated PODS_STRICT_MODE since 2.3.5
360
	elseif ( pods_allow_deprecated( false ) && defined( 'PODS_STRICT_MODE' ) && PODS_STRICT_MODE ) {
361
		return true;
362
	}
363
	elseif ( $include_debug && defined( 'WP_DEBUG' ) && WP_DEBUG ) {
364
		return true;
365
	}
366
367
	return false;
368
369
}
370
371
/**
372
 * Determine if Deprecated Mode is enabled
373
 *
374
 * @param bool $include_debug Whether to include strict mode
0 ignored issues
show
Bug introduced by
There is no parameter named $include_debug. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
375
 *
376
 * @return bool Whether Deprecated Mode is enabled
377
 *
378
 * @since 2.3.10
379
 */
380
function pods_allow_deprecated( $strict = true ) {
381
382
	if ( $strict && pods_strict() ) {
383
		return false;
384
	}
385
	elseif ( !defined( 'PODS_DEPRECATED' ) || PODS_DEPRECATED ) {
386
		return true;
387
	}
388
389
	return false;
390
391
}
392
393
/**
394
 * Determine if Pods API Caching is enabled
395
 *
396
 * @return bool Whether Pods API Caching is enabled
397
 *
398
 * @since 2.3.9
399
 */
400
function pods_api_cache () {
401
    if ( defined( 'PODS_API_CACHE' ) && !PODS_API_CACHE )
402
        return false;
403
404
    return true;
405
}
406
407
/**
408
 * Marks a function as deprecated and informs when it has been used.
409
 *
410
 * There is a hook deprecated_function_run that will be called that can be used
411
 * to get the backtrace up to what file and function called the deprecated
412
 * function.
413
 *
414
 * The current behavior is to trigger a user error if WP_DEBUG is true.
415
 *
416
 * This function is to be used in every function that is deprecated.
417
 *
418
 * @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead,
419
 *   and the version the function was deprecated in.
420
 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do
421
 *   trigger or false to not trigger error.
422
 *
423
 * @param string $function The function that was called
424
 * @param string $version The version of WordPress that deprecated the function
425
 * @param string $replacement Optional. The function that should have been called
426
 *
427
 * @since 2.0
428
 */
429
function pods_deprecated ( $function, $version, $replacement = null ) {
430
    if ( !version_compare( $version, PODS_VERSION, '<=' ) && !version_compare( $version . '-a-0', PODS_VERSION, '<=' ) )
431
        return;
432
433
    do_action( 'deprecated_function_run', $function, $replacement, $version );
434
435
    // Allow plugin to filter the output error trigger
436
    if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
437
        if ( !is_null( $replacement ) )
438
            $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s! Use %3$s instead.', 'pods' );
439
        else
440
            $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s with no alternative available.', 'pods' );
441
442
        trigger_error( sprintf( $error, $function, $version, $replacement ) );
443
    }
444
}
445
446
/**
447
 * Inline help
448
 *
449
 * @param string $text Help text
450
 * @param string $url Documentation URL
451
 *
452
 * @return void
453
 *
454
 * @since 2.0
455
 */
456
function pods_help ( $text, $url = null ) {
457
458 View Code Duplication
	if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) {
459
		wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' );
460
	}
461
	elseif ( ! wp_script_is( 'jquery-qtip2', 'queue' ) && ! wp_script_is( 'jquery-qtip2', 'to_do' ) && ! wp_script_is( 'jquery-qtip2', 'done' ) ) {
462
		wp_enqueue_script( 'jquery-qtip2' );
463
	}
464
465 View Code Duplication
	if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) {
466
		wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' );
467
	}
468
	elseif ( ! wp_style_is( 'jquery-qtip2', 'queue' ) && ! wp_style_is( 'jquery-qtip2', 'to_do' ) && ! wp_style_is( 'jquery-qtip2', 'done' ) ) {
469
		wp_enqueue_style( 'jquery-qtip2' );
470
	}
471
472 View Code Duplication
	if ( ! wp_script_is( 'pods-qtip-init', 'registered' ) ) {
473
		wp_register_script( 'pods-qtip-init', PODS_URL . 'ui/js/qtip.js', array(
474
			'jquery',
475
			'jquery-qtip2'
476
		), PODS_VERSION );
477
	}
478
	elseif ( ! wp_script_is( 'pods-qtip-init', 'queue' ) && ! wp_script_is( 'pods-qtip-init', 'to_do' ) && ! wp_script_is( 'pods-qtip-init', 'done' ) ) {
479
		wp_enqueue_script( 'pods-qtip-init' );
480
	}
481
482 View Code Duplication
	if ( is_array( $text ) ) {
483
		if ( isset( $text[ 1 ] ) ) {
484
			$url = $text[ 1 ];
485
		}
486
487
		$text = $text[ 0 ];
488
	}
489
490
	if ( 'help' == $text ) {
491
		return;
492
	}
493
494
	if ( 0 < strlen( $url ) ) {
495
		$text .= '<br /><br /><a href="' . $url . '" target="_blank">' . __( 'Find out more', 'pods' ) . ' &raquo;</a>';
496
	}
497
498
    echo '<img src="' . esc_url( PODS_URL ) . 'ui/images/help.png" alt="' . esc_attr( $text ) . '" class="pods-icon pods-qtip" />';
499
}
500
501
/**
502
 * Check whether or not something is a specific version minimum and/or maximum
503
 *
504
 * @param string $minimum_version Minimum version
505
 * @param string $comparison Comparison operator
506
 * @param string $maximum_version Maximum version
507
 *
508
 * @return bool
509
 */
510
function pods_version_check ( $what, $minimum_version, $comparison = '<=', $maximum_version = null ) {
511
    global $wp_version, $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...
512
513
    if ( 'php' == $what )
514
        $version = phpversion();
515
    elseif ( 'mysql' === $what )
516
        $version = $wpdb->db_version();
517
    else
518
        $version = $wp_version;
519
520
    if ( !empty( $minimum_version ) && !version_compare( $minimum_version, $version, $comparison ) )
521
        return false;
522
523
    if ( !empty( $maximum_version ) && !version_compare( $version, $maximum_version, $comparison ) )
524
        return false;
525
526
    return true;
527
}
528
529
/**
530
 * Run a Pods Helper
531
 *
532
 * @param string $helper_name Helper Name
533
 * @param string $value Value to run Helper on
534
 * @param string $name Field name.
535
 *
536
 * @return bool
537
 * @since 1.7.5
538
 */
539
function pods_helper ( $helper_name, $value = null, $name = null ) {
540
    return pods()->helper( $helper_name, $value, $name );
541
}
542
543
/**
544
 * Get the full URL of the current page
545
 *
546
 * @return string Full URL of the current page
547
 * @since 2.3
548
 */
549
function pods_current_url () {
550
    $url = 'http';
551
552
    if ( isset( $_SERVER[ 'HTTPS' ] ) && 'off' != $_SERVER[ 'HTTPS' ] && 0 != $_SERVER[ 'HTTPS' ] )
553
        $url = 'https';
554
555
    $url .= '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
556
557
    return apply_filters( 'pods_current_url', $url );
558
}
559
560
/**
561
 * Find out if the current page has a valid $pods
562
 *
563
 * @param object $object The Pod Object currently checking (optional)
564
 *
565
 * @return bool
566
 * @since 2.0
567
 */
568
function is_pod ( $object = null ) {
569
    global $pods, $post;
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...
570
571
    if ( is_object( $object ) && isset( $object->pod ) && !empty( $object->pod ) )
572
        return true;
573
    elseif ( is_object( $pods ) && isset( $pods->pod ) && !empty( $pods->pod ) )
574
        return true;
575
    elseif ( is_object( $post ) && isset( $post->post_type ) && pods_api()->pod_exists( $post->post_type, 'post_type' ) )
576
        return true;
577
578
    return false;
579
}
580
581
/**
582
 * See if the current user has a certain privilege
583
 *
584
 * @param mixed $privs The privilege name or names (array if multiple)
585
 * @param string $method The access method ("AND", "OR")
586
 *
587
 * @return bool
588
 * @since 1.2.0
589
 */
590
function pods_access ( $privs, $method = 'OR' ) {
591
    // Convert $privs to an array
592
    $privs = (array) $privs;
593
594
    // Convert $method to uppercase
595
    $method = strtoupper( $method );
596
597
    $check = apply_filters( 'pods_access', null, $privs, $method );
598
    if ( null !== $check && is_bool( $check ) )
599
        return $check;
600
601
    if ( !is_user_logged_in() )
602
        return false;
603
604
    if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
605
        return true;
606
607
    // Store approved privs when using "AND"
608
    $approved_privs = array();
609
610
    // Loop through the user's roles
611
    foreach ( $privs as $priv ) {
612
        if ( 0 === strpos( $priv, 'pod_' ) )
613
            $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 );
614
615
        if ( 0 === strpos( $priv, 'manage_' ) )
616
            $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 );
617
618
        if ( current_user_can( $priv ) ) {
619
            if ( 'OR' == $method )
620
                return true;
621
622
            $approved_privs[ $priv ] = true;
623
        }
624
    }
625
    if ( 'AND' == strtoupper( $method ) ) {
626
        foreach ( $privs as $priv ) {
627
            if ( 0 === strpos( $priv, 'pod_' ) )
628
                $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 );
629
630
            if ( 0 === strpos( $priv, 'manage_' ) )
631
                $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 );
632
633
            if ( !isset( $approved_privs[ $priv ] ) )
634
                return false;
635
        }
636
637
        return true;
638
    }
639
640
    return false;
641
}
642
643
/**
644
 * Shortcode support for use anywhere that support WP Shortcodes
645
 *
646
 * @param array $tags An associative array of shortcode properties
647
 * @param string $content A string that represents a template override
648
 *
649
 * @return string
650
 * @since 1.6.7
651
 */
652
function pods_shortcode ( $tags, $content = null ) {
653
654
	if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
655
		return '';
656
	}
657
658
	// For enforcing pagination parameters when not displaying pagination
659
	$page = 1;
660
	$offset = 0;
661
662
	if ( isset( $tags['page'] ) ) {
663
		$page = (int) $tags['page'];
664
		$page = max( $page, 1 );
665
	}
666
667
	if ( isset( $tags['offset'] ) ) {
668
		$offset = (int) $tags['offset'];
669
		$offset = max( $offset, 0 );
670
	}
671
672
    $defaults = array(
673
    	'use_current' => false,
674
        'name' => null,
675
        'id' => null,
676
        'slug' => null,
677
        'select' => null,
678
        'join' => null,
679
        'order' => null,
680
        'orderby' => null,
681
        'limit' => null,
682
        'where' => null,
683
        'having' => null,
684
        'groupby' => null,
685
        'search' => true,
686
        'pagination' => false,
687
        'page' => null,
688
        'offset' => null,
689
        'filters' => false,
690
        'filters_label' => null,
691
        'filters_location' => 'before',
692
        'pagination_label' => null,
693
        'pagination_location' => 'after',
694
        'field' => null,
695
        'col' => null,
696
        'template' => null,
697
        'pods_page' => null,
698
        'helper' => null,
699
        'form' => null,
700
        'fields' => null,
701
        'label' => null,
702
        'thank_you' => null,
703
        'view' => null,
704
        'cache_mode' => 'none',
705
        'expires' => 0,
706
		'shortcodes' => false
707
    );
708
709
    if ( !empty( $tags ) )
710
        $tags = array_merge( $defaults, $tags );
711
    else
712
        $tags = $defaults;
713
714
    $tags = apply_filters( 'pods_shortcode', $tags );
715
716
	$tags[ 'pagination' ] = filter_var($tags[ 'pagination' ], FILTER_VALIDATE_BOOLEAN);
717
	$tags[ 'search' ] = filter_var($tags[ 'pagination' ], FILTER_VALIDATE_BOOLEAN);
718
	$tags[ 'use_current' ] = filter_var($tags[ 'use_current' ], FILTER_VALIDATE_BOOLEAN);
719
720
    if ( empty( $content ) )
721
        $content = null;
722
723
	// Allow views only if not targeting a file path (must be within theme)
724
    if ( 0 < strlen( $tags[ 'view' ] ) ) {
725
		$return = '';
726
727
		if ( !file_exists( $tags[ 'view' ] ) ) {
728
			$return = pods_view( $tags[ 'view' ], null, (int) $tags[ 'expires' ], $tags[ 'cache_mode' ] );
729
730 View Code Duplication
			if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
731
				$return = do_shortcode( $return );
732
			}
733
		}
734
735
		return $return;
736
	}
737
738
    if ( ! $tags['use_current'] && empty( $tags[ 'name' ] ) ) {
739
        if ( in_the_loop() || is_singular() ) {
740
            $pod = pods( get_post_type(), get_the_ID(), false );
741
742
            if ( !empty( $pod ) ) {
743
                $tags[ 'name' ] = get_post_type();
744
                $id = $tags[ 'id' ] = get_the_ID();
745
            }
746
        }
747
748
        if ( empty( $tags[ 'name' ] ) )
749
            return '<p>Please provide a Pod name</p>';
750
    }
751
752
    if ( !empty( $tags[ 'col' ] ) ) {
753
        $tags[ 'field' ] = $tags[ 'col' ];
754
755
        unset( $tags[ 'col' ] );
756
    }
757
758
    if ( !empty( $tags[ 'order' ] ) ) {
759
        $tags[ 'orderby' ] = $tags[ 'order' ];
760
761
        unset( $tags[ 'order' ] );
762
    }
763
764
    if ( empty( $content ) && empty( $tags[ 'pods_page' ] ) && empty( $tags[ 'template' ] ) && empty( $tags[ 'field' ] ) && empty( $tags[ 'form' ] ) ) {
765
        return '<p>Please provide either a template or field name</p>';
766
    }
767
768
    if ( ! $tags['use_current'] && !isset( $id ) ) {
769
        // id > slug (if both exist)
770
		$id = null;
771
772
		if ( !empty( $tags[ 'slug' ] ) ) {
773
			$id = $tags[ 'slug' ];
774
775
			if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
776
				$id = pods_evaluate_tags( $id );
777
			}
778
		}
779
780
        if ( !empty( $tags[ 'id' ] ) ) {
781
            $id = $tags[ 'id' ];
782
783
            if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
784
                $id = pods_evaluate_tags( $id );
785
            }
786
787
            if ( is_numeric( $id ) )
788
                $id = absint( $id );
789
        }
790
    }
791
792
    if ( !isset( $pod ) ) {
793
    	if ( ! $tags['use_current'] ) {
794
        	$pod = pods( $tags[ 'name' ], $id );
0 ignored issues
show
Bug introduced by
The variable $id does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
795
    	} else {
796
    		$pod = pods();
797
    		$id = $pod->id();
798
    	}
799
    }
800
801
    if ( empty( $pod ) || ! $pod->valid() )
802
        return '<p>Pod not found</p>';
803
804
	$found = 0;
805
	
806
	$is_singular = ( ! empty( $id ) || $tags['use_current'] );
807
808
	if ( ! $is_singular ) {
809
		$params = array();
810
811
		if ( !defined( 'PODS_DISABLE_SHORTCODE_SQL' ) || !PODS_DISABLE_SHORTCODE_SQL ) {
812
			if ( 0 < strlen( $tags[ 'orderby' ] ) ) {
813
				$params[ 'orderby' ] = $tags[ 'orderby' ];
814
			}
815
816 View Code Duplication
			if ( 0 < strlen( $tags[ 'where' ] ) ) {
817
				$params[ 'where' ] = $tags[ 'where' ];
818
819
				if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
820
					$params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ] );
821
				}
822
			}
823
824 View Code Duplication
			if ( 0 < strlen( $tags[ 'having' ] ) ) {
825
				$params[ 'having' ] = $tags[ 'having' ];
826
827
				if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
828
					$params[ 'having' ] = pods_evaluate_tags( $id );
829
				}
830
			}
831
832
			if ( 0 < strlen( $tags[ 'groupby' ] ) ) {
833
				$params[ 'groupby' ] = $tags[ 'groupby' ];
834
			}
835
836
			if ( 0 < strlen( $tags[ 'select' ] ) ) {
837
				$params[ 'select' ] = $tags[ 'select' ];
838
			}
839
			if ( 0 < strlen( $tags[ 'join' ] ) ) {
840
				$params[ 'join' ] = $tags[ 'join' ];
841
			}
842
		}
843
844
		// Forms require params set
845
		if ( ! empty( $params ) || empty( $tags[ 'form' ] ) ) {
846
			if ( !empty( $tags[ 'limit' ] ) ) {
847
				$params[ 'limit' ] = (int) $tags[ 'limit' ];
848
			}
849
850
			$params[ 'search' ] = $tags[ 'search' ];
851
852
			$params[ 'pagination' ] = $tags[ 'pagination' ];
853
854
			// If we aren't displaying pagination, we need to enforce page/offset
855
			if ( ! $params['pagination'] ) {
856
				$params['page']   = $page;
857
				$params['offset'] = $offset;
858
859
				// Force pagination on, we need it and we're enforcing page/offset
860
				$params['pagination'] = true;
861
			} else {
862
				// If we are displaying pagination, allow page/offset override only if *set*
863
864 View Code Duplication
				if ( isset( $tags['page'] ) ) {
865
					$params['page'] = (int) $tags['page'];
866
					$params['page'] = max( $params['page'], 1 );
867
				}
868
869 View Code Duplication
				if ( isset( $tags['offset'] ) ) {
870
					$params['offset'] = (int) $tags['offset'];
871
					$params['offset'] = max( $params['offset'], 0 );
872
				}
873
			}
874
875
			if ( !empty( $tags[ 'cache_mode' ] ) && 'none' != $tags[ 'cache_mode' ] ) {
876
				$params[ 'cache_mode' ] = $tags[ 'cache_mode' ];
877
				$params[ 'expires' ] = (int) $tags[ 'expires' ];
878
			}
879
880
			$params = apply_filters( 'pods_shortcode_findrecords_params', $params, $pod, $tags );
881
882
			$pod->find( $params );
883
884
			$found = $pod->total();
885
		}
886
	}
887
888
    if ( !empty( $tags[ 'form' ] ) ) {
889
		if ( 'user' == $pod->pod ) {
890
			// Further hardening of User-based forms
891
			if ( false !== strpos( $tags[ 'fields' ], '_capabilities' ) || false !== strpos( $tags[ 'fields' ], '_user_level' ) ) {
892
				return '';
893
			}
894
			// Only explicitly allow user edit forms
895
			elseif ( $is_singular && ( !defined( 'PODS_SHORTCODE_ALLOW_USER_EDIT' ) || !PODS_SHORTCODE_ALLOW_USER_EDIT ) ) {
896
				return '';
897
			}
898
		}
899
900
        return $pod->form( $tags[ 'fields' ], $tags[ 'label' ], $tags[ 'thank_you' ] );
901
	}
902
    elseif ( !empty( $tags[ 'field' ] ) ) {
903
        if ( empty( $tags[ 'helper' ] ) )
904
            $return = $pod->display( $tags[ 'field' ] );
905
        else
906
            $return = $pod->helper( $tags[ 'helper' ], $pod->field( $tags[ 'field' ] ), $tags[ 'field' ] );
907
908 View Code Duplication
		if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
909
			$return = do_shortcode( $return );
910
		}
911
912
		return $return;
913
    }
914
    elseif ( !empty( $tags[ 'pods_page' ] ) && class_exists( 'Pods_Pages' ) ) {
915
        $pods_page = Pods_Pages::exists( $tags[ 'pods_page' ] );
916
917
        if ( empty( $pods_page ) )
918
            return '<p>Pods Page not found</p>';
919
920
        $return = Pods_Pages::content( true, $pods_page );
921
922 View Code Duplication
		if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
923
			$return = do_shortcode( $return );
924
		}
925
926
		return $return;
927
    }
928
929
    ob_start();
930
931 View Code Duplication
    if ( ! $is_singular && false !== $tags[ 'filters' ] && 'before' == $tags[ 'filters_location' ] )
932
        echo $pod->filters( $tags[ 'filters' ], $tags[ 'filters_label' ] );
0 ignored issues
show
Unused Code introduced by
The call to Pods::filters() has too many arguments starting with $tags['filters_label'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
933
934 View Code Duplication
    if ( ! $is_singular && 0 < $found && true === $tags[ 'pagination' ] && in_array( $tags[ 'pagination_location' ], array( 'before', 'both' ) ) )
935
        echo $pod->pagination( $tags[ 'pagination_label' ] );
936
937
    echo $pod->template( $tags[ 'template' ], $content );
938
939 View Code Duplication
    if ( ! $is_singular && 0 < $found && true === $tags[ 'pagination' ] && in_array( $tags[ 'pagination_location' ], array( 'after', 'both' ) ) )
940
        echo $pod->pagination( $tags[ 'pagination_label' ] );
941
942 View Code Duplication
    if ( ! $is_singular && false !== $tags[ 'filters' ] && 'after' == $tags[ 'filters_location' ] )
943
        echo $pod->filters( $tags[ 'filters' ], $tags[ 'filters_label' ] );
0 ignored issues
show
Unused Code introduced by
The call to Pods::filters() has too many arguments starting with $tags['filters_label'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
944
945
	$return = ob_get_clean();
946
947 View Code Duplication
	if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
948
		$return = do_shortcode( $return );
949
	}
950
951
	return $return;
952
}
953
954
/**
955
 * Form Shortcode support for use anywhere that support WP Shortcodes
956
 *
957
 * @param array $tags An associative array of shortcode properties
958
 * @param string $content Not currently used
959
 *
960
 * @return string
961
 * @since 2.3
962
 */
963
function pods_shortcode_form ( $tags, $content = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $content 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...
964
    $tags[ 'form' ] = 1;
965
966
    return pods_shortcode( $tags );
967
}
968
969
/**
970
 * Fork of WordPress do_shortcode that allows specifying which shortcodes are ran.
971
 *
972
 * Search content for shortcodes and filter shortcodes through their hooks.
973
 *
974
 * If there are no shortcode tags defined, then the content will be returned
975
 * without any filtering. This might cause issues when plugins are disabled but
976
 * the shortcode will still show up in the post or content.
977
 *
978
 * @since 2.4.3
979
 *
980
 * @uses $shortcode_tags
981
 * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.
982
 *
983
 * @param string $content Content to search for shortcodes
984
 * @param array $shortcodes Array of shortcodes to run
985
 * @return string Content with shortcodes filtered out.
986
 */
987
function pods_do_shortcode( $content, $shortcodes ) {
988
989
	global $shortcode_tags;
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...
990
991
	// No shortcodes in content
992
	if ( false === strpos( $content, '[' ) ) {
993
		return $content;
994
	}
995
996
	// No shortcodes registered
997
	if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
998
		return $content;
999
	}
1000
1001
	// Store all shortcodes, to restore later
1002
	$temp_shortcode_tags = $shortcode_tags;
1003
1004
	// Loop through all shortcodes and remove those not being used right now
1005
	foreach ( $shortcode_tags as $tag => $callback ) {
1006
		if ( ! in_array( $tag, $shortcodes ) ) {
1007
			unset( $shortcode_tags[ $tag ] );
1008
		}
1009
	}
1010
1011
	// Build Shortcode regex pattern just for the shortcodes we want
1012
	$pattern = get_shortcode_regex();
1013
1014
	// Call shortcode callbacks just for the shortcodes we want
1015
	$content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
1016
1017
	// Restore all shortcode tags
1018
	$shortcode_tags = $temp_shortcode_tags;
1019
1020
	return $content;
1021
1022
}
1023
1024
/**
1025
 * Check if Pods is compatible with WP / PHP / MySQL or not
1026
 *
1027
 * @return bool
1028
 *
1029
 * @since 1.10
1030
 */
1031
function pods_compatibility_check () {
1032
    $compatible = true;
1033
1034
    if ( !pods_version_check( 'wp', PODS_WP_VERSION_MINIMUM ) ) {
1035
        $compatible = false;
1036
1037
        add_action( 'admin_notices', 'pods_version_notice_wp' );
1038
    }
1039
1040
    if ( !pods_version_check( 'php', PODS_PHP_VERSION_MINIMUM ) ) {
1041
        $compatible = false;
1042
1043
        add_action( 'admin_notices', 'pods_version_notice_php' );
1044
    }
1045
1046
    if ( !pods_version_check( 'mysql', PODS_MYSQL_VERSION_MINIMUM ) ) {
1047
        $compatible = false;
1048
1049
        add_action( 'admin_notices', 'pods_version_notice_mysql' );
1050
    }
1051
1052
    return $compatible;
1053
}
1054
1055
/**
1056
 * Show WP notice if WP version is incompatible
1057
 *
1058
 * @return void
1059
 *
1060
 * @since 1.10
1061
 */
1062 View Code Duplication
function pods_version_notice_wp () {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

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

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

Loading history...
1063
    global $wp_version;
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...
1064
?>
1065
    <div class="error fade">
1066
        <p>
1067
            <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1068
            <strong>WordPress <?php echo esc_html( PODS_WP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1069
            <strong>WordPress <?php echo esc_html( $wp_version ); ?></strong> - <?php _e( 'Please upgrade your WordPress to continue.', 'pods' ); ?>
1070
        </p>
1071
    </div>
1072
<?php
1073
}
1074
1075
/**
1076
 * Show WP notice if PHP version is incompatible
1077
 *
1078
 * @return void
1079
 *
1080
 * @since 1.10
1081
 */
1082 View Code Duplication
function pods_version_notice_php () {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

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

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

Loading history...
1083
?>
1084
    <div class="error fade">
1085
        <p>
1086
            <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1087
            <strong>PHP <?php echo esc_html( PODS_PHP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1088
            <strong>PHP <?php echo esc_html( phpversion() ); ?></strong> - <?php _e( 'Please upgrade (or have your Hosting Provider upgrade it for you) your PHP version to continue.', 'pods' ); ?>
1089
        </p>
1090
    </div>
1091
<?php
1092
}
1093
1094
/**
1095
 * Show WP notice if MySQL version is incompatible
1096
 *
1097
 * @return void
1098
 *
1099
 * @since 1.10
1100
 */
1101 View Code Duplication
function pods_version_notice_mysql () {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

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

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

Loading history...
1102
    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...
1103
    $mysql = $wpdb->db_version();
1104
?>
1105
    <div class="error fade">
1106
        <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1107
            <strong>MySQL <?php echo esc_html( PODS_MYSQL_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1108
            <strong>MySQL <?php echo esc_html( $mysql ); ?></strong> - <?php _e( 'Please upgrade (or have your Hosting Provider upgrade it for you) your MySQL version to continue.', 'pods' ); ?>
1109
        </p>
1110
    </div>
1111
<?php
1112
}
1113
1114
/**
1115
 * Check if a Function exists or File exists in Theme / Child Theme
1116
 *
1117
 * @param string $function_or_file Function or file name to look for.
1118
 * @param string $function_name (optional) Function name to look for.
1119
 * @param string $file_dir (optional) Drectory to look into
1120
 * @param string $file_name (optional) Filename to look for
1121
 *
1122
 * @return mixed
1123
 *
1124
 * @since 1.12
1125
 */
1126
function pods_function_or_file ( $function_or_file, $function_name = null, $file_dir = null, $file_name = null ) {
1127
    $found = false;
1128
    $function_or_file = (string) $function_or_file;
1129
    if ( false !== $function_name ) {
1130
        if ( null === $function_name )
1131
            $function_name = $function_or_file;
1132
        $function_name = str_replace( array(
1133
            '__',
1134
            '__',
1135
            '__'
1136
        ), '_', preg_replace( '/[^a-z^A-Z^_][^a-z^A-Z^0-9^_]*/', '_', (string) $function_name ) );
1137
        if ( function_exists( 'pods_custom_' . $function_name ) )
1138
            $found = array( 'function' => 'pods_custom_' . $function_name );
1139
        elseif ( function_exists( $function_name ) )
1140
            $found = array( 'function' => $function_name );
1141
    }
1142
    if ( false !== $file_name && false === $found ) {
1143
        if ( null === $file_name )
1144
            $file_name = $function_or_file;
1145
        $file_name = str_replace( array(
1146
            '__',
1147
            '__',
1148
            '__'
1149
        ), '_', preg_replace( '/[^a-z^A-Z^0-9^_]*/', '_', (string) $file_name ) ) . '.php';
1150
        $custom_location = apply_filters( 'pods_file_directory', null, $function_or_file, $function_name, $file_dir, $file_name );
1151
        if ( defined( 'PODS_FILE_DIRECTORY' ) && false !== PODS_FILE_DIRECTORY )
1152
            $custom_location = PODS_FILE_DIRECTORY;
1153
        if ( !empty( $custom_location ) && locate_template( trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
1154
            $found = array( 'file' => trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
1155 View Code Duplication
        elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
1156
            $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
1157 View Code Duplication
        elseif ( locate_template( 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
1158
            $found = array( 'file' => 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
1159 View Code Duplication
        elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
1160
            $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
1161
    }
1162
1163
    return apply_filters( 'pods_function_or_file', $found, $function_or_file, $function_name, $file_name );
1164
}
1165
1166
/**
1167
 * Redirects to another page.
1168
 *
1169
 * @param string $location The path to redirect to
1170
 * @param int $status Status code to use
1171
 *
1172
 * @return void
1173
 *
1174
 * @since 2.0
1175
 */
1176
function pods_redirect ( $location, $status = 302 ) {
1177
    if ( !headers_sent() ) {
1178
        wp_redirect( $location, $status );
1179
        die();
0 ignored issues
show
Coding Style Compatibility introduced by
The function pods_redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1180
    }
1181
    else {
1182
        die( '<script type="text/javascript">'
0 ignored issues
show
Coding Style Compatibility introduced by
The function pods_redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1183
            . 'document.location = "' . str_replace( '&amp;', '&', esc_js( $location ) ) . '";'
1184
            . '</script>' );
1185
    }
1186
}
1187
1188
/**
1189
 * Check if a user has permission to be doing something based on standard permission options
1190
 *
1191
 * @param array $options
1192
 *
1193
 * @return bool Whether the user has permissions
1194
 *
1195
 * @since 2.0.5
1196
 */
1197
function pods_permission ( $options ) {
1198
    global $current_user;
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...
1199
1200
    wp_get_current_user();
1201
1202
    $permission = false;
1203
1204
    if ( isset( $options[ 'options' ] ) )
1205
        $options = $options[ 'options' ];
1206
1207
    if ( pods_is_admin() )
1208
        $permission = true;
1209
    elseif ( 0 == pods_v( 'restrict_role', $options, 0 ) && 0 == pods_v( 'restrict_capability', $options, 0 ) && 0 == pods_v( 'admin_only', $options, 0 ) )
1210
        $permission = true;
1211
1212
    if ( !$permission && 1 == pods_v( 'restrict_role', $options, 0 ) ) {
1213
        $roles = pods_v( 'roles_allowed', $options );
1214
1215
        if ( !is_array( $roles ) )
1216
            $roles = explode( ',', $roles );
1217
1218
        $roles = array_unique( array_filter( $roles ) );
1219
1220
        foreach( $roles as $role ) {
1221
            if ( is_user_logged_in() && in_array( $role, $current_user->roles ) ) {
1222
                $permission = true;
1223
1224
                break;
1225
            }
1226
        }
1227
    }
1228
1229
    if ( !$permission && 1 == pods_v( 'restrict_capability', $options, 0 ) ) {
1230
        $capabilities = pods_v( 'capability_allowed', $options );
1231
1232
        if ( !is_array( $capabilities ) )
1233
            $capabilities = explode( ',', $capabilities );
1234
1235
        $capabilities = array_unique( array_filter( $capabilities ) );
1236
1237
        foreach( $capabilities as $capability ) {
1238
            $must_have_capabilities = explode( '&&', $capability );
1239
            $must_have_capabilities = array_unique( array_filter( $must_have_capabilities ) );
1240
1241
            $must_have_permission = true;
1242
1243
            foreach ( $must_have_capabilities as $must_have_capability ) {
1244
                if ( !current_user_can( $must_have_capability ) ) {
1245
                    $must_have_permission = false;
1246
1247
                    break;
1248
                }
1249
            }
1250
1251
            if ( $must_have_permission && is_user_logged_in() ) {
1252
                $permission = true;
1253
1254
                break;
1255
            }
1256
        }
1257
    }
1258
1259
    return $permission;
1260
}
1261
1262
/**
1263
 * Check if permissions are restricted
1264
 *
1265
 * @param array $options
1266
 *
1267
 * @return bool Whether the permissions are restricted
1268
 *
1269
 * @since 2.3.4
1270
 */
1271
function pods_has_permissions ( $options ) {
1272
    $permission = false;
1273
1274
    if ( isset( $options[ 'options' ] ) )
1275
        $options = $options[ 'options' ];
1276
1277
    if ( 1 == pods_v( 'restrict_role', $options, 0 ) || 1 == pods_v( 'restrict_capability', $options, 0 ) || 1 == pods_v( 'admin_only', $options, 0 ) )
1278
        return true;
1279
1280
    return false;
1281
}
1282
1283
/**
1284
 * A fork of get_page_by_title that excludes items unavailable via access rights (by status)
1285
 *
1286
 * @see get_page_by_title
1287
 *
1288
 * @param string $title Title of item to get
1289
 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
1290
 * @param string $type Post Type
1291
 * @param string|array $status Post statuses to include (default is what user has access to)
1292
 *
1293
 * @return WP_Post|null WP_Post on success or null on failure
1294
 *
1295
 * @since 2.3.4
1296
 */
1297
function pods_by_title ( $title, $output = OBJECT, $type = 'page', $status = null ) {
1298
    // @todo support Pod item lookups, not just Post Types
1299
1300
    /**
1301
     * @var $wpdb WPDB
1302
     */
1303
    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...
1304
1305
    if ( empty( $status ) ) {
1306
        $status = array(
1307
            'publish'
1308
        );
1309
1310
        if ( current_user_can( 'read_private_' . $type . 's') )
1311
            $status[] = 'private';
1312
1313
        if ( current_user_can( 'edit_' . $type . 's' ) )
1314
            $status[] = 'draft';
1315
    }
1316
1317
    $status = (array) $status;
1318
1319
    $status_sql = ' AND `post_status` IN ( %s' . str_repeat( ', %s', count( $status ) -1 ) . ' )';
1320
1321
    $orderby_sql = ' ORDER BY ( `post_status` = %s ) DESC' . str_repeat( ', ( `post_status` = %s ) DESC', count( $status ) - 1 ) . ', `ID` DESC';
1322
1323
    $prepared = array_merge( array( $title, $type ), $status, $status ); // once for WHERE, once for ORDER BY
1324
1325
    $page = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` = %s AND `post_type` = %s" . $status_sql . $orderby_sql, $prepared ) );
1326
1327
    if ( $page )
1328
        return get_post( pods_v( $page, 'post_id' ), $output );
1329
1330
    return null;
1331
}
1332
1333
/**
1334
 * Get a field value from a Pod
1335
 *
1336
 * @param string $pod The pod name
1337
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1338
 * @param string|array $name The field name, or an associative array of parameters
1339
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1340
 *
1341
 * @return mixed Field value
1342
 *
1343
 * @since 2.1
1344
 */
1345 View Code Duplication
function pods_field ( $pod, $id = false, $name = null, $single = false ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

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

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

Loading history...
1346
    // allow for pods_field( 'field_name' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1347
    if ( null === $name ) {
1348
        $name = $pod;
1349
        $single = (boolean) $id;
1350
1351
        $pod = get_post_type();
1352
        $id = get_the_ID();
1353
    }
1354
1355
    $pod = pods( $pod, $id );
1356
1357
	if ( is_object( $pod ) ) {
1358
		return $pod->field( $name, $single );
1359
	}
1360
1361
	return null;
1362
}
1363
1364
/**
1365
 * Get a field display value from a Pod
1366
 *
1367
 * @param string $pod The pod name
1368
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1369
 * @param string|array $name The field name, or an associative array of parameters
1370
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1371
 *
1372
 * @return mixed Field value
1373
 *
1374
 * @since 2.1
1375
 */
1376 View Code Duplication
function pods_field_display ( $pod, $id = false, $name = null, $single = false ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

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

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

Loading history...
1377
    // allow for pods_field_display( 'field_name' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1378
    if ( null === $name ) {
1379
        $name = $pod;
1380
        $single = (boolean) $id;
1381
1382
        $pod = get_post_type();
1383
        $id = get_the_ID();
1384
    }
1385
1386
    $pod = pods( $pod, $id );
1387
1388
	if ( is_object( $pod ) ) {
1389
		return $pod->display( $name, $single );
1390
	}
1391
1392
	return null;
1393
}
1394
1395
/**
1396
 * Get a field raw value from a Pod
1397
 *
1398
 * @param string $pod The pod name
1399
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1400
 * @param string|array $name The field name, or an associative array of parameters
1401
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1402
 *
1403
 * @return mixed Field value
1404
 *
1405
 * @since 2.1
1406
 */
1407
function pods_field_raw ( $pod, $id = false, $name = null, $single = false ) {
1408
    // allow for pods_field_raw( 'field_name' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1409
    if ( null === $name ) {
1410
        $name = $pod;
1411
        $single = (boolean) $id;
1412
1413
        $pod = get_post_type();
1414
        $id = get_the_ID();
1415
    }
1416
1417
    return pods( $pod, $id )->raw( $name, $single );
1418
1419
}
1420
1421
/**
1422
 * Set a cached value
1423
 *
1424
 * @see PodsView::set
1425
 *
1426
 * @param string $key Key for the cache
1427
 * @param mixed $value Value to add to the cache
1428
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1429
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1430
 * @param string $group (optional) Key for the group
1431
 *
1432
 * @return bool|mixed|null|string|void
1433
 *
1434
 * @since 2.0
1435
 */
1436
function pods_view_set ( $key, $value, $expires = 0, $cache_mode = 'cache', $group = '' ) {
1437
    require_once( PODS_DIR . 'classes/PodsView.php' );
1438
1439
    return PodsView::set( $key, $value, $expires, $cache_mode, $group );
1440
}
1441
1442
/**
1443
 * Get a cached value
1444
 *
1445
 * @see PodsView::get
1446
 *
1447
 * @param string $key Key for the cache
1448
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1449
 * @param string $group (optional) Key for the group
1450
 * @param string $callback (optional) Callback function to run to set the value if not cached
1451
 *
1452
 * @return bool|mixed|null|void
1453
 *
1454
 * @since 2.0
1455
 */
1456
function pods_view_get ( $key, $cache_mode = 'cache', $group = '', $callback = null ) {
1457
    require_once( PODS_DIR . 'classes/PodsView.php' );
1458
1459
    return PodsView::get( $key, $cache_mode, $group, $callback );
1460
}
1461
1462
/**
1463
 * Clear a cached value
1464
 *
1465
 * @see PodsView::clear
1466
 *
1467
 * @param string|bool $key Key for the cache
1468
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1469
 * @param string $group (optional) Key for the group
1470
 *
1471
 * @return bool
1472
 *
1473
 * @since 2.0
1474
 */
1475
function pods_view_clear ( $key = true, $cache_mode = 'cache', $group = '' ) {
1476
    require_once( PODS_DIR . 'classes/PodsView.php' );
1477
1478
    return PodsView::clear( $key, $cache_mode, $group );
1479
}
1480
1481
/**
1482
 * Set a cached value
1483
 *
1484
 * @see PodsView::set
1485
 *
1486
 * @param string $key Key for the cache
1487
 * @param mixed $value Value to add to the cache
1488
 * @param string $group (optional) Key for the group
1489
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1490
 *
1491
 * @return bool|mixed|null|string|void
1492
 *
1493
 * @since 2.0
1494
 */
1495
function pods_cache_set ( $key, $value, $group = '', $expires = 0) {
1496
    return pods_view_set( $key, $value, $expires, 'cache', $group );
1497
}
1498
1499
/**
1500
 * Get a cached value
1501
 *
1502
 * @see PodsView::get
1503
 *
1504
 * @param string $key Key for the cache
1505
 * @param string $group (optional) Key for the group
1506
 * @param string $callback (optional) Callback function to run to set the value if not cached
1507
 *
1508
 * @return bool
1509
 *
1510
 * @since 2.0
1511
 */
1512
function pods_cache_get ( $key, $group = '', $callback = null ) {
1513
    return pods_view_get( $key, 'cache', $group, $callback );
1514
}
1515
1516
/**
1517
 * Clear a cached value
1518
 *
1519
 * @see PodsView::clear
1520
 *
1521
 * @param string|bool $key Key for the cache
1522
 * @param string $group (optional) Key for the group
1523
 *
1524
 * @return bool|mixed|null|void
1525
 *
1526
 * @since 2.0
1527
 */
1528
function pods_cache_clear ( $key = true, $group = '' ) {
1529
    return pods_view_clear( $key, 'cache', $group );
1530
}
1531
1532
/**
1533
 * Set a cached value
1534
 *
1535
 * @see PodsView::set
1536
 *
1537
 * @param string $key Key for the cache
1538
 * @param mixed $value Value to add to the cache
1539
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1540
 *
1541
 * @return bool|mixed|null|string|void
1542
 *
1543
 * @since 2.0
1544
 */
1545
function pods_transient_set ( $key, $value, $expires = 0 ) {
1546
    return pods_view_set( $key, $value, $expires, 'transient' );
1547
}
1548
1549
/**
1550
 * Get a cached value
1551
 *
1552
 * @see PodsView::get
1553
 *
1554
 * @param string $key Key for the cache
1555
 * @param string $callback (optional) Callback function to run to set the value if not cached
1556
 *
1557
 * @return bool|mixed|null|void
1558
 *
1559
 * @since 2.0
1560
 */
1561
function pods_transient_get ( $key, $callback = null ) {
1562
    return pods_view_get( $key, 'transient', '', $callback );
1563
}
1564
1565
/**
1566
 * Clear a cached value
1567
 *
1568
 * @see PodsView::clear
1569
 *
1570
 * @param string|bool $key Key for the cache
1571
 *
1572
 * @return bool
1573
 *
1574
 * @since 2.0
1575
 */
1576
function pods_transient_clear ( $key = true ) {
1577
    return pods_view_clear( $key, 'transient' );
1578
}
1579
1580
/**
1581
 * Set a cached value
1582
 *
1583
 * @see PodsView::set
1584
 *
1585
 * @param string $key Key for the cache
1586
 * @param mixed $value Value to add to the cache
1587
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1588
 *
1589
 * @return bool|mixed|null|string|void
1590
 *
1591
 * @since 2.3.10
1592
 */
1593
function pods_site_transient_set ( $key, $value, $expires = 0 ) {
1594
    return pods_view_set( $key, $value, $expires, 'site-transient' );
1595
}
1596
1597
/**
1598
 * Get a cached value
1599
 *
1600
 * @see PodsView::get
1601
 *
1602
 * @param string $key Key for the cache
1603
 * @param string $callback (optional) Callback function to run to set the value if not cached
1604
 *
1605
 * @return bool|mixed|null|void
1606
 *
1607
 * @since 2.3.10
1608
 */
1609
function pods_site_transient_get ( $key, $callback = null ) {
1610
    return pods_view_get( $key, 'site-transient', '', $callback );
1611
}
1612
1613
/**
1614
 * Clear a cached value
1615
 *
1616
 * @see PodsView::clear
1617
 *
1618
 * @param string|bool $key Key for the cache
1619
 *
1620
 * @return bool
1621
 *
1622
 * @since 2.3.10
1623
 */
1624
function pods_site_transient_clear ( $key = true ) {
1625
    return pods_view_clear( $key, 'site-transient' );
1626
}
1627
1628
/**
1629
 * Set a cached value
1630
 *
1631
 * @see PodsView::set
1632
 *
1633
 * @param string $key Key for the cache
1634
 * @param mixed $value Value to add to the cache
1635
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1636
 * @param string $group (optional) Key for the group
1637
 *
1638
 * @return bool|mixed|null|string|void
1639
 *
1640
 * @since 2.3.10
1641
 */
1642
function pods_option_cache_set ( $key, $value, $expires = 0, $group = '' ) {
1643
    return pods_view_set( $key, $value, $expires, 'option-cache', $group );
1644
}
1645
1646
/**
1647
 * Get a cached value
1648
 *
1649
 * @see PodsView::get
1650
 *
1651
 * @param string $key Key for the cache
1652
 * @param string $group (optional) Key for the group
1653
 * @param string $callback (optional) Callback function to run to set the value if not cached
1654
 *
1655
 * @return bool|mixed|null|void
1656
 *
1657
 * @since 2.3.10
1658
 */
1659
function pods_option_cache_get ( $key, $group = '', $callback = null ) {
1660
    return pods_view_get( $key, 'option-cache', $group, $callback );
1661
}
1662
1663
/**
1664
 * Clear a cached value
1665
 *
1666
 * @see PodsView::clear
1667
 *
1668
 * @param string|bool $key Key for the cache
1669
 * @param string $group (optional) Key for the group
1670
 *
1671
 * @return bool
1672
 *
1673
 * @since 2.3.10
1674
 */
1675
function pods_option_cache_clear ( $key = true, $group = '' ) {
1676
    return pods_view_clear( $key, 'option-cache', $group );
1677
}
1678
1679
/**
1680
 * Scope variables and include a template like get_template_part that's child-theme aware
1681
 *
1682
 * @see get_template_part
1683
 *
1684
 * @param string|array $template Template names (see get_template_part)
1685
 * @param array $data Data to scope to the include
1686
 * @param bool $return Whether to return the output (echo by default)
1687
 * @return string|null Template output
1688
 *
1689
 * @since 2.3.9
1690
 */
1691
function pods_template_part ( $template, $data = null, $return = false ) {
1692
    $part = PodsView::get_template_part( $template, $data );
1693
1694
    if ( !$return ) {
1695
        echo $part;
1696
1697
        return null;
1698
    }
1699
1700
    return $part;
1701
}
1702
1703
/**
1704
 * Add a new Pod outside of the DB
1705
 *
1706
 * @see PodsMeta::register
1707
 *
1708
 * @param string $type The pod type ('post_type', 'taxonomy', 'media', 'user', 'comment')
1709
 * @param string $name The pod name
1710
 * @param array $object (optional) Pod array, including any 'fields' arrays
1711
 *
1712
 * @return array|boolean Pod data or false if unsuccessful
1713
 * @since 2.1
1714
 */
1715
function pods_register_type ( $type, $name, $object = null ) {
1716
    if ( empty( $object ) )
1717
        $object = array();
1718
1719
    if ( !empty( $name ) )
1720
        $object[ 'name' ] = $name;
1721
1722
    return pods_meta()->register( $type, $object );
1723
}
1724
1725
/**
1726
 * Add a new Pod field outside of the DB
1727
 *
1728
 * @see PodsMeta::register_field
1729
 *
1730
 * @param string|array $pod The pod name or array of pod names
1731
 * @param string $name The name of the Pod
1732
 * @param array $object (optional) Pod array, including any 'fields' arrays
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1733
 *
1734
 * @return array|boolean Field data or false if unsuccessful
1735
 * @since 2.1
1736
 */
1737
function pods_register_field ( $pod, $name, $field = null ) {
1738
    if ( empty( $field ) )
1739
        $field = array();
1740
1741
    if ( !empty( $name ) )
1742
        $field[ 'name' ] = $name;
1743
1744
    return pods_meta()->register_field( $pod, $field );
1745
}
1746
1747
/**
1748
 * Add a new Pod field type
1749
 *
1750
 * @see PodsForm::register_field_type
1751
 *
1752
 * @param string $type The new field type identifier
1753
 * @param string $file The new field type class file location
1754
 *
1755
 * @return array Field type array
1756
 * @since 2.3
1757
 */
1758
function pods_register_field_type ( $type, $file = null ) {
1759
    return PodsForm::register_field_type( $type, $file );
1760
}
1761
1762
/**
1763
 * Register a related object
1764
 *
1765
 * @param string $name Object name
1766
 * @param string $label Object label
1767
 * @param array $options Object options
1768
 *
1769
 * @return array|boolean Object array or false if unsuccessful
1770
 * @since 2.3
1771
 */
1772
function pods_register_related_object ( $name, $label, $options = null ) {
1773
    return PodsForm::field_method( 'pick', 'register_related_object', $name, $label, $options );
1774
}
1775
1776
/**
1777
 * Require a component (always-on)
1778
 *
1779
 * @param string $component Component ID
1780
 *
1781
 * @return void
1782
 *
1783
 * @since 2.3
1784
 */
1785
function pods_require_component ( $component ) {
1786
    add_filter( 'pods_component_require_' . $component, '__return_true' );
1787
}
1788
1789
/**
1790
 * Add a meta group of fields to add/edit forms
1791
 *
1792
 * @see PodsMeta::group_add
1793
 *
1794
 * @param string|array $pod The pod or type of element to attach the group to.
1795
 * @param string $label Title of the edit screen section, visible to user.
1796
 * @param string|array $fields Either a comma separated list of text fields or an associative array containing field information.
1797
 * @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').
1798
 * @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low').
1799
 * @param string $type (optional) Type of the post to attach to.
1800
 *
1801
 * @return void
1802
 *
1803
 * @since 2.0
1804
 * @link http://pods.io/docs/pods-group-add/
1805
 */
1806
function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) {
1807 View Code Duplication
    if ( !is_array( $pod ) && null !== $type ) {
1808
        $pod = array(
1809
            'name' => $pod,
1810
            'type' => $type
1811
        );
1812
    }
1813
1814
    pods_meta()->group_add( $pod, $label, $fields, $context, $priority );
1815
}
1816
1817
/**
1818
 * Check if a plugin is active on non-admin pages (is_plugin_active() only available in admin)
1819
 *
1820
 * @param string $plugin Plugin name.
1821
 *
1822
 * @return bool
1823
 *
1824
 * @since 2.0
1825
 */
1826
function pods_is_plugin_active ( $plugin ) {
1827
    $active = false;
1828
1829
    if ( function_exists( 'is_plugin_active' ) )
1830
        $active = is_plugin_active( $plugin );
1831
1832
    if ( !$active ) {
1833
        $active_plugins = (array) get_option( 'active_plugins', array() );
1834
1835
        if ( in_array( $plugin, $active_plugins ) )
1836
            $active = true;
1837
1838
        if ( !$active && is_multisite() ) {
1839
            $plugins = get_site_option( 'active_sitewide_plugins' );
1840
1841
            if ( isset( $plugins[ $plugin ] ) )
1842
                $active = true;
1843
        }
1844
    }
1845
1846
    return $active;
1847
}
1848
1849
/**
1850
 * Check if Pods no conflict is on or not
1851
 *
1852
 * @param string $object_type
1853
 *
1854
 * @return bool
1855
 *
1856
 * @since 2.3
1857
 */
1858
function pods_no_conflict_check ( $object_type = 'post' ) {
1859
    if ( 'post_type' == $object_type )
1860
        $object_type = 'post';
1861
    elseif ( 'term' == $object_type )
1862
        $object_type = 'taxonomy';
1863
1864
    if ( ! class_exists( 'PodsInit' ) ) 
1865
        pods_init();
1866
1867 View Code Duplication
    if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) )
0 ignored issues
show
Bug introduced by
The property no_conflict cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1868
        return true;
1869
1870
    return false;
1871
}
1872
1873
/**
1874
 * Turn off conflicting / recursive actions for an object type that Pods hooks into
1875
 *
1876
 * @param string $object_type
1877
 * @param string $object
1878
 *
1879
 * @return bool
1880
 *
1881
 * @since 2.0
1882
 */
1883
function pods_no_conflict_on ( $object_type = 'post', $object = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $object 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...
1884
1885
    if ( 'post_type' == $object_type )
1886
        $object_type = 'post';
1887
    elseif ( 'term' == $object_type )
1888
        $object_type = 'taxonomy';
1889
1890
    if ( ! class_exists( 'PodsInit' ) ) 
1891
        pods_init();
1892
1893 View Code Duplication
    if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) )
0 ignored issues
show
Bug introduced by
The property no_conflict cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1894
        return true;
1895
1896
    if ( !is_object( PodsInit::$meta ) )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1897
        return false;
1898
1899
    $no_conflict = array(
1900
		'filter' => array()
1901
	);
1902
1903
    // Filters = Usually get/update/delete meta functions
1904
    // Actions = Usually insert/update/save/delete object functions
1905
    if ( 'post' == $object_type ) {
1906 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1907
            // Handle *_post_meta
1908
			if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1909
				$no_conflict[ 'filter' ] = array(
1910
					array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1911
				);
1912
			}
1913
1914
			if ( !pods_tableless() ) {
1915
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1916
					array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1917
					array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1918
					array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1919
				) );
1920
			}
1921
		}
1922
1923
        $no_conflict[ 'action' ] = array(
1924
            array( 'transition_post_status', array( PodsInit::$meta, 'save_post_detect_new' ), 10, 3 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1925
            array( 'save_post', array( PodsInit::$meta, 'save_post' ), 10, 2 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1926
        );
1927
    }
1928
    elseif ( 'taxonomy' == $object_type ) {
1929
		if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
1930
            // Handle *_term_meta
1931 View Code Duplication
			if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) {
1932
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1933
					array( 'get_term_metadata', array( PodsInit::$meta, 'get_term_meta' ), 10, 4 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1934
				) );
1935
			}
1936
			
1937
			if ( !pods_tableless() ) {
1938
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1939
					array( 'add_term_metadata', array( PodsInit::$meta, 'add_term_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1940
					array( 'update_term_metadata', array( PodsInit::$meta, 'update_term_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1941
					array( 'delete_term_metadata', array( PodsInit::$meta, 'delete_term_meta' ), 10, 5 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1942
				) );
1943
			}
1944
1945
			$no_conflict[ 'action' ] = array(
1946
				array( 'edited_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1947
				array( 'create_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1948
			);
1949
		}
1950
    }
1951
    elseif ( 'media' == $object_type ) {
1952
		$no_conflict[ 'filter' ] = array(
1953
			array( 'wp_update_attachment_metadata', array( PodsInit::$meta, 'save_media' ), 10, 2 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1954
		);
1955
1956
		if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1957
            // Handle *_post_meta
1958 View Code Duplication
			if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1959
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1960
					array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1961
				) );
1962
			}
1963
1964
			if ( !pods_tableless() ) {
1965
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1966
					array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1967
					array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1968
					array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1969
				) );
1970
			}
1971
1972
			$no_conflict[ 'action' ] = array();
1973
		}
1974
    }
1975
    elseif ( 'user' == $object_type ) {
1976 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
1977
            // Handle *_term_meta
1978
			if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) {
1979
				$no_conflict[ 'filter' ] = array(
1980
					array( 'get_user_metadata', array( PodsInit::$meta, 'get_user_meta' ), 10, 4 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1981
				);
1982
			}
1983
1984
			if ( !pods_tableless() ) {
1985
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1986
					array( 'add_user_metadata', array( PodsInit::$meta, 'add_user_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1987
					array( 'update_user_metadata', array( PodsInit::$meta, 'update_user_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1988
					array( 'delete_user_metadata', array( PodsInit::$meta, 'delete_user_meta' ), 10, 5 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1989
				) );
1990
			}
1991
		}
1992
1993
        $no_conflict[ 'action' ] = array(
1994
            array( 'user_register', array( PodsInit::$meta, 'save_user' ) ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1995
            array( 'profile_update', array( PodsInit::$meta, 'save_user' ), 10, 2 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1996
        );
1997
    }
1998
    elseif ( 'comment' == $object_type ) {
1999 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
2000
            // Handle *_term_meta
2001
			if ( apply_filters( 'pods_meta_handler_get', true, 'comment' ) ) {
2002
				$no_conflict[ 'filter' ] = array(
2003
					array( 'get_comment_metadata', array( PodsInit::$meta, 'get_comment_meta' ), 10, 4 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2004
				);
2005
			}
2006
2007
			if ( !pods_tableless() ) {
2008
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
2009
					array( 'add_comment_metadata', array( PodsInit::$meta, 'add_comment_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2010
					array( 'update_comment_metadata', array( PodsInit::$meta, 'update_comment_meta' ), 10, 5 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2011
					array( 'delete_comment_metadata', array( PodsInit::$meta, 'delete_comment_meta' ), 10, 5 )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2012
				) );
2013
			}
2014
		}
2015
2016
        $no_conflict[ 'action' ] = array(
2017
            array( 'pre_comment_approved', array( PodsInit::$meta, 'validate_comment' ), 10, 2 ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2018
            array( 'comment_post', array( PodsInit::$meta, 'save_comment' ) ),
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2019
            array( 'edit_comment', array( PodsInit::$meta, 'save_comment' ) )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2020
        );
2021
    }
2022
    elseif ( 'settings' == $object_type ) {
2023
        $no_conflict[ 'filter' ] = array();
2024
2025
        // @todo Better handle settings conflicts apart from each other
2026
        /*if ( empty( $object ) ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
2027
            foreach ( PodsMeta::$settings as $setting_pod ) {
2028
                foreach ( $setting_pod[ 'fields' ] as $option ) {
2029
                    $no_conflict[ 'filter' ][] = array( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2030
                    $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2031
                }
2032
            }
2033
        }
2034
        elseif ( isset( PodsMeta::$settings[ $object ] ) ) {
2035
            foreach ( PodsMeta::$settings[ $object ][ 'fields' ] as $option ) {
2036
                $no_conflict[ 'filter' ][] = array( 'pre_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2037
                $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2038
            }
2039
        }*/
2040
    }
2041
2042
    $conflicted = false;
2043
2044
    foreach ( $no_conflict as $action_filter => $conflicts ) {
2045
        foreach ( $conflicts as $k => $args ) {
2046
            if ( call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2047
                call_user_func_array( 'remove_' . $action_filter, array_slice( $args, 0, 3 ) );
2048
2049
                $conflicted = true;
2050
            }
2051
            else
2052
                unset( $no_conflict[ $action_filter ][ $k ] );
2053
        }
2054
    }
2055
2056
    if ( $conflicted ) {
2057
        PodsInit::$no_conflict[ $object_type ] = $no_conflict;
0 ignored issues
show
Bug introduced by
The property no_conflict cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2058
2059
        return true;
2060
    }
2061
2062
    return false;
2063
}
2064
2065
/**
2066
 * Turn on actions after running code during pods_conflict
2067
 *
2068
 * @param string $object_type
2069
 *
2070
 * @return bool
2071
 *
2072
 * @since 2.0
2073
 */
2074
function pods_no_conflict_off ( $object_type = 'post' ) {
2075
    if ( 'post_type' == $object_type )
2076
        $object_type = 'post';
2077
    elseif ( 'term' == $object_type )
2078
        $object_type = 'taxonomy';
2079
2080
    if ( ! class_exists( 'PodsInit' ) ) 
2081
        pods_init();
2082
2083 View Code Duplication
    if ( empty( PodsInit::$no_conflict ) || !isset( PodsInit::$no_conflict[ $object_type ] ) || empty( PodsInit::$no_conflict[ $object_type ] ) )
0 ignored issues
show
Bug introduced by
The property no_conflict cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2084
        return false;
2085
2086
    if ( !is_object( PodsInit::$meta ) )
0 ignored issues
show
Bug introduced by
The property meta cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2087
        return false;
2088
2089
    $no_conflict = PodsInit::$no_conflict[ $object_type ];
0 ignored issues
show
Bug introduced by
The property no_conflict cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2090
2091
    $conflicted = false;
2092
2093
    foreach ( $no_conflict as $action_filter => $conflicts ) {
2094
        foreach ( $conflicts as $args ) {
2095
            if ( !call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2096
                call_user_func_array( 'add_' . $action_filter, $args );
2097
2098
                $conflicted = true;
2099
            }
2100
        }
2101
    }
2102
2103
    if ( $conflicted ) {
2104
        unset( PodsInit::$no_conflict[ $object_type ] );
0 ignored issues
show
Bug introduced by
The property no_conflict cannot be accessed from this context as it is declared private in class PodsInit.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
2105
2106
        return true;
2107
    }
2108
2109
    return false;
2110
}
2111
2112
/**
2113
 * Safely start a new session (without whitescreening on certain hosts,
2114
 * which have no session path or isn't writable)
2115
 *
2116
 * @since 2.3.10
2117
 */
2118
function pods_session_start() {
2119
2120
	$save_path = session_save_path();
2121
2122
	// Check if headers were sent
2123
	if ( false !== headers_sent() ) {
2124
		return false;
2125
	}
2126
	// Allow for bypassing Pods session autostarting
2127
	elseif ( defined( 'PODS_SESSION_AUTO_START' ) && !PODS_SESSION_AUTO_START ) {
2128
		return false;
2129
	}
2130
	// Allow for non-file based sessions, like Memcache
2131
	elseif ( 0 === strpos( $save_path, 'tcp://' ) ) {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
2132
		// This is OK, but we don't want to check if file_exists on next statement
2133
	}
2134
	// Check if session path exists and can be written to, avoiding PHP fatal errors
2135
	elseif ( empty( $save_path ) || !@file_exists( $save_path ) || !is_writable( $save_path ) ) {
2136
		return false;
2137
	}
2138
	// Check if session ID is already set
2139
	elseif ( '' != session_id() ) {
2140
		return false;
2141
	}
2142
2143
	// Start session
2144
	@session_start();
2145
2146
	return true;
2147
2148
}
2149