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

general.php ➔ pods_is_modal_window()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
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
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...
96
$pods_errors = array();
97
98
/**
99
 * Error Handling which throws / displays errors
100
 *
101
 * @param string $error The error message to be thrown / displayed
102
 * @param object / boolean $obj If object, if $obj->display_errors is set, and is set to true: display errors;
103
 *                              If boolean, and is set to true: display errors
104
 *
105
 * @throws Exception
106
 *
107
 * @return mixed|void
108
 *
109
 * @since 2.0
110
 */
111
function pods_error ( $error, $obj = null ) {
112
113
    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...
114
115
    $display_errors = false;
116
117
    if ( is_object( $obj ) && isset( $obj->display_errors ) && true === $obj->display_errors )
118
        $display_errors = true;
119
    elseif ( is_bool( $obj ) && true === $obj )
120
        $display_errors = true;
121
122
    if ( is_object( $error ) && 'Exception' == get_class( $error ) ) {
123
        $error = $error->getMessage();
124
        $display_errors = false;
125
    }
126
127
    if ( is_array( $error ) ) {
128
        if ( 1 == count( $error ) )
129
            $error = current( $error );
130
        elseif ( defined( 'DOING_AJAX' ) && DOING_AJAX )
131
            $error = __( 'The following issue occurred:', 'pods' ) . "\n\n- " . implode( "\n- ", $error );
132
        else
133
            $error = __( 'The following issues occurred:', 'pods' ) . "\n<ul><li>" . implode( "</li>\n<li>", $error ) . "</li></ul>";
134
    }
135
136
    if ( is_object( $error ) )
137
        $error = __( 'An unknown error has occurred', 'pods' );
138
139
    // log error in WP
140
    $log_error = new WP_Error( 'pods-error-' . md5( $error ), $error );
141
142
    // throw error as Exception and return false if silent
143
    if ( $pods_errors !== $error && false === $display_errors && !empty( $error ) ) {
144
        $exception_bypass = apply_filters( 'pods_error_exception', null, $error );
145
146
        if ( null !== $exception_bypass )
147
            return $exception_bypass;
148
149
        $pods_errors = $error;
150
151
        set_exception_handler( 'pods_error' );
152
153
        throw new Exception( $error );
154
    }
155
156
    $pods_errors = array();
157
158
    $die_bypass = apply_filters( 'pods_error_die', null, $error );
159
160
    if ( null !== $die_bypass )
161
        return $die_bypass;
162
163
    // die with error
164
    if ( !defined( 'DOING_AJAX' ) && !headers_sent() && ( is_admin() || false !== strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) )
165
        wp_die( $error );
166
    else
167
        die( "<e>$error</e>" );
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...
168
}
169
170
/**
171
 * Debug variable used in pods_debug to count the instances debug is used
172
 */
173
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...
174
$pods_debug = 0;
175
/**
176
 * Debugging common issues using this function saves a few lines and is compatible with
177
 *
178
 * @param mixed $debug The error message to be thrown / displayed
179
 * @param boolean $die If set to true, a die() will occur, if set to (int) 2 then a wp_die() will occur
180
 * @param string $prefix
181
 *
182
 * @return void
183
 *
184
 * @since 2.0
185
 */
186
function pods_debug ( $debug = '_null', $die = false, $prefix = '_null' ) {
187
    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...
188
189
    $pods_debug++;
190
191
    ob_start();
192
193
    if ( '_null' !== $prefix )
194
        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...
195
196
    if ( '_null' !== $debug )
197
        var_dump( $debug );
198
    else
199
        var_dump( 'Pods Debug #' . $pods_debug );
200
201
    $debug = ob_get_clean();
202
203
    if ( false === strpos( $debug, "<pre class='xdebug-var-dump'" ) && ( !ini_get( 'xdebug.overload_var_dump' ) && !ini_get( 'html_errors' ) ) ) {
204
        if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX )
205
            $debug = esc_html( $debug );
206
207
        $debug = '<pre>' . $debug . '</pre>';
208
    }
209
210
    $debug = '<e>' . $debug;
211
212
    if ( 2 === $die )
213
        wp_die( $debug );
214
    elseif ( true === $die )
215
        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...
216
217
    echo $debug;
218
}
219
220
/**
221
 * Determine if user has admin access
222
 *
223
 * @param string|array $cap Additional capabilities to check
224
 *
225
 * @return bool Whether user has admin access
226
 *
227
 * @since 2.3.5
228
 */
229
function pods_is_admin ( $cap = null ) {
230
    if ( is_user_logged_in() ) {
231
        $pods_admin_capabilities = array(
232
            'delete_users' // default is_super_admin checks against this
233
        );
234
235
        $pods_admin_capabilities = apply_filters( 'pods_admin_capabilities', $pods_admin_capabilities, $cap );
236
237
        if ( is_multisite() && is_super_admin() )
238
            return apply_filters( 'pods_is_admin', true, $cap, '_super_admin' );
239
240
        if ( empty( $cap ) )
241
            $cap = array();
242
        else
243
            $cap = (array) $cap;
244
245
        $cap = array_unique( array_filter( array_merge( $pods_admin_capabilities, $cap ) ) );
246
247
        foreach ( $cap as $capability ) {
248
            if ( current_user_can( $capability ) )
249
                return apply_filters( 'pods_is_admin', true, $cap, $capability );
250
        }
251
    }
252
253
    return apply_filters( 'pods_is_admin', false, $cap, null );
254
}
255
256
/**
257
 * Determine if Developer Mode is enabled
258
 *
259
 * @return bool Whether Developer Mode is enabled
260
 *
261
 * @since 2.3
262
 */
263
function pods_developer () {
264
    if ( defined( 'PODS_DEVELOPER' ) && PODS_DEVELOPER )
265
        return true;
266
267
    return false;
268
}
269
270
/**
271
 * Determine if Tableless Mode is enabled
272
 *
273
 * @return bool Whether Tableless Mode is enabled
274
 *
275
 * @since 2.3
276
 */
277
function pods_tableless () {
278
    if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
279
        return true;
280
281
    return false;
282
}
283
284
/**
285
 * Determine if Strict Mode is enabled
286
 *
287
 * @param bool $include_debug Whether to include WP_DEBUG in strictness level
288
 *
289
 * @return bool Whether Strict Mode is enabled
290
 *
291
 * @since 2.3.5
292
 */
293
function pods_strict( $include_debug = true ) {
294
295
	if ( defined( 'PODS_STRICT' ) && PODS_STRICT ) {
296
		return true;
297
	}
298
	// @deprecated PODS_STRICT_MODE since 2.3.5
299
	elseif ( pods_allow_deprecated( false ) && defined( 'PODS_STRICT_MODE' ) && PODS_STRICT_MODE ) {
300
		return true;
301
	}
302
	elseif ( $include_debug && defined( 'WP_DEBUG' ) && WP_DEBUG ) {
303
		return true;
304
	}
305
306
	return false;
307
308
}
309
310
/**
311
 * Determine if Deprecated Mode is enabled
312
 *
313
 * @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...
314
 *
315
 * @return bool Whether Deprecated Mode is enabled
316
 *
317
 * @since 2.3.10
318
 */
319
function pods_allow_deprecated( $strict = true ) {
320
321
	if ( $strict && pods_strict() ) {
322
		return false;
323
	}
324
	elseif ( !defined( 'PODS_DEPRECATED' ) || PODS_DEPRECATED ) {
325
		return true;
326
	}
327
328
	return false;
329
330
}
331
332
/**
333
 * Determine if Pods API Caching is enabled
334
 *
335
 * @return bool Whether Pods API Caching is enabled
336
 *
337
 * @since 2.3.9
338
 */
339
function pods_api_cache () {
340
    if ( defined( 'PODS_API_CACHE' ) && !PODS_API_CACHE )
341
        return false;
342
343
    return true;
344
}
345
346
/**
347
 * Marks a function as deprecated and informs when it has been used.
348
 *
349
 * There is a hook deprecated_function_run that will be called that can be used
350
 * to get the backtrace up to what file and function called the deprecated
351
 * function.
352
 *
353
 * The current behavior is to trigger a user error if WP_DEBUG is true.
354
 *
355
 * This function is to be used in every function that is deprecated.
356
 *
357
 * @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead,
358
 *   and the version the function was deprecated in.
359
 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do
360
 *   trigger or false to not trigger error.
361
 *
362
 * @param string $function The function that was called
363
 * @param string $version The version of WordPress that deprecated the function
364
 * @param string $replacement Optional. The function that should have been called
365
 *
366
 * @since 2.0
367
 */
368
function pods_deprecated ( $function, $version, $replacement = null ) {
369
    if ( !version_compare( $version, PODS_VERSION, '<=' ) && !version_compare( $version . '-a-0', PODS_VERSION, '<=' ) )
370
        return;
371
372
    do_action( 'deprecated_function_run', $function, $replacement, $version );
373
374
    // Allow plugin to filter the output error trigger
375
    if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
376
        if ( !is_null( $replacement ) )
377
            $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s! Use %3$s instead.', 'pods' );
378
        else
379
            $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s with no alternative available.', 'pods' );
380
381
        trigger_error( sprintf( $error, $function, $version, $replacement ) );
382
    }
383
}
384
385
/**
386
 * Inline help
387
 *
388
 * @param string $text Help text
389
 * @param string $url Documentation URL
390
 *
391
 * @return void
392
 *
393
 * @since 2.0
394
 */
395
function pods_help ( $text, $url = null ) {
396
397 View Code Duplication
	if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) {
398
		wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' );
399
	}
400
	elseif ( ! wp_script_is( 'jquery-qtip2', 'queue' ) && ! wp_script_is( 'jquery-qtip2', 'to_do' ) && ! wp_script_is( 'jquery-qtip2', 'done' ) ) {
401
		wp_enqueue_script( 'jquery-qtip2' );
402
	}
403
404 View Code Duplication
	if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) {
405
		wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' );
406
	}
407
	elseif ( ! wp_style_is( 'jquery-qtip2', 'queue' ) && ! wp_style_is( 'jquery-qtip2', 'to_do' ) && ! wp_style_is( 'jquery-qtip2', 'done' ) ) {
408
		wp_enqueue_style( 'jquery-qtip2' );
409
	}
410
411 View Code Duplication
	if ( ! wp_script_is( 'pods-qtip-init', 'registered' ) ) {
412
		wp_register_script( 'pods-qtip-init', PODS_URL . 'ui/js/qtip.js', array(
413
			'jquery',
414
			'jquery-qtip2'
415
		), PODS_VERSION );
416
	}
417
	elseif ( ! wp_script_is( 'pods-qtip-init', 'queue' ) && ! wp_script_is( 'pods-qtip-init', 'to_do' ) && ! wp_script_is( 'pods-qtip-init', 'done' ) ) {
418
		wp_enqueue_script( 'pods-qtip-init' );
419
	}
420
421 View Code Duplication
	if ( is_array( $text ) ) {
422
		if ( isset( $text[ 1 ] ) ) {
423
			$url = $text[ 1 ];
424
		}
425
426
		$text = $text[ 0 ];
427
	}
428
429
	if ( 'help' == $text ) {
430
		return;
431
	}
432
433
	if ( 0 < strlen( $url ) ) {
434
		$text .= '<br /><br /><a href="' . $url . '" target="_blank">' . __( 'Find out more', 'pods' ) . ' &raquo;</a>';
435
	}
436
437
    echo '<img src="' . esc_url( PODS_URL ) . 'ui/images/help.png" alt="' . esc_attr( $text ) . '" class="pods-icon pods-qtip" />';
438
}
439
440
/**
441
 * Check whether or not something is a specific version minimum and/or maximum
442
 *
443
 * @param string $minimum_version Minimum version
444
 * @param string $comparison Comparison operator
445
 * @param string $maximum_version Maximum version
446
 *
447
 * @return bool
448
 */
449
function pods_version_check ( $what, $minimum_version, $comparison = '<=', $maximum_version = null ) {
450
    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...
451
452
    if ( 'php' == $what )
453
        $version = phpversion();
454
    elseif ( 'mysql' === $what )
455
        $version = $wpdb->db_version();
456
    else
457
        $version = $wp_version;
458
459
    if ( !empty( $minimum_version ) && !version_compare( $minimum_version, $version, $comparison ) )
460
        return false;
461
462
    if ( !empty( $maximum_version ) && !version_compare( $version, $maximum_version, $comparison ) )
463
        return false;
464
465
    return true;
466
}
467
468
/**
469
 * Run a Pods Helper
470
 *
471
 * @param string $helper_name Helper Name
472
 * @param string $value Value to run Helper on
473
 * @param string $name Field name.
474
 *
475
 * @return bool
476
 * @since 1.7.5
477
 */
478
function pods_helper ( $helper_name, $value = null, $name = null ) {
479
    return pods()->helper( $helper_name, $value, $name );
480
}
481
482
/**
483
 * Get the full URL of the current page
484
 *
485
 * @return string Full URL of the current page
486
 * @since 2.3
487
 */
488
function pods_current_url () {
489
    $url = 'http';
490
491
    if ( isset( $_SERVER[ 'HTTPS' ] ) && 'off' != $_SERVER[ 'HTTPS' ] && 0 != $_SERVER[ 'HTTPS' ] )
492
        $url = 'https';
493
494
    $url .= '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
495
496
    return apply_filters( 'pods_current_url', $url );
497
}
498
499
/**
500
 * Find out if the current page has a valid $pods
501
 *
502
 * @param object $object The Pod Object currently checking (optional)
503
 *
504
 * @return bool
505
 * @since 2.0
506
 */
507
function is_pod ( $object = null ) {
508
    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...
509
510
    if ( is_object( $object ) && isset( $object->pod ) && !empty( $object->pod ) )
511
        return true;
512
    elseif ( is_object( $pods ) && isset( $pods->pod ) && !empty( $pods->pod ) )
513
        return true;
514
    elseif ( is_object( $post ) && isset( $post->post_type ) && pods_api()->pod_exists( $post->post_type, 'post_type' ) )
515
        return true;
516
517
    return false;
518
}
519
520
/**
521
 * See if the current user has a certain privilege
522
 *
523
 * @param mixed $privs The privilege name or names (array if multiple)
524
 * @param string $method The access method ("AND", "OR")
525
 *
526
 * @return bool
527
 * @since 1.2.0
528
 */
529
function pods_access ( $privs, $method = 'OR' ) {
530
    // Convert $privs to an array
531
    $privs = (array) $privs;
532
533
    // Convert $method to uppercase
534
    $method = strtoupper( $method );
535
536
    $check = apply_filters( 'pods_access', null, $privs, $method );
537
    if ( null !== $check && is_bool( $check ) )
538
        return $check;
539
540
    if ( !is_user_logged_in() )
541
        return false;
542
543
    if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
544
        return true;
545
546
    // Store approved privs when using "AND"
547
    $approved_privs = array();
548
549
    // Loop through the user's roles
550
    foreach ( $privs as $priv ) {
551
        if ( 0 === strpos( $priv, 'pod_' ) )
552
            $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 );
553
554
        if ( 0 === strpos( $priv, 'manage_' ) )
555
            $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 );
556
557
        if ( current_user_can( $priv ) ) {
558
            if ( 'OR' == $method )
559
                return true;
560
561
            $approved_privs[ $priv ] = true;
562
        }
563
    }
564
    if ( 'AND' == strtoupper( $method ) ) {
565
        foreach ( $privs as $priv ) {
566
            if ( 0 === strpos( $priv, 'pod_' ) )
567
                $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 );
568
569
            if ( 0 === strpos( $priv, 'manage_' ) )
570
                $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 );
571
572
            if ( !isset( $approved_privs[ $priv ] ) )
573
                return false;
574
        }
575
576
        return true;
577
    }
578
579
    return false;
580
}
581
582
/**
583
 * Shortcode support for use anywhere that support WP Shortcodes
584
 *
585
 * @param array $tags An associative array of shortcode properties
586
 * @param string $content A string that represents a template override
587
 *
588
 * @return string
589
 * @since 1.6.7
590
 */
591
function pods_shortcode ( $tags, $content = null ) {
592
593
	if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
594
		return '';
595
	}
596
597
	// For enforcing pagination parameters when not displaying pagination
598
	$page = 1;
599
	$offset = 0;
600
601
	if ( isset( $tags['page'] ) ) {
602
		$page = (int) $tags['page'];
603
		$page = max( $page, 1 );
604
	}
605
606
	if ( isset( $tags['offset'] ) ) {
607
		$offset = (int) $tags['offset'];
608
		$offset = max( $offset, 0 );
609
	}
610
611
    $defaults = array(
612
    	'use_current' => false,
613
        'name' => null,
614
        'id' => null,
615
        'slug' => null,
616
        'select' => null,
617
        'join' => null,
618
        'order' => null,
619
        'orderby' => null,
620
        'limit' => null,
621
        'where' => null,
622
        'having' => null,
623
        'groupby' => null,
624
        'search' => true,
625
        'pagination' => false,
626
        'page' => null,
627
        'offset' => null,
628
        'filters' => false,
629
        'filters_label' => null,
630
        'filters_location' => 'before',
631
        'pagination_label' => null,
632
        'pagination_location' => 'after',
633
        'field' => null,
634
        'col' => null,
635
        'template' => null,
636
        'pods_page' => null,
637
        'helper' => null,
638
        'form' => null,
639
        'fields' => null,
640
        'label' => null,
641
        'thank_you' => null,
642
        'view' => null,
643
        'cache_mode' => 'none',
644
        'expires' => 0,
645
		'shortcodes' => false
646
    );
647
648
    if ( !empty( $tags ) )
649
        $tags = array_merge( $defaults, $tags );
650
    else
651
        $tags = $defaults;
652
653
    $tags = apply_filters( 'pods_shortcode', $tags );
654
655
	$tags[ 'pagination' ] = filter_var($tags[ 'pagination' ], FILTER_VALIDATE_BOOLEAN);
656
	$tags[ 'search' ] = filter_var($tags[ 'pagination' ], FILTER_VALIDATE_BOOLEAN);
657
	$tags[ 'use_current' ] = filter_var($tags[ 'use_current' ], FILTER_VALIDATE_BOOLEAN);
658
659
    if ( empty( $content ) )
660
        $content = null;
661
662
	// Allow views only if not targeting a file path (must be within theme)
663
    if ( 0 < strlen( $tags[ 'view' ] ) ) {
664
		$return = '';
665
666
		if ( !file_exists( $tags[ 'view' ] ) ) {
667
			$return = pods_view( $tags[ 'view' ], null, (int) $tags[ 'expires' ], $tags[ 'cache_mode' ] );
668
669 View Code Duplication
			if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
670
				$return = do_shortcode( $return );
671
			}
672
		}
673
674
		return $return;
675
	}
676
677
    if ( ! $tags['use_current'] && empty( $tags[ 'name' ] ) ) {
678
        if ( in_the_loop() || is_singular() ) {
679
            $pod = pods( get_post_type(), get_the_ID(), false );
680
681
            if ( !empty( $pod ) ) {
682
                $tags[ 'name' ] = get_post_type();
683
                $id = $tags[ 'id' ] = get_the_ID();
684
            }
685
        }
686
687
        if ( empty( $tags[ 'name' ] ) )
688
            return '<p>Please provide a Pod name</p>';
689
    }
690
691
    if ( !empty( $tags[ 'col' ] ) ) {
692
        $tags[ 'field' ] = $tags[ 'col' ];
693
694
        unset( $tags[ 'col' ] );
695
    }
696
697
    if ( !empty( $tags[ 'order' ] ) ) {
698
        $tags[ 'orderby' ] = $tags[ 'order' ];
699
700
        unset( $tags[ 'order' ] );
701
    }
702
703
    if ( empty( $content ) && empty( $tags[ 'pods_page' ] ) && empty( $tags[ 'template' ] ) && empty( $tags[ 'field' ] ) && empty( $tags[ 'form' ] ) ) {
704
        return '<p>Please provide either a template or field name</p>';
705
    }
706
707
    if ( ! $tags['use_current'] && !isset( $id ) ) {
708
        // id > slug (if both exist)
709
		$id = null;
710
711
		if ( !empty( $tags[ 'slug' ] ) ) {
712
			$id = $tags[ 'slug' ];
713
714
			if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
715
				$id = pods_evaluate_tags( $id );
716
			}
717
		}
718
719
        if ( !empty( $tags[ 'id' ] ) ) {
720
            $id = $tags[ 'id' ];
721
722
            if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
723
                $id = pods_evaluate_tags( $id );
724
            }
725
726
            if ( is_numeric( $id ) )
727
                $id = absint( $id );
728
        }
729
    }
730
731
    if ( !isset( $pod ) ) {
732
    	if ( ! $tags['use_current'] ) {
733
        	$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...
734
    	} else {
735
    		$pod = pods();
736
    		$id = $pod->id();
737
    	}
738
    }
739
740
    if ( empty( $pod ) || ! $pod->valid() )
741
        return '<p>Pod not found</p>';
742
743
	$found = 0;
744
745
	$is_singular = ( ! empty( $id ) || $tags['use_current'] );
746
747
	if ( ! $is_singular ) {
748
		$params = array();
749
750
		if ( !defined( 'PODS_DISABLE_SHORTCODE_SQL' ) || !PODS_DISABLE_SHORTCODE_SQL ) {
751
			if ( 0 < strlen( $tags[ 'orderby' ] ) ) {
752
				$params[ 'orderby' ] = $tags[ 'orderby' ];
753
			}
754
755 View Code Duplication
			if ( 0 < strlen( $tags[ 'where' ] ) ) {
756
				$params[ 'where' ] = $tags[ 'where' ];
757
758
				if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
759
					$params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ] );
760
				}
761
			}
762
763 View Code Duplication
			if ( 0 < strlen( $tags[ 'having' ] ) ) {
764
				$params[ 'having' ] = $tags[ 'having' ];
765
766
				if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
767
					$params[ 'having' ] = pods_evaluate_tags( $id );
768
				}
769
			}
770
771
			if ( 0 < strlen( $tags[ 'groupby' ] ) ) {
772
				$params[ 'groupby' ] = $tags[ 'groupby' ];
773
			}
774
775
			if ( 0 < strlen( $tags[ 'select' ] ) ) {
776
				$params[ 'select' ] = $tags[ 'select' ];
777
			}
778
			if ( 0 < strlen( $tags[ 'join' ] ) ) {
779
				$params[ 'join' ] = $tags[ 'join' ];
780
			}
781
		}
782
783
		// Forms require params set
784
		if ( ! empty( $params ) || empty( $tags[ 'form' ] ) ) {
785
			if ( !empty( $tags[ 'limit' ] ) ) {
786
				$params[ 'limit' ] = (int) $tags[ 'limit' ];
787
			}
788
789
			$params[ 'search' ] = $tags[ 'search' ];
790
791
			$params[ 'pagination' ] = $tags[ 'pagination' ];
792
793
			// If we aren't displaying pagination, we need to enforce page/offset
794
			if ( ! $params['pagination'] ) {
795
				$params['page']   = $page;
796
				$params['offset'] = $offset;
797
798
				// Force pagination on, we need it and we're enforcing page/offset
799
				$params['pagination'] = true;
800
			} else {
801
				// If we are displaying pagination, allow page/offset override only if *set*
802
803 View Code Duplication
				if ( isset( $tags['page'] ) ) {
804
					$params['page'] = (int) $tags['page'];
805
					$params['page'] = max( $params['page'], 1 );
806
				}
807
808 View Code Duplication
				if ( isset( $tags['offset'] ) ) {
809
					$params['offset'] = (int) $tags['offset'];
810
					$params['offset'] = max( $params['offset'], 0 );
811
				}
812
			}
813
814
			if ( !empty( $tags[ 'cache_mode' ] ) && 'none' != $tags[ 'cache_mode' ] ) {
815
				$params[ 'cache_mode' ] = $tags[ 'cache_mode' ];
816
				$params[ 'expires' ] = (int) $tags[ 'expires' ];
817
			}
818
819
			$params = apply_filters( 'pods_shortcode_findrecords_params', $params, $pod, $tags );
820
821
			$pod->find( $params );
822
823
			$found = $pod->total();
824
		}
825
	}
826
827
    if ( !empty( $tags[ 'form' ] ) ) {
828
		if ( 'user' == $pod->pod ) {
829
			// Further hardening of User-based forms
830
			if ( false !== strpos( $tags[ 'fields' ], '_capabilities' ) || false !== strpos( $tags[ 'fields' ], '_user_level' ) ) {
831
				return '';
832
			}
833
			// Only explicitly allow user edit forms
834
			elseif ( $is_singular && ( !defined( 'PODS_SHORTCODE_ALLOW_USER_EDIT' ) || !PODS_SHORTCODE_ALLOW_USER_EDIT ) ) {
835
				return '';
836
			}
837
		}
838
839
        return $pod->form( $tags[ 'fields' ], $tags[ 'label' ], $tags[ 'thank_you' ] );
840
	}
841
    elseif ( !empty( $tags[ 'field' ] ) ) {
842
        if ( empty( $tags[ 'helper' ] ) )
843
            $return = $pod->display( $tags[ 'field' ] );
844
        else
845
            $return = $pod->helper( $tags[ 'helper' ], $pod->field( $tags[ 'field' ] ), $tags[ 'field' ] );
846
847 View Code Duplication
		if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
848
			$return = do_shortcode( $return );
849
		}
850
851
		return $return;
852
    }
853
    elseif ( !empty( $tags[ 'pods_page' ] ) && class_exists( 'Pods_Pages' ) ) {
854
        $pods_page = Pods_Pages::exists( $tags[ 'pods_page' ] );
855
856
        if ( empty( $pods_page ) )
857
            return '<p>Pods Page not found</p>';
858
859
        $return = Pods_Pages::content( true, $pods_page );
860
861 View Code Duplication
		if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
862
			$return = do_shortcode( $return );
863
		}
864
865
		return $return;
866
    }
867
868
    ob_start();
869
870 View Code Duplication
    if ( ! $is_singular && false !== $tags[ 'filters' ] && 'before' == $tags[ 'filters_location' ] )
871
        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...
872
873 View Code Duplication
    if ( ! $is_singular && 0 < $found && true === $tags[ 'pagination' ] && in_array( $tags[ 'pagination_location' ], array( 'before', 'both' ) ) )
874
        echo $pod->pagination( $tags[ 'pagination_label' ] );
875
876
    echo $pod->template( $tags[ 'template' ], $content );
877
878 View Code Duplication
    if ( ! $is_singular && 0 < $found && true === $tags[ 'pagination' ] && in_array( $tags[ 'pagination_location' ], array( 'after', 'both' ) ) )
879
        echo $pod->pagination( $tags[ 'pagination_label' ] );
880
881 View Code Duplication
    if ( ! $is_singular && false !== $tags[ 'filters' ] && 'after' == $tags[ 'filters_location' ] )
882
        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...
883
884
	$return = ob_get_clean();
885
886 View Code Duplication
	if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) {
887
		$return = do_shortcode( $return );
888
	}
889
890
	return $return;
891
}
892
893
/**
894
 * Form Shortcode support for use anywhere that support WP Shortcodes
895
 *
896
 * @param array $tags An associative array of shortcode properties
897
 * @param string $content Not currently used
898
 *
899
 * @return string
900
 * @since 2.3
901
 */
902
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...
903
    $tags[ 'form' ] = 1;
904
905
    return pods_shortcode( $tags );
906
}
907
908
/**
909
 * Fork of WordPress do_shortcode that allows specifying which shortcodes are ran.
910
 *
911
 * Search content for shortcodes and filter shortcodes through their hooks.
912
 *
913
 * If there are no shortcode tags defined, then the content will be returned
914
 * without any filtering. This might cause issues when plugins are disabled but
915
 * the shortcode will still show up in the post or content.
916
 *
917
 * @since 2.4.3
918
 *
919
 * @uses $shortcode_tags
920
 * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.
921
 *
922
 * @param string $content Content to search for shortcodes
923
 * @param array $shortcodes Array of shortcodes to run
924
 * @return string Content with shortcodes filtered out.
925
 */
926
function pods_do_shortcode( $content, $shortcodes ) {
927
928
	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...
929
930
	// No shortcodes in content
931
	if ( false === strpos( $content, '[' ) ) {
932
		return $content;
933
	}
934
935
	// No shortcodes registered
936
	if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
937
		return $content;
938
	}
939
940
	// Store all shortcodes, to restore later
941
	$temp_shortcode_tags = $shortcode_tags;
942
943
	// Loop through all shortcodes and remove those not being used right now
944
	foreach ( $shortcode_tags as $tag => $callback ) {
945
		if ( ! in_array( $tag, $shortcodes ) ) {
946
			unset( $shortcode_tags[ $tag ] );
947
		}
948
	}
949
950
	// Build Shortcode regex pattern just for the shortcodes we want
951
	$pattern = get_shortcode_regex();
952
953
	// Call shortcode callbacks just for the shortcodes we want
954
	$content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
955
956
	// Restore all shortcode tags
957
	$shortcode_tags = $temp_shortcode_tags;
958
959
	return $content;
960
961
}
962
963
/**
964
 * Check if Pods is compatible with WP / PHP / MySQL or not
965
 *
966
 * @return bool
967
 *
968
 * @since 1.10
969
 */
970
function pods_compatibility_check () {
971
    $compatible = true;
972
973
    if ( !pods_version_check( 'wp', PODS_WP_VERSION_MINIMUM ) ) {
974
        $compatible = false;
975
976
        add_action( 'admin_notices', 'pods_version_notice_wp' );
977
    }
978
979
    if ( !pods_version_check( 'php', PODS_PHP_VERSION_MINIMUM ) ) {
980
        $compatible = false;
981
982
        add_action( 'admin_notices', 'pods_version_notice_php' );
983
    }
984
985
    if ( !pods_version_check( 'mysql', PODS_MYSQL_VERSION_MINIMUM ) ) {
986
        $compatible = false;
987
988
        add_action( 'admin_notices', 'pods_version_notice_mysql' );
989
    }
990
991
    return $compatible;
992
}
993
994
/**
995
 * Show WP notice if WP version is incompatible
996
 *
997
 * @return void
998
 *
999
 * @since 1.10
1000
 */
1001 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...
1002
    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...
1003
?>
1004
    <div class="error fade">
1005
        <p>
1006
            <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1007
            <strong>WordPress <?php echo esc_html( PODS_WP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1008
            <strong>WordPress <?php echo esc_html( $wp_version ); ?></strong> - <?php _e( 'Please upgrade your WordPress to continue.', 'pods' ); ?>
1009
        </p>
1010
    </div>
1011
<?php
1012
}
1013
1014
/**
1015
 * Show WP notice if PHP version is incompatible
1016
 *
1017
 * @return void
1018
 *
1019
 * @since 1.10
1020
 */
1021 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...
1022
?>
1023
    <div class="error fade">
1024
        <p>
1025
            <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1026
            <strong>PHP <?php echo esc_html( PODS_PHP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1027
            <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' ); ?>
1028
        </p>
1029
    </div>
1030
<?php
1031
}
1032
1033
/**
1034
 * Show WP notice if MySQL version is incompatible
1035
 *
1036
 * @return void
1037
 *
1038
 * @since 1.10
1039
 */
1040 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...
1041
    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...
1042
    $mysql = $wpdb->db_version();
1043
?>
1044
    <div class="error fade">
1045
        <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
1046
            <strong>MySQL <?php echo esc_html( PODS_MYSQL_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
1047
            <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' ); ?>
1048
        </p>
1049
    </div>
1050
<?php
1051
}
1052
1053
/**
1054
 * Check if a Function exists or File exists in Theme / Child Theme
1055
 *
1056
 * @param string $function_or_file Function or file name to look for.
1057
 * @param string $function_name (optional) Function name to look for.
1058
 * @param string $file_dir (optional) Drectory to look into
1059
 * @param string $file_name (optional) Filename to look for
1060
 *
1061
 * @return mixed
1062
 *
1063
 * @since 1.12
1064
 */
1065
function pods_function_or_file ( $function_or_file, $function_name = null, $file_dir = null, $file_name = null ) {
1066
    $found = false;
1067
    $function_or_file = (string) $function_or_file;
1068
    if ( false !== $function_name ) {
1069
        if ( null === $function_name )
1070
            $function_name = $function_or_file;
1071
        $function_name = str_replace( array(
1072
            '__',
1073
            '__',
1074
            '__'
1075
        ), '_', preg_replace( '/[^a-z^A-Z^_][^a-z^A-Z^0-9^_]*/', '_', (string) $function_name ) );
1076
        if ( function_exists( 'pods_custom_' . $function_name ) )
1077
            $found = array( 'function' => 'pods_custom_' . $function_name );
1078
        elseif ( function_exists( $function_name ) )
1079
            $found = array( 'function' => $function_name );
1080
    }
1081
    if ( false !== $file_name && false === $found ) {
1082
        if ( null === $file_name )
1083
            $file_name = $function_or_file;
1084
        $file_name = str_replace( array(
1085
            '__',
1086
            '__',
1087
            '__'
1088
        ), '_', preg_replace( '/[^a-z^A-Z^0-9^_]*/', '_', (string) $file_name ) ) . '.php';
1089
        $custom_location = apply_filters( 'pods_file_directory', null, $function_or_file, $function_name, $file_dir, $file_name );
1090
        if ( defined( 'PODS_FILE_DIRECTORY' ) && false !== PODS_FILE_DIRECTORY )
1091
            $custom_location = PODS_FILE_DIRECTORY;
1092
        if ( !empty( $custom_location ) && locate_template( trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
1093
            $found = array( 'file' => trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
1094 View Code Duplication
        elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
1095
            $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
1096 View Code Duplication
        elseif ( locate_template( 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
1097
            $found = array( 'file' => 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
1098 View Code Duplication
        elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
1099
            $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
1100
    }
1101
1102
    return apply_filters( 'pods_function_or_file', $found, $function_or_file, $function_name, $file_name );
1103
}
1104
1105
/**
1106
 * Redirects to another page.
1107
 *
1108
 * @param string $location The path to redirect to
1109
 * @param int $status Status code to use
1110
 *
1111
 * @return void
1112
 *
1113
 * @since 2.0
1114
 */
1115
function pods_redirect ( $location, $status = 302 ) {
1116
    if ( !headers_sent() ) {
1117
        wp_redirect( $location, $status );
1118
        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...
1119
    }
1120
    else {
1121
        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...
1122
            . 'document.location = "' . str_replace( '&amp;', '&', esc_js( $location ) ) . '";'
1123
            . '</script>' );
1124
    }
1125
}
1126
1127
/**
1128
 * Check if a user has permission to be doing something based on standard permission options
1129
 *
1130
 * @param array $options
1131
 *
1132
 * @return bool Whether the user has permissions
1133
 *
1134
 * @since 2.0.5
1135
 */
1136
function pods_permission ( $options ) {
1137
    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...
1138
1139
    wp_get_current_user();
1140
1141
    $permission = false;
1142
1143
    if ( isset( $options[ 'options' ] ) )
1144
        $options = $options[ 'options' ];
1145
1146
    if ( pods_is_admin() )
1147
        $permission = true;
1148
    elseif ( 0 == pods_v( 'restrict_role', $options, 0 ) && 0 == pods_v( 'restrict_capability', $options, 0 ) && 0 == pods_v( 'admin_only', $options, 0 ) )
1149
        $permission = true;
1150
1151
    if ( !$permission && 1 == pods_v( 'restrict_role', $options, 0 ) ) {
1152
        $roles = pods_v( 'roles_allowed', $options );
1153
1154
        if ( !is_array( $roles ) )
1155
            $roles = explode( ',', $roles );
1156
1157
        $roles = array_unique( array_filter( $roles ) );
1158
1159
        foreach( $roles as $role ) {
1160
            if ( is_user_logged_in() && in_array( $role, $current_user->roles ) ) {
1161
                $permission = true;
1162
1163
                break;
1164
            }
1165
        }
1166
    }
1167
1168
    if ( !$permission && 1 == pods_v( 'restrict_capability', $options, 0 ) ) {
1169
        $capabilities = pods_v( 'capability_allowed', $options );
1170
1171
        if ( !is_array( $capabilities ) )
1172
            $capabilities = explode( ',', $capabilities );
1173
1174
        $capabilities = array_unique( array_filter( $capabilities ) );
1175
1176
        foreach( $capabilities as $capability ) {
1177
            $must_have_capabilities = explode( '&&', $capability );
1178
            $must_have_capabilities = array_unique( array_filter( $must_have_capabilities ) );
1179
1180
            $must_have_permission = true;
1181
1182
            foreach ( $must_have_capabilities as $must_have_capability ) {
1183
                if ( !current_user_can( $must_have_capability ) ) {
1184
                    $must_have_permission = false;
1185
1186
                    break;
1187
                }
1188
            }
1189
1190
            if ( $must_have_permission && is_user_logged_in() ) {
1191
                $permission = true;
1192
1193
                break;
1194
            }
1195
        }
1196
    }
1197
1198
    return $permission;
1199
}
1200
1201
/**
1202
 * Check if permissions are restricted
1203
 *
1204
 * @param array $options
1205
 *
1206
 * @return bool Whether the permissions are restricted
1207
 *
1208
 * @since 2.3.4
1209
 */
1210
function pods_has_permissions ( $options ) {
1211
    $permission = false;
1212
1213
    if ( isset( $options[ 'options' ] ) )
1214
        $options = $options[ 'options' ];
1215
1216
    if ( 1 == pods_v( 'restrict_role', $options, 0 ) || 1 == pods_v( 'restrict_capability', $options, 0 ) || 1 == pods_v( 'admin_only', $options, 0 ) )
1217
        return true;
1218
1219
    return false;
1220
}
1221
1222
/**
1223
 * A fork of get_page_by_title that excludes items unavailable via access rights (by status)
1224
 *
1225
 * @see get_page_by_title
1226
 *
1227
 * @param string $title Title of item to get
1228
 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
1229
 * @param string $type Post Type
1230
 * @param string|array $status Post statuses to include (default is what user has access to)
1231
 *
1232
 * @return WP_Post|null WP_Post on success or null on failure
1233
 *
1234
 * @since 2.3.4
1235
 */
1236
function pods_by_title ( $title, $output = OBJECT, $type = 'page', $status = null ) {
1237
    // @todo support Pod item lookups, not just Post Types
1238
1239
    /**
1240
     * @var $wpdb WPDB
1241
     */
1242
    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...
1243
1244
    if ( empty( $status ) ) {
1245
        $status = array(
1246
            'publish'
1247
        );
1248
1249
        if ( current_user_can( 'read_private_' . $type . 's') )
1250
            $status[] = 'private';
1251
1252
        if ( current_user_can( 'edit_' . $type . 's' ) )
1253
            $status[] = 'draft';
1254
    }
1255
1256
    $status = (array) $status;
1257
1258
    $status_sql = ' AND `post_status` IN ( %s' . str_repeat( ', %s', count( $status ) -1 ) . ' )';
1259
1260
    $orderby_sql = ' ORDER BY ( `post_status` = %s ) DESC' . str_repeat( ', ( `post_status` = %s ) DESC', count( $status ) - 1 ) . ', `ID` DESC';
1261
1262
    $prepared = array_merge( array( $title, $type ), $status, $status ); // once for WHERE, once for ORDER BY
1263
1264
    $page = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` = %s AND `post_type` = %s" . $status_sql . $orderby_sql, $prepared ) );
1265
1266
    if ( $page )
1267
        return get_post( pods_v( $page, 'post_id' ), $output );
1268
1269
    return null;
1270
}
1271
1272
/**
1273
 * Get a field value from a Pod
1274
 *
1275
 * @param string $pod The pod name
1276
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1277
 * @param string|array $name The field name, or an associative array of parameters
1278
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1279
 *
1280
 * @return mixed Field value
1281
 *
1282
 * @since 2.1
1283
 */
1284 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...
1285
    // 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...
1286
    if ( null === $name ) {
1287
        $name = $pod;
1288
        $single = (boolean) $id;
1289
1290
        $pod = get_post_type();
1291
        $id = get_the_ID();
1292
    }
1293
1294
    $pod = pods( $pod, $id );
1295
1296
	if ( is_object( $pod ) ) {
1297
		return $pod->field( $name, $single );
1298
	}
1299
1300
	return null;
1301
}
1302
1303
/**
1304
 * Get a field display value from a Pod
1305
 *
1306
 * @param string $pod The pod name
1307
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1308
 * @param string|array $name The field name, or an associative array of parameters
1309
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1310
 *
1311
 * @return mixed Field value
1312
 *
1313
 * @since 2.1
1314
 */
1315 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...
1316
    // 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...
1317
    if ( null === $name ) {
1318
        $name = $pod;
1319
        $single = (boolean) $id;
1320
1321
        $pod = get_post_type();
1322
        $id = get_the_ID();
1323
    }
1324
1325
    $pod = pods( $pod, $id );
1326
1327
	if ( is_object( $pod ) ) {
1328
		return $pod->display( $name, $single );
1329
	}
1330
1331
	return null;
1332
}
1333
1334
/**
1335
 * Get a field raw value from a Pod
1336
 *
1337
 * @param string $pod The pod name
1338
 * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
1339
 * @param string|array $name The field name, or an associative array of parameters
1340
 * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
1341
 *
1342
 * @return mixed Field value
1343
 *
1344
 * @since 2.1
1345
 */
1346
function pods_field_raw ( $pod, $id = false, $name = null, $single = false ) {
1347
    // 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...
1348
    if ( null === $name ) {
1349
        $name = $pod;
1350
        $single = (boolean) $id;
1351
1352
        $pod = get_post_type();
1353
        $id = get_the_ID();
1354
    }
1355
1356
    return pods( $pod, $id )->raw( $name, $single );
1357
1358
}
1359
1360
/**
1361
 * Set a cached value
1362
 *
1363
 * @see PodsView::set
1364
 *
1365
 * @param string $key Key for the cache
1366
 * @param mixed $value Value to add to the cache
1367
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1368
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1369
 * @param string $group (optional) Key for the group
1370
 *
1371
 * @return bool|mixed|null|string|void
1372
 *
1373
 * @since 2.0
1374
 */
1375
function pods_view_set ( $key, $value, $expires = 0, $cache_mode = 'cache', $group = '' ) {
1376
    require_once( PODS_DIR . 'classes/PodsView.php' );
1377
1378
    return PodsView::set( $key, $value, $expires, $cache_mode, $group );
1379
}
1380
1381
/**
1382
 * Get a cached value
1383
 *
1384
 * @see PodsView::get
1385
 *
1386
 * @param string $key Key for the cache
1387
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1388
 * @param string $group (optional) Key for the group
1389
 * @param string $callback (optional) Callback function to run to set the value if not cached
1390
 *
1391
 * @return bool|mixed|null|void
1392
 *
1393
 * @since 2.0
1394
 */
1395
function pods_view_get ( $key, $cache_mode = 'cache', $group = '', $callback = null ) {
1396
    require_once( PODS_DIR . 'classes/PodsView.php' );
1397
1398
    return PodsView::get( $key, $cache_mode, $group, $callback );
1399
}
1400
1401
/**
1402
 * Clear a cached value
1403
 *
1404
 * @see PodsView::clear
1405
 *
1406
 * @param string|bool $key Key for the cache
1407
 * @param string $cache_mode (optional) Decides the caching method to use for the view.
1408
 * @param string $group (optional) Key for the group
1409
 *
1410
 * @return bool
1411
 *
1412
 * @since 2.0
1413
 */
1414
function pods_view_clear ( $key = true, $cache_mode = 'cache', $group = '' ) {
1415
    require_once( PODS_DIR . 'classes/PodsView.php' );
1416
1417
    return PodsView::clear( $key, $cache_mode, $group );
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 string $group (optional) Key for the group
1428
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1429
 *
1430
 * @return bool|mixed|null|string|void
1431
 *
1432
 * @since 2.0
1433
 */
1434
function pods_cache_set ( $key, $value, $group = '', $expires = 0) {
1435
    return pods_view_set( $key, $value, $expires, 'cache', $group );
1436
}
1437
1438
/**
1439
 * Get a cached value
1440
 *
1441
 * @see PodsView::get
1442
 *
1443
 * @param string $key Key for the cache
1444
 * @param string $group (optional) Key for the group
1445
 * @param string $callback (optional) Callback function to run to set the value if not cached
1446
 *
1447
 * @return bool
1448
 *
1449
 * @since 2.0
1450
 */
1451
function pods_cache_get ( $key, $group = '', $callback = null ) {
1452
    return pods_view_get( $key, 'cache', $group, $callback );
1453
}
1454
1455
/**
1456
 * Clear a cached value
1457
 *
1458
 * @see PodsView::clear
1459
 *
1460
 * @param string|bool $key Key for the cache
1461
 * @param string $group (optional) Key for the group
1462
 *
1463
 * @return bool|mixed|null|void
1464
 *
1465
 * @since 2.0
1466
 */
1467
function pods_cache_clear ( $key = true, $group = '' ) {
1468
    return pods_view_clear( $key, 'cache', $group );
1469
}
1470
1471
/**
1472
 * Set a cached value
1473
 *
1474
 * @see PodsView::set
1475
 *
1476
 * @param string $key Key for the cache
1477
 * @param mixed $value Value to add to the cache
1478
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1479
 *
1480
 * @return bool|mixed|null|string|void
1481
 *
1482
 * @since 2.0
1483
 */
1484
function pods_transient_set ( $key, $value, $expires = 0 ) {
1485
    return pods_view_set( $key, $value, $expires, 'transient' );
1486
}
1487
1488
/**
1489
 * Get a cached value
1490
 *
1491
 * @see PodsView::get
1492
 *
1493
 * @param string $key Key for the cache
1494
 * @param string $callback (optional) Callback function to run to set the value if not cached
1495
 *
1496
 * @return bool|mixed|null|void
1497
 *
1498
 * @since 2.0
1499
 */
1500
function pods_transient_get ( $key, $callback = null ) {
1501
    return pods_view_get( $key, 'transient', '', $callback );
1502
}
1503
1504
/**
1505
 * Clear a cached value
1506
 *
1507
 * @see PodsView::clear
1508
 *
1509
 * @param string|bool $key Key for the cache
1510
 *
1511
 * @return bool
1512
 *
1513
 * @since 2.0
1514
 */
1515
function pods_transient_clear ( $key = true ) {
1516
    return pods_view_clear( $key, 'transient' );
1517
}
1518
1519
/**
1520
 * Set a cached value
1521
 *
1522
 * @see PodsView::set
1523
 *
1524
 * @param string $key Key for the cache
1525
 * @param mixed $value Value to add to the cache
1526
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1527
 *
1528
 * @return bool|mixed|null|string|void
1529
 *
1530
 * @since 2.3.10
1531
 */
1532
function pods_site_transient_set ( $key, $value, $expires = 0 ) {
1533
    return pods_view_set( $key, $value, $expires, 'site-transient' );
1534
}
1535
1536
/**
1537
 * Get a cached value
1538
 *
1539
 * @see PodsView::get
1540
 *
1541
 * @param string $key Key for the cache
1542
 * @param string $callback (optional) Callback function to run to set the value if not cached
1543
 *
1544
 * @return bool|mixed|null|void
1545
 *
1546
 * @since 2.3.10
1547
 */
1548
function pods_site_transient_get ( $key, $callback = null ) {
1549
    return pods_view_get( $key, 'site-transient', '', $callback );
1550
}
1551
1552
/**
1553
 * Clear a cached value
1554
 *
1555
 * @see PodsView::clear
1556
 *
1557
 * @param string|bool $key Key for the cache
1558
 *
1559
 * @return bool
1560
 *
1561
 * @since 2.3.10
1562
 */
1563
function pods_site_transient_clear ( $key = true ) {
1564
    return pods_view_clear( $key, 'site-transient' );
1565
}
1566
1567
/**
1568
 * Set a cached value
1569
 *
1570
 * @see PodsView::set
1571
 *
1572
 * @param string $key Key for the cache
1573
 * @param mixed $value Value to add to the cache
1574
 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
1575
 * @param string $group (optional) Key for the group
1576
 *
1577
 * @return bool|mixed|null|string|void
1578
 *
1579
 * @since 2.3.10
1580
 */
1581
function pods_option_cache_set ( $key, $value, $expires = 0, $group = '' ) {
1582
    return pods_view_set( $key, $value, $expires, 'option-cache', $group );
1583
}
1584
1585
/**
1586
 * Get a cached value
1587
 *
1588
 * @see PodsView::get
1589
 *
1590
 * @param string $key Key for the cache
1591
 * @param string $group (optional) Key for the group
1592
 * @param string $callback (optional) Callback function to run to set the value if not cached
1593
 *
1594
 * @return bool|mixed|null|void
1595
 *
1596
 * @since 2.3.10
1597
 */
1598
function pods_option_cache_get ( $key, $group = '', $callback = null ) {
1599
    return pods_view_get( $key, 'option-cache', $group, $callback );
1600
}
1601
1602
/**
1603
 * Clear a cached value
1604
 *
1605
 * @see PodsView::clear
1606
 *
1607
 * @param string|bool $key Key for the cache
1608
 * @param string $group (optional) Key for the group
1609
 *
1610
 * @return bool
1611
 *
1612
 * @since 2.3.10
1613
 */
1614
function pods_option_cache_clear ( $key = true, $group = '' ) {
1615
    return pods_view_clear( $key, 'option-cache', $group );
1616
}
1617
1618
/**
1619
 * Scope variables and include a template like get_template_part that's child-theme aware
1620
 *
1621
 * @see get_template_part
1622
 *
1623
 * @param string|array $template Template names (see get_template_part)
1624
 * @param array $data Data to scope to the include
1625
 * @param bool $return Whether to return the output (echo by default)
1626
 * @return string|null Template output
1627
 *
1628
 * @since 2.3.9
1629
 */
1630
function pods_template_part ( $template, $data = null, $return = false ) {
1631
    $part = PodsView::get_template_part( $template, $data );
1632
1633
    if ( !$return ) {
1634
        echo $part;
1635
1636
        return null;
1637
    }
1638
1639
    return $part;
1640
}
1641
1642
/**
1643
 * Add a new Pod outside of the DB
1644
 *
1645
 * @see PodsMeta::register
1646
 *
1647
 * @param string $type The pod type ('post_type', 'taxonomy', 'media', 'user', 'comment')
1648
 * @param string $name The pod name
1649
 * @param array $object (optional) Pod array, including any 'fields' arrays
1650
 *
1651
 * @return array|boolean Pod data or false if unsuccessful
1652
 * @since 2.1
1653
 */
1654
function pods_register_type ( $type, $name, $object = null ) {
1655
    if ( empty( $object ) )
1656
        $object = array();
1657
1658
    if ( !empty( $name ) )
1659
        $object[ 'name' ] = $name;
1660
1661
    return pods_meta()->register( $type, $object );
1662
}
1663
1664
/**
1665
 * Add a new Pod field outside of the DB
1666
 *
1667
 * @see PodsMeta::register_field
1668
 *
1669
 * @param string|array $pod The pod name or array of pod names
1670
 * @param string $name The name of the Pod
1671
 * @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...
1672
 *
1673
 * @return array|boolean Field data or false if unsuccessful
1674
 * @since 2.1
1675
 */
1676
function pods_register_field ( $pod, $name, $field = null ) {
1677
    if ( empty( $field ) )
1678
        $field = array();
1679
1680
    if ( !empty( $name ) )
1681
        $field[ 'name' ] = $name;
1682
1683
    return pods_meta()->register_field( $pod, $field );
1684
}
1685
1686
/**
1687
 * Add a new Pod field type
1688
 *
1689
 * @see PodsForm::register_field_type
1690
 *
1691
 * @param string $type The new field type identifier
1692
 * @param string $file The new field type class file location
1693
 *
1694
 * @return array Field type array
1695
 * @since 2.3
1696
 */
1697
function pods_register_field_type ( $type, $file = null ) {
1698
    return PodsForm::register_field_type( $type, $file );
1699
}
1700
1701
/**
1702
 * Register a related object
1703
 *
1704
 * @param string $name Object name
1705
 * @param string $label Object label
1706
 * @param array $options Object options
1707
 *
1708
 * @return array|boolean Object array or false if unsuccessful
1709
 * @since 2.3
1710
 */
1711
function pods_register_related_object ( $name, $label, $options = null ) {
1712
    return PodsForm::field_method( 'pick', 'register_related_object', $name, $label, $options );
1713
}
1714
1715
/**
1716
 * Require a component (always-on)
1717
 *
1718
 * @param string $component Component ID
1719
 *
1720
 * @return void
1721
 *
1722
 * @since 2.3
1723
 */
1724
function pods_require_component ( $component ) {
1725
    add_filter( 'pods_component_require_' . $component, '__return_true' );
1726
}
1727
1728
/**
1729
 * Add a meta group of fields to add/edit forms
1730
 *
1731
 * @see PodsMeta::group_add
1732
 *
1733
 * @param string|array $pod The pod or type of element to attach the group to.
1734
 * @param string $label Title of the edit screen section, visible to user.
1735
 * @param string|array $fields Either a comma separated list of text fields or an associative array containing field information.
1736
 * @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').
1737
 * @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low').
1738
 * @param string $type (optional) Type of the post to attach to.
1739
 *
1740
 * @return void
1741
 *
1742
 * @since 2.0
1743
 * @link http://pods.io/docs/pods-group-add/
1744
 */
1745
function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) {
1746 View Code Duplication
    if ( !is_array( $pod ) && null !== $type ) {
1747
        $pod = array(
1748
            'name' => $pod,
1749
            'type' => $type
1750
        );
1751
    }
1752
1753
    pods_meta()->group_add( $pod, $label, $fields, $context, $priority );
1754
}
1755
1756
/**
1757
 * Check if a plugin is active on non-admin pages (is_plugin_active() only available in admin)
1758
 *
1759
 * @param string $plugin Plugin name.
1760
 *
1761
 * @return bool
1762
 *
1763
 * @since 2.0
1764
 */
1765
function pods_is_plugin_active ( $plugin ) {
1766
    $active = false;
1767
1768
    if ( function_exists( 'is_plugin_active' ) )
1769
        $active = is_plugin_active( $plugin );
1770
1771
    if ( !$active ) {
1772
        $active_plugins = (array) get_option( 'active_plugins', array() );
1773
1774
        if ( in_array( $plugin, $active_plugins ) )
1775
            $active = true;
1776
1777
        if ( !$active && is_multisite() ) {
1778
            $plugins = get_site_option( 'active_sitewide_plugins' );
1779
1780
            if ( isset( $plugins[ $plugin ] ) )
1781
                $active = true;
1782
        }
1783
    }
1784
1785
    return $active;
1786
}
1787
1788
/**
1789
 * Check if Pods no conflict is on or not
1790
 *
1791
 * @param string $object_type
1792
 *
1793
 * @return bool
1794
 *
1795
 * @since 2.3
1796
 */
1797
function pods_no_conflict_check ( $object_type = 'post' ) {
1798
    if ( 'post_type' == $object_type )
1799
        $object_type = 'post';
1800
    elseif ( 'term' == $object_type )
1801
        $object_type = 'taxonomy';
1802
1803 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...
1804
        return true;
1805
1806
    return false;
1807
}
1808
1809
/**
1810
 * Turn off conflicting / recursive actions for an object type that Pods hooks into
1811
 *
1812
 * @param string $object_type
1813
 * @param string $object
1814
 *
1815
 * @return bool
1816
 *
1817
 * @since 2.0
1818
 */
1819
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...
1820
1821
    if ( 'post_type' == $object_type )
1822
        $object_type = 'post';
1823
    elseif ( 'term' == $object_type )
1824
        $object_type = 'taxonomy';
1825
1826 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...
1827
        return true;
1828
1829
    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...
1830
        return false;
1831
1832
    $no_conflict = array(
1833
		'filter' => array()
1834
	);
1835
1836
    // Filters = Usually get/update/delete meta functions
1837
    // Actions = Usually insert/update/save/delete object functions
1838
    if ( 'post' == $object_type ) {
1839 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1840
            // Handle *_post_meta
1841
			if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1842
				$no_conflict[ 'filter' ] = array(
1843
					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...
1844
				);
1845
			}
1846
1847
			if ( !pods_tableless() ) {
1848
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1849
					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...
1850
					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...
1851
					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...
1852
				) );
1853
			}
1854
		}
1855
1856
        $no_conflict[ 'action' ] = array(
1857
            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...
1858
            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...
1859
        );
1860
    }
1861
    elseif ( 'taxonomy' == $object_type ) {
1862
		if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
1863
            // Handle *_term_meta
1864 View Code Duplication
			if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) {
1865
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1866
					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...
1867
				) );
1868
			}
1869
1870
			if ( !pods_tableless() ) {
1871
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1872
					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...
1873
					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...
1874
					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...
1875
				) );
1876
			}
1877
1878
			$no_conflict[ 'action' ] = array(
1879
				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...
1880
				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...
1881
			);
1882
		}
1883
    }
1884
    elseif ( 'media' == $object_type ) {
1885
		$no_conflict[ 'filter' ] = array(
1886
			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...
1887
		);
1888
1889
		if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1890
            // Handle *_post_meta
1891 View Code Duplication
			if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1892
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1893
					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...
1894
				) );
1895
			}
1896
1897
			if ( !pods_tableless() ) {
1898
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1899
					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...
1900
					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...
1901
					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...
1902
				) );
1903
			}
1904
1905
			$no_conflict[ 'action' ] = array();
1906
		}
1907
    }
1908
    elseif ( 'user' == $object_type ) {
1909 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
1910
            // Handle *_term_meta
1911
			if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) {
1912
				$no_conflict[ 'filter' ] = array(
1913
					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...
1914
				);
1915
			}
1916
1917
			if ( !pods_tableless() ) {
1918
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1919
					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...
1920
					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...
1921
					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...
1922
				) );
1923
			}
1924
		}
1925
1926
        $no_conflict[ 'action' ] = array(
1927
            //array( 'user_register', array( PodsInit::$meta, 'save_user' ) ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
1928
            array( 'profile_update', 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...
1929
        );
1930
    }
1931
    elseif ( 'comment' == $object_type ) {
1932 View Code Duplication
		if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
1933
            // Handle *_term_meta
1934
			if ( apply_filters( 'pods_meta_handler_get', true, 'comment' ) ) {
1935
				$no_conflict[ 'filter' ] = array(
1936
					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...
1937
				);
1938
			}
1939
1940
			if ( !pods_tableless() ) {
1941
				$no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1942
					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...
1943
					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...
1944
					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...
1945
				) );
1946
			}
1947
		}
1948
1949
        $no_conflict[ 'action' ] = array(
1950
            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...
1951
            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...
1952
            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...
1953
        );
1954
    }
1955
    elseif ( 'settings' == $object_type ) {
1956
        $no_conflict[ 'filter' ] = array();
1957
1958
        // @todo Better handle settings conflicts apart from each other
1959
        /*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...
1960
            foreach ( PodsMeta::$settings as $setting_pod ) {
1961
                foreach ( $setting_pod[ 'fields' ] as $option ) {
1962
                    $no_conflict[ 'filter' ][] = array( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
1963
                    $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
1964
                }
1965
            }
1966
        }
1967
        elseif ( isset( PodsMeta::$settings[ $object ] ) ) {
1968
            foreach ( PodsMeta::$settings[ $object ][ 'fields' ] as $option ) {
1969
                $no_conflict[ 'filter' ][] = array( 'pre_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
1970
                $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
1971
            }
1972
        }*/
1973
    }
1974
1975
    $conflicted = false;
1976
1977
    foreach ( $no_conflict as $action_filter => $conflicts ) {
1978
        foreach ( $conflicts as $k => $args ) {
1979
            if ( call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
1980
                call_user_func_array( 'remove_' . $action_filter, array_slice( $args, 0, 3 ) );
1981
1982
                $conflicted = true;
1983
            }
1984
            else
1985
                unset( $no_conflict[ $action_filter ][ $k ] );
1986
        }
1987
    }
1988
1989
    if ( $conflicted ) {
1990
        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...
1991
1992
        return true;
1993
    }
1994
1995
    return false;
1996
}
1997
1998
/**
1999
 * Turn on actions after running code during pods_conflict
2000
 *
2001
 * @param string $object_type
2002
 *
2003
 * @return bool
2004
 *
2005
 * @since 2.0
2006
 */
2007
function pods_no_conflict_off ( $object_type = 'post' ) {
2008
    if ( 'post_type' == $object_type )
2009
        $object_type = 'post';
2010
    elseif ( 'term' == $object_type )
2011
        $object_type = 'taxonomy';
2012
2013 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...
2014
        return false;
2015
2016
    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...
2017
        return false;
2018
2019
    $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...
2020
2021
    $conflicted = false;
2022
2023
    foreach ( $no_conflict as $action_filter => $conflicts ) {
2024
        foreach ( $conflicts as $args ) {
2025
            if ( !call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2026
                call_user_func_array( 'add_' . $action_filter, $args );
2027
2028
                $conflicted = true;
2029
            }
2030
        }
2031
    }
2032
2033
    if ( $conflicted ) {
2034
        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...
2035
2036
        return true;
2037
    }
2038
2039
    return false;
2040
}
2041
2042
/**
2043
 * Safely start a new session (without whitescreening on certain hosts,
2044
 * which have no session path or isn't writable)
2045
 *
2046
 * @since 2.3.10
2047
 */
2048
function pods_session_start() {
2049
2050
	$save_path = session_save_path();
2051
2052
	// Check if headers were sent
2053
	if ( false !== headers_sent() ) {
2054
		return false;
2055
	}
2056
	// Allow for bypassing Pods session autostarting
2057
	elseif ( defined( 'PODS_SESSION_AUTO_START' ) && !PODS_SESSION_AUTO_START ) {
2058
		return false;
2059
	}
2060
	// Allow for non-file based sessions, like Memcache
2061
	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...
2062
		// This is OK, but we don't want to check if file_exists on next statement
2063
	}
2064
	// Check if session path exists and can be written to, avoiding PHP fatal errors
2065
	elseif ( empty( $save_path ) || !@file_exists( $save_path ) || !is_writable( $save_path ) ) {
2066
		return false;
2067
	}
2068
	// Check if session ID is already set
2069
	elseif ( '' != session_id() ) {
2070
		return false;
2071
	}
2072
2073
	// Start session
2074
	@session_start();
2075
2076
	return true;
2077
2078
}
2079
2080
/**
2081
 * @todo: replace string literal with a defined constant
2082
 *
2083
 * @return bool
2084
 */
2085
function pods_is_modal_window() {
2086
    return isset( $_GET[ 'pods_modal' ] );
2087
}
2088