Completed
Pull Request — 2.x (#4088)
by Phil
04:11
created

general.php ➔ pods_do_shortcode()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 35
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 16
nc 6
nop 2
dl 0
loc 35
rs 6.7272
c 0
b 0
f 0
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' ], true );
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
	if ( !empty( $shortcodes ) ) {
1002
		$temp_shortcode_filter = function ( $return, $tag, $attr, $m ) use ( $shortcodes ) {
1003
			if ( in_array( $m[2], $shortcodes ) ) {
1004
				// If shortcode being called is in list, return false to allow it to run
1005
				return false;
1006
			}
1007
			// Return original shortcode string if we aren't going to handle at this time
1008
			return $m[0];
1009
		};
1010
		add_filter( 'pre_do_shortcode_tag', $temp_shortcode_filter, 10, 4 );
1011
	}
1012
1013
	$content = do_shortcode( $content );
1014
1015
	if ( isset( $temp_shortcode_filter ) ) {
1016
		remove_filter( 'pre_do_shortcode_tag', $temp_shortcode_filter );
1017
	}
1018
1019
	return $content;
1020
1021
}
1022
1023
/**
1024
 * Check if Pods is compatible with WP / PHP / MySQL or not
1025
 *
1026
 * @return bool
1027
 *
1028
 * @since 1.10
1029
 */
1030
function pods_compatibility_check () {
1031
    $compatible = true;
1032
1033
    if ( !pods_version_check( 'wp', PODS_WP_VERSION_MINIMUM ) ) {
1034
        $compatible = false;
1035
1036
        add_action( 'admin_notices', 'pods_version_notice_wp' );
1037
    }
1038
1039
    if ( !pods_version_check( 'php', PODS_PHP_VERSION_MINIMUM ) ) {
1040
        $compatible = false;
1041
1042
        add_action( 'admin_notices', 'pods_version_notice_php' );
1043
    }
1044
1045
    if ( !pods_version_check( 'mysql', PODS_MYSQL_VERSION_MINIMUM ) ) {
1046
        $compatible = false;
1047
1048
        add_action( 'admin_notices', 'pods_version_notice_mysql' );
1049
    }
1050
1051
    return $compatible;
1052
}
1053
1054
/**
1055
 * Show WP notice if WP version is incompatible
1056
 *
1057
 * @return void
1058
 *
1059
 * @since 1.10
1060
 */
1061 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...
1062
    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...
1063
?>
1064
    <div class="error fade">
1065
        <p>
1066
            <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1067
            <strong>WordPress <?php echo esc_html( PODS_WP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1068
            <strong>WordPress <?php echo esc_html( $wp_version ); ?></strong> - <?php _e( 'Please upgrade your WordPress to continue.', 'pods' ); ?>
1069
        </p>
1070
    </div>
1071
<?php
1072
}
1073
1074
/**
1075
 * Show WP notice if PHP version is incompatible
1076
 *
1077
 * @return void
1078
 *
1079
 * @since 1.10
1080
 */
1081 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...
1082
?>
1083
    <div class="error fade">
1084
        <p>
1085
            <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1086
            <strong>PHP <?php echo esc_html( PODS_PHP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1087
            <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' ); ?>
1088
        </p>
1089
    </div>
1090
<?php
1091
}
1092
1093
/**
1094
 * Show WP notice if MySQL version is incompatible
1095
 *
1096
 * @return void
1097
 *
1098
 * @since 1.10
1099
 */
1100 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...
1101
    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...
1102
    $mysql = $wpdb->db_version();
1103
?>
1104
    <div class="error fade">
1105
        <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1106
            <strong>MySQL <?php echo esc_html( PODS_MYSQL_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1107
            <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' ); ?>
1108
        </p>
1109
    </div>
1110
<?php
1111
}
1112
1113
/**
1114
 * Check if a Function exists or File exists in Theme / Child Theme
1115
 *
1116
 * @param string $function_or_file Function or file name to look for.
1117
 * @param string $function_name (optional) Function name to look for.
1118
 * @param string $file_dir (optional) Drectory to look into
1119
 * @param string $file_name (optional) Filename to look for
1120
 *
1121
 * @return mixed
1122
 *
1123
 * @since 1.12
1124
 */
1125
function pods_function_or_file ( $function_or_file, $function_name = null, $file_dir = null, $file_name = null ) {
1126
    $found = false;
1127
    $function_or_file = (string) $function_or_file;
1128
    if ( false !== $function_name ) {
1129
        if ( null === $function_name )
1130
            $function_name = $function_or_file;
1131
        $function_name = str_replace( array(
1132
            '__',
1133
            '__',
1134
            '__'
1135
        ), '_', preg_replace( '/[^a-z^A-Z^_][^a-z^A-Z^0-9^_]*/', '_', (string) $function_name ) );
1136
        if ( function_exists( 'pods_custom_' . $function_name ) )
1137
            $found = array( 'function' => 'pods_custom_' . $function_name );
1138
        elseif ( function_exists( $function_name ) )
1139
            $found = array( 'function' => $function_name );
1140
    }
1141
    if ( false !== $file_name && false === $found ) {
1142
        if ( null === $file_name )
1143
            $file_name = $function_or_file;
1144
        $file_name = str_replace( array(
1145
            '__',
1146
            '__',
1147
            '__'
1148
        ), '_', preg_replace( '/[^a-z^A-Z^0-9^_]*/', '_', (string) $file_name ) ) . '.php';
1149
        $custom_location = apply_filters( 'pods_file_directory', null, $function_or_file, $function_name, $file_dir, $file_name );
1150
        if ( defined( 'PODS_FILE_DIRECTORY' ) && false !== PODS_FILE_DIRECTORY )
1151
            $custom_location = PODS_FILE_DIRECTORY;
1152
        if ( !empty( $custom_location ) && locate_template( trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
1153
            $found = array( 'file' => trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
1154 View Code Duplication
        elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
1155
            $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
1156 View Code Duplication
        elseif ( locate_template( 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
1157
            $found = array( 'file' => 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
1158 View Code Duplication
        elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
1159
            $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
1160
    }
1161
1162
    return apply_filters( 'pods_function_or_file', $found, $function_or_file, $function_name, $file_name );
1163
}
1164
1165
/**
1166
 * Redirects to another page.
1167
 *
1168
 * @param string $location The path to redirect to
1169
 * @param int $status Status code to use
1170
 *
1171
 * @return void
1172
 *
1173
 * @since 2.0
1174
 */
1175
function pods_redirect ( $location, $status = 302 ) {
1176
    if ( !headers_sent() ) {
1177
        wp_redirect( $location, $status );
1178
        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...
1179
    }
1180
    else {
1181
        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...
1182
            . 'document.location = "' . str_replace( '&amp;', '&', esc_js( $location ) ) . '";'
1183
            . '</script>' );
1184
    }
1185
}
1186
1187
/**
1188
 * Check if a user has permission to be doing something based on standard permission options
1189
 *
1190
 * @param array $options
1191
 *
1192
 * @return bool Whether the user has permissions
1193
 *
1194
 * @since 2.0.5
1195
 */
1196
function pods_permission ( $options ) {
1197
    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...
1198
1199
    wp_get_current_user();
1200
1201
    $permission = false;
1202
1203
    if ( isset( $options[ 'options' ] ) )
1204
        $options = $options[ 'options' ];
1205
1206
    if ( pods_is_admin() )
1207
        $permission = true;
1208
    elseif ( 0 == pods_v( 'restrict_role', $options, 0 ) && 0 == pods_v( 'restrict_capability', $options, 0 ) && 0 == pods_v( 'admin_only', $options, 0 ) )
1209
        $permission = true;
1210
1211
    if ( !$permission && 1 == pods_v( 'restrict_role', $options, 0 ) ) {
1212
        $roles = pods_v( 'roles_allowed', $options );
1213
1214
        if ( !is_array( $roles ) )
1215
            $roles = explode( ',', $roles );
1216
1217
        $roles = array_unique( array_filter( $roles ) );
1218
1219
        foreach( $roles as $role ) {
1220
            if ( is_user_logged_in() && in_array( $role, $current_user->roles ) ) {
1221
                $permission = true;
1222
1223
                break;
1224
            }
1225
        }
1226
    }
1227
1228
    if ( !$permission && 1 == pods_v( 'restrict_capability', $options, 0 ) ) {
1229
        $capabilities = pods_v( 'capability_allowed', $options );
1230
1231
        if ( !is_array( $capabilities ) )
1232
            $capabilities = explode( ',', $capabilities );
1233
1234
        $capabilities = array_unique( array_filter( $capabilities ) );
1235
1236
        foreach( $capabilities as $capability ) {
1237
            $must_have_capabilities = explode( '&&', $capability );
1238
            $must_have_capabilities = array_unique( array_filter( $must_have_capabilities ) );
1239
1240
            $must_have_permission = true;
1241
1242
            foreach ( $must_have_capabilities as $must_have_capability ) {
1243
                if ( !current_user_can( $must_have_capability ) ) {
1244
                    $must_have_permission = false;
1245
1246
                    break;
1247
                }
1248
            }
1249
1250
            if ( $must_have_permission && is_user_logged_in() ) {
1251
                $permission = true;
1252
1253
                break;
1254
            }
1255
        }
1256
    }
1257
1258
    return $permission;
1259
}
1260
1261
/**
1262
 * Check if permissions are restricted
1263
 *
1264
 * @param array $options
1265
 *
1266
 * @return bool Whether the permissions are restricted
1267
 *
1268
 * @since 2.3.4
1269
 */
1270
function pods_has_permissions ( $options ) {
1271
    $permission = false;
1272
1273
    if ( isset( $options[ 'options' ] ) )
1274
        $options = $options[ 'options' ];
1275
1276
    if ( 1 == pods_v( 'restrict_role', $options, 0 ) || 1 == pods_v( 'restrict_capability', $options, 0 ) || 1 == pods_v( 'admin_only', $options, 0 ) )
1277
        return true;
1278
1279
    return false;
1280
}
1281
1282
/**
1283
 * A fork of get_page_by_title that excludes items unavailable via access rights (by status)
1284
 *
1285
 * @see get_page_by_title
1286
 *
1287
 * @param string $title Title of item to get
1288
 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
1289
 * @param string $type Post Type
1290
 * @param string|array $status Post statuses to include (default is what user has access to)
1291
 *
1292
 * @return WP_Post|null WP_Post on success or null on failure
1293
 *
1294
 * @since 2.3.4
1295
 */
1296
function pods_by_title ( $title, $output = OBJECT, $type = 'page', $status = null ) {
1297
    // @todo support Pod item lookups, not just Post Types
1298
1299
    /**
1300
     * @var $wpdb WPDB
1301
     */
1302
    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...
1303
1304
    if ( empty( $status ) ) {
1305
        $status = array(
1306
            'publish'
1307
        );
1308
1309
        if ( current_user_can( 'read_private_' . $type . 's') )
1310
            $status[] = 'private';
1311
1312
        if ( current_user_can( 'edit_' . $type . 's' ) )
1313
            $status[] = 'draft';
1314
    }
1315
1316
    $status = (array) $status;
1317
1318
    $status_sql = ' AND `post_status` IN ( %s' . str_repeat( ', %s', count( $status ) -1 ) . ' )';
1319
1320
    $orderby_sql = ' ORDER BY ( `post_status` = %s ) DESC' . str_repeat( ', ( `post_status` = %s ) DESC', count( $status ) - 1 ) . ', `ID` DESC';
1321
1322
    $prepared = array_merge( array( $title, $type ), $status, $status ); // once for WHERE, once for ORDER BY
1323
1324
    $page = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` = %s AND `post_type` = %s" . $status_sql . $orderby_sql, $prepared ) );
1325
1326
    if ( $page )
1327
        return get_post( pods_v( $page, 'post_id' ), $output );
1328
1329
    return null;
1330
}
1331
1332
/**
1333
 * Get a field value from a Pod
1334
 *
1335
 * @param string $pod The pod name
1336
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1337
 * @param string|array $name The field name, or an associative array of parameters
1338
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1339
 *
1340
 * @return mixed Field value
1341
 *
1342
 * @since 2.1
1343
 */
1344 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...
1345
    // 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...
1346
    if ( null === $name ) {
1347
        $name = $pod;
1348
        $single = (boolean) $id;
1349
1350
        $pod = get_post_type();
1351
        $id = get_the_ID();
1352
    }
1353
1354
    $pod = pods( $pod, $id );
1355
1356
	if ( is_object( $pod ) ) {
1357
		return $pod->field( $name, $single );
1358
	}
1359
1360
	return null;
1361
}
1362
1363
/**
1364
 * Get a field display value from a Pod
1365
 *
1366
 * @param string $pod The pod name
1367
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1368
 * @param string|array $name The field name, or an associative array of parameters
1369
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1370
 *
1371
 * @return mixed Field value
1372
 *
1373
 * @since 2.1
1374
 */
1375 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...
1376
    // 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...
1377
    if ( null === $name ) {
1378
        $name = $pod;
1379
        $single = (boolean) $id;
1380
1381
        $pod = get_post_type();
1382
        $id = get_the_ID();
1383
    }
1384
1385
    $pod = pods( $pod, $id );
1386
1387
	if ( is_object( $pod ) ) {
1388
		return $pod->display( $name, $single );
1389
	}
1390
1391
	return null;
1392
}
1393
1394
/**
1395
 * Get a field raw value from a Pod
1396
 *
1397
 * @param string $pod The pod name
1398
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1399
 * @param string|array $name The field name, or an associative array of parameters
1400
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1401
 *
1402
 * @return mixed Field value
1403
 *
1404
 * @since 2.1
1405
 */
1406
function pods_field_raw ( $pod, $id = false, $name = null, $single = false ) {
1407
    // 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...
1408
    if ( null === $name ) {
1409
        $name = $pod;
1410
        $single = (boolean) $id;
1411
1412
        $pod = get_post_type();
1413
        $id = get_the_ID();
1414
    }
1415
1416
    return pods( $pod, $id )->raw( $name, $single );
1417
1418
}
1419
1420
/**
1421
 * Set a cached value
1422
 *
1423
 * @see PodsView::set
1424
 *
1425
 * @param string $key Key for the cache
1426
 * @param mixed $value Value to add to the cache
1427
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1428
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1429
 * @param string $group (optional) Key for the group
1430
 *
1431
 * @return bool|mixed|null|string|void
1432
 *
1433
 * @since 2.0
1434
 */
1435
function pods_view_set ( $key, $value, $expires = 0, $cache_mode = 'cache', $group = '' ) {
1436
    require_once( PODS_DIR . 'classes/PodsView.php' );
1437
1438
    return PodsView::set( $key, $value, $expires, $cache_mode, $group );
1439
}
1440
1441
/**
1442
 * Get a cached value
1443
 *
1444
 * @see PodsView::get
1445
 *
1446
 * @param string $key Key for the cache
1447
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1448
 * @param string $group (optional) Key for the group
1449
 * @param string $callback (optional) Callback function to run to set the value if not cached
1450
 *
1451
 * @return bool|mixed|null|void
1452
 *
1453
 * @since 2.0
1454
 */
1455
function pods_view_get ( $key, $cache_mode = 'cache', $group = '', $callback = null ) {
1456
    require_once( PODS_DIR . 'classes/PodsView.php' );
1457
1458
    return PodsView::get( $key, $cache_mode, $group, $callback );
1459
}
1460
1461
/**
1462
 * Clear a cached value
1463
 *
1464
 * @see PodsView::clear
1465
 *
1466
 * @param string|bool $key Key for the cache
1467
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1468
 * @param string $group (optional) Key for the group
1469
 *
1470
 * @return bool
1471
 *
1472
 * @since 2.0
1473
 */
1474
function pods_view_clear ( $key = true, $cache_mode = 'cache', $group = '' ) {
1475
    require_once( PODS_DIR . 'classes/PodsView.php' );
1476
1477
    return PodsView::clear( $key, $cache_mode, $group );
1478
}
1479
1480
/**
1481
 * Set a cached value
1482
 *
1483
 * @see PodsView::set
1484
 *
1485
 * @param string $key Key for the cache
1486
 * @param mixed $value Value to add to the cache
1487
 * @param string $group (optional) Key for the group
1488
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1489
 *
1490
 * @return bool|mixed|null|string|void
1491
 *
1492
 * @since 2.0
1493
 */
1494
function pods_cache_set ( $key, $value, $group = '', $expires = 0) {
1495
    return pods_view_set( $key, $value, $expires, 'cache', $group );
1496
}
1497
1498
/**
1499
 * Get a cached value
1500
 *
1501
 * @see PodsView::get
1502
 *
1503
 * @param string $key Key for the cache
1504
 * @param string $group (optional) Key for the group
1505
 * @param string $callback (optional) Callback function to run to set the value if not cached
1506
 *
1507
 * @return bool
1508
 *
1509
 * @since 2.0
1510
 */
1511
function pods_cache_get ( $key, $group = '', $callback = null ) {
1512
    return pods_view_get( $key, 'cache', $group, $callback );
1513
}
1514
1515
/**
1516
 * Clear a cached value
1517
 *
1518
 * @see PodsView::clear
1519
 *
1520
 * @param string|bool $key Key for the cache
1521
 * @param string $group (optional) Key for the group
1522
 *
1523
 * @return bool|mixed|null|void
1524
 *
1525
 * @since 2.0
1526
 */
1527
function pods_cache_clear ( $key = true, $group = '' ) {
1528
    return pods_view_clear( $key, 'cache', $group );
1529
}
1530
1531
/**
1532
 * Set a cached value
1533
 *
1534
 * @see PodsView::set
1535
 *
1536
 * @param string $key Key for the cache
1537
 * @param mixed $value Value to add to the cache
1538
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1539
 *
1540
 * @return bool|mixed|null|string|void
1541
 *
1542
 * @since 2.0
1543
 */
1544
function pods_transient_set ( $key, $value, $expires = 0 ) {
1545
    return pods_view_set( $key, $value, $expires, 'transient' );
1546
}
1547
1548
/**
1549
 * Get a cached value
1550
 *
1551
 * @see PodsView::get
1552
 *
1553
 * @param string $key Key for the cache
1554
 * @param string $callback (optional) Callback function to run to set the value if not cached
1555
 *
1556
 * @return bool|mixed|null|void
1557
 *
1558
 * @since 2.0
1559
 */
1560
function pods_transient_get ( $key, $callback = null ) {
1561
    return pods_view_get( $key, 'transient', '', $callback );
1562
}
1563
1564
/**
1565
 * Clear a cached value
1566
 *
1567
 * @see PodsView::clear
1568
 *
1569
 * @param string|bool $key Key for the cache
1570
 *
1571
 * @return bool
1572
 *
1573
 * @since 2.0
1574
 */
1575
function pods_transient_clear ( $key = true ) {
1576
    return pods_view_clear( $key, 'transient' );
1577
}
1578
1579
/**
1580
 * Set a cached value
1581
 *
1582
 * @see PodsView::set
1583
 *
1584
 * @param string $key Key for the cache
1585
 * @param mixed $value Value to add to the cache
1586
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1587
 *
1588
 * @return bool|mixed|null|string|void
1589
 *
1590
 * @since 2.3.10
1591
 */
1592
function pods_site_transient_set ( $key, $value, $expires = 0 ) {
1593
    return pods_view_set( $key, $value, $expires, 'site-transient' );
1594
}
1595
1596
/**
1597
 * Get a cached value
1598
 *
1599
 * @see PodsView::get
1600
 *
1601
 * @param string $key Key for the cache
1602
 * @param string $callback (optional) Callback function to run to set the value if not cached
1603
 *
1604
 * @return bool|mixed|null|void
1605
 *
1606
 * @since 2.3.10
1607
 */
1608
function pods_site_transient_get ( $key, $callback = null ) {
1609
    return pods_view_get( $key, 'site-transient', '', $callback );
1610
}
1611
1612
/**
1613
 * Clear a cached value
1614
 *
1615
 * @see PodsView::clear
1616
 *
1617
 * @param string|bool $key Key for the cache
1618
 *
1619
 * @return bool
1620
 *
1621
 * @since 2.3.10
1622
 */
1623
function pods_site_transient_clear ( $key = true ) {
1624
    return pods_view_clear( $key, 'site-transient' );
1625
}
1626
1627
/**
1628
 * Set a cached value
1629
 *
1630
 * @see PodsView::set
1631
 *
1632
 * @param string $key Key for the cache
1633
 * @param mixed $value Value to add to the cache
1634
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1635
 * @param string $group (optional) Key for the group
1636
 *
1637
 * @return bool|mixed|null|string|void
1638
 *
1639
 * @since 2.3.10
1640
 */
1641
function pods_option_cache_set ( $key, $value, $expires = 0, $group = '' ) {
1642
    return pods_view_set( $key, $value, $expires, 'option-cache', $group );
1643
}
1644
1645
/**
1646
 * Get a cached value
1647
 *
1648
 * @see PodsView::get
1649
 *
1650
 * @param string $key Key for the cache
1651
 * @param string $group (optional) Key for the group
1652
 * @param string $callback (optional) Callback function to run to set the value if not cached
1653
 *
1654
 * @return bool|mixed|null|void
1655
 *
1656
 * @since 2.3.10
1657
 */
1658
function pods_option_cache_get ( $key, $group = '', $callback = null ) {
1659
    return pods_view_get( $key, 'option-cache', $group, $callback );
1660
}
1661
1662
/**
1663
 * Clear a cached value
1664
 *
1665
 * @see PodsView::clear
1666
 *
1667
 * @param string|bool $key Key for the cache
1668
 * @param string $group (optional) Key for the group
1669
 *
1670
 * @return bool
1671
 *
1672
 * @since 2.3.10
1673
 */
1674
function pods_option_cache_clear ( $key = true, $group = '' ) {
1675
    return pods_view_clear( $key, 'option-cache', $group );
1676
}
1677
1678
/**
1679
 * Scope variables and include a template like get_template_part that's child-theme aware
1680
 *
1681
 * @see get_template_part
1682
 *
1683
 * @param string|array $template Template names (see get_template_part)
1684
 * @param array $data Data to scope to the include
1685
 * @param bool $return Whether to return the output (echo by default)
1686
 * @return string|null Template output
1687
 *
1688
 * @since 2.3.9
1689
 */
1690
function pods_template_part ( $template, $data = null, $return = false ) {
1691
    $part = PodsView::get_template_part( $template, $data );
1692
1693
    if ( !$return ) {
1694
        echo $part;
1695
1696
        return null;
1697
    }
1698
1699
    return $part;
1700
}
1701
1702
/**
1703
 * Add a new Pod outside of the DB
1704
 *
1705
 * @see PodsMeta::register
1706
 *
1707
 * @param string $type The pod type ('post_type', 'taxonomy', 'media', 'user', 'comment')
1708
 * @param string $name The pod name
1709
 * @param array $object (optional) Pod array, including any 'fields' arrays
1710
 *
1711
 * @return array|boolean Pod data or false if unsuccessful
1712
 * @since 2.1
1713
 */
1714
function pods_register_type ( $type, $name, $object = null ) {
1715
    if ( empty( $object ) )
1716
        $object = array();
1717
1718
    if ( !empty( $name ) )
1719
        $object[ 'name' ] = $name;
1720
1721
    return pods_meta()->register( $type, $object );
1722
}
1723
1724
/**
1725
 * Add a new Pod field outside of the DB
1726
 *
1727
 * @see PodsMeta::register_field
1728
 *
1729
 * @param string|array $pod The pod name or array of pod names
1730
 * @param string $name The name of the Pod
1731
 * @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...
1732
 *
1733
 * @return array|boolean Field data or false if unsuccessful
1734
 * @since 2.1
1735
 */
1736
function pods_register_field ( $pod, $name, $field = null ) {
1737
    if ( empty( $field ) )
1738
        $field = array();
1739
1740
    if ( !empty( $name ) )
1741
        $field[ 'name' ] = $name;
1742
1743
    return pods_meta()->register_field( $pod, $field );
1744
}
1745
1746
/**
1747
 * Add a new Pod field type
1748
 *
1749
 * @see PodsForm::register_field_type
1750
 *
1751
 * @param string $type The new field type identifier
1752
 * @param string $file The new field type class file location
1753
 *
1754
 * @return array Field type array
1755
 * @since 2.3
1756
 */
1757
function pods_register_field_type ( $type, $file = null ) {
1758
    return PodsForm::register_field_type( $type, $file );
1759
}
1760
1761
/**
1762
 * Register a related object
1763
 *
1764
 * @param string $name Object name
1765
 * @param string $label Object label
1766
 * @param array $options Object options
1767
 *
1768
 * @return array|boolean Object array or false if unsuccessful
1769
 * @since 2.3
1770
 */
1771
function pods_register_related_object ( $name, $label, $options = null ) {
1772
    return PodsForm::field_method( 'pick', 'register_related_object', $name, $label, $options );
1773
}
1774
1775
/**
1776
 * Require a component (always-on)
1777
 *
1778
 * @param string $component Component ID
1779
 *
1780
 * @return void
1781
 *
1782
 * @since 2.3
1783
 */
1784
function pods_require_component ( $component ) {
1785
    add_filter( 'pods_component_require_' . $component, '__return_true' );
1786
}
1787
1788
/**
1789
 * Add a meta group of fields to add/edit forms
1790
 *
1791
 * @see PodsMeta::group_add
1792
 *
1793
 * @param string|array $pod The pod or type of element to attach the group to.
1794
 * @param string $label Title of the edit screen section, visible to user.
1795
 * @param string|array $fields Either a comma separated list of text fields or an associative array containing field information.
1796
 * @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').
1797
 * @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low').
1798
 * @param string $type (optional) Type of the post to attach to.
1799
 *
1800
 * @return void
1801
 *
1802
 * @since 2.0
1803
 * @link http://pods.io/docs/pods-group-add/
1804
 */
1805
function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) {
1806 View Code Duplication
    if ( !is_array( $pod ) && null !== $type ) {
1807
        $pod = array(
1808
            'name' => $pod,
1809
            'type' => $type
1810
        );
1811
    }
1812
1813
    pods_meta()->group_add( $pod, $label, $fields, $context, $priority );
1814
}
1815
1816
/**
1817
 * Check if a plugin is active on non-admin pages (is_plugin_active() only available in admin)
1818
 *
1819
 * @param string $plugin Plugin name.
1820
 *
1821
 * @return bool
1822
 *
1823
 * @since 2.0
1824
 */
1825
function pods_is_plugin_active ( $plugin ) {
1826
    $active = false;
1827
1828
    if ( function_exists( 'is_plugin_active' ) )
1829
        $active = is_plugin_active( $plugin );
1830
1831
    if ( !$active ) {
1832
        $active_plugins = (array) get_option( 'active_plugins', array() );
1833
1834
        if ( in_array( $plugin, $active_plugins ) )
1835
            $active = true;
1836
1837
        if ( !$active && is_multisite() ) {
1838
            $plugins = get_site_option( 'active_sitewide_plugins' );
1839
1840
            if ( isset( $plugins[ $plugin ] ) )
1841
                $active = true;
1842
        }
1843
    }
1844
1845
    return $active;
1846
}
1847
1848
/**
1849
 * Check if Pods no conflict is on or not
1850
 *
1851
 * @param string $object_type
1852
 *
1853
 * @return bool
1854
 *
1855
 * @since 2.3
1856
 */
1857
function pods_no_conflict_check ( $object_type = 'post' ) {
1858
    if ( 'post_type' == $object_type )
1859
        $object_type = 'post';
1860
    elseif ( 'term' == $object_type )
1861
        $object_type = 'taxonomy';
1862
1863
    if ( ! class_exists( 'PodsInit' ) ) 
1864
        pods_init();
1865
1866 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...
1867
        return true;
1868
1869
    return false;
1870
}
1871
1872
/**
1873
 * Turn off conflicting / recursive actions for an object type that Pods hooks into
1874
 *
1875
 * @param string $object_type
1876
 * @param string $object
1877
 *
1878
 * @return bool
1879
 *
1880
 * @since 2.0
1881
 */
1882
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...
1883
1884
    if ( 'post_type' == $object_type )
1885
        $object_type = 'post';
1886
    elseif ( 'term' == $object_type )
1887
        $object_type = 'taxonomy';
1888
1889
    if ( ! class_exists( 'PodsInit' ) ) 
1890
        pods_init();
1891
1892 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...
1893
        return true;
1894
1895
    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...
1896
        return false;
1897
1898
    $no_conflict = array(
1899
		'filter' => array()
1900
	);
1901
1902
    // Filters = Usually get/update/delete meta functions
1903
    // Actions = Usually insert/update/save/delete object functions
1904
    if ( 'post' == $object_type ) {
1905 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1906
            // Handle *_post_meta
1907
			if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1908
				$no_conflict[ 'filter' ] = array(
1909
					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...
1910
				);
1911
			}
1912
1913
			if ( !pods_tableless() ) {
1914
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1915
					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...
1916
					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...
1917
					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...
1918
				) );
1919
			}
1920
		}
1921
1922
        $no_conflict[ 'action' ] = array(
1923
            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...
1924
            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...
1925
        );
1926
    }
1927
    elseif ( 'taxonomy' == $object_type ) {
1928
		if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
1929
            // Handle *_term_meta
1930 View Code Duplication
			if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) {
1931
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1932
					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...
1933
				) );
1934
			}
1935
			
1936
			if ( !pods_tableless() ) {
1937
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1938
					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...
1939
					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...
1940
					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...
1941
				) );
1942
			}
1943
1944
			$no_conflict[ 'action' ] = array(
1945
				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...
1946
				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...
1947
			);
1948
		}
1949
    }
1950
    elseif ( 'media' == $object_type ) {
1951
		$no_conflict[ 'filter' ] = array(
1952
			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...
1953
		);
1954
1955
		if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1956
            // Handle *_post_meta
1957 View Code Duplication
			if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1958
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1959
					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...
1960
				) );
1961
			}
1962
1963
			if ( !pods_tableless() ) {
1964
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1965
					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...
1966
					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...
1967
					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...
1968
				) );
1969
			}
1970
1971
			$no_conflict[ 'action' ] = array();
1972
		}
1973
    }
1974
    elseif ( 'user' == $object_type ) {
1975 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
1976
            // Handle *_term_meta
1977
			if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) {
1978
				$no_conflict[ 'filter' ] = array(
1979
					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...
1980
				);
1981
			}
1982
1983
			if ( !pods_tableless() ) {
1984
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1985
					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...
1986
					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...
1987
					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...
1988
				) );
1989
			}
1990
		}
1991
1992
        $no_conflict[ 'action' ] = array(
1993
            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...
1994
            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...
1995
        );
1996
    }
1997
    elseif ( 'comment' == $object_type ) {
1998 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
1999
            // Handle *_term_meta
2000
			if ( apply_filters( 'pods_meta_handler_get', true, 'comment' ) ) {
2001
				$no_conflict[ 'filter' ] = array(
2002
					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...
2003
				);
2004
			}
2005
2006
			if ( !pods_tableless() ) {
2007
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
2008
					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...
2009
					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...
2010
					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...
2011
				) );
2012
			}
2013
		}
2014
2015
        $no_conflict[ 'action' ] = array(
2016
            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...
2017
            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...
2018
            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...
2019
        );
2020
    }
2021
    elseif ( 'settings' == $object_type ) {
2022
        $no_conflict[ 'filter' ] = array();
2023
2024
        // @todo Better handle settings conflicts apart from each other
2025
        /*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...
2026
            foreach ( PodsMeta::$settings as $setting_pod ) {
2027
                foreach ( $setting_pod[ 'fields' ] as $option ) {
2028
                    $no_conflict[ 'filter' ][] = array( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2029
                    $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2030
                }
2031
            }
2032
        }
2033
        elseif ( isset( PodsMeta::$settings[ $object ] ) ) {
2034
            foreach ( PodsMeta::$settings[ $object ][ 'fields' ] as $option ) {
2035
                $no_conflict[ 'filter' ][] = array( 'pre_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2036
                $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2037
            }
2038
        }*/
2039
    }
2040
2041
    $conflicted = false;
2042
2043
    foreach ( $no_conflict as $action_filter => $conflicts ) {
2044
        foreach ( $conflicts as $k => $args ) {
2045
            if ( call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2046
                call_user_func_array( 'remove_' . $action_filter, array_slice( $args, 0, 3 ) );
2047
2048
                $conflicted = true;
2049
            }
2050
            else
2051
                unset( $no_conflict[ $action_filter ][ $k ] );
2052
        }
2053
    }
2054
2055
    if ( $conflicted ) {
2056
        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...
2057
2058
        return true;
2059
    }
2060
2061
    return false;
2062
}
2063
2064
/**
2065
 * Turn on actions after running code during pods_conflict
2066
 *
2067
 * @param string $object_type
2068
 *
2069
 * @return bool
2070
 *
2071
 * @since 2.0
2072
 */
2073
function pods_no_conflict_off ( $object_type = 'post' ) {
2074
    if ( 'post_type' == $object_type )
2075
        $object_type = 'post';
2076
    elseif ( 'term' == $object_type )
2077
        $object_type = 'taxonomy';
2078
2079
    if ( ! class_exists( 'PodsInit' ) ) 
2080
        pods_init();
2081
2082 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...
2083
        return false;
2084
2085
    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...
2086
        return false;
2087
2088
    $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...
2089
2090
    $conflicted = false;
2091
2092
    foreach ( $no_conflict as $action_filter => $conflicts ) {
2093
        foreach ( $conflicts as $args ) {
2094
            if ( !call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2095
                call_user_func_array( 'add_' . $action_filter, $args );
2096
2097
                $conflicted = true;
2098
            }
2099
        }
2100
    }
2101
2102
    if ( $conflicted ) {
2103
        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...
2104
2105
        return true;
2106
    }
2107
2108
    return false;
2109
}
2110
2111
/**
2112
 * Safely start a new session (without whitescreening on certain hosts,
2113
 * which have no session path or isn't writable)
2114
 *
2115
 * @since 2.3.10
2116
 */
2117
function pods_session_start() {
2118
2119
	$save_path = session_save_path();
2120
2121
	// Check if headers were sent
2122
	if ( false !== headers_sent() ) {
2123
		return false;
2124
	}
2125
	// Allow for bypassing Pods session autostarting
2126
	elseif ( defined( 'PODS_SESSION_AUTO_START' ) && !PODS_SESSION_AUTO_START ) {
2127
		return false;
2128
	}
2129
	// Allow for non-file based sessions, like Memcache
2130
	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...
2131
		// This is OK, but we don't want to check if file_exists on next statement
2132
	}
2133
	// Check if session path exists and can be written to, avoiding PHP fatal errors
2134
	elseif ( empty( $save_path ) || !@file_exists( $save_path ) || !is_writable( $save_path ) ) {
2135
		return false;
2136
	}
2137
	// Check if session ID is already set
2138
	elseif ( '' != session_id() ) {
2139
		return false;
2140
	}
2141
2142
	// Start session
2143
	@session_start();
2144
2145
	return true;
2146
2147
}
2148