PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.9.19.5
Pods – Custom Content Types and Fields v2.9.19.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / PodsView.php
pods / classes Last commit date
cli 1 day ago fields 1 day ago widgets 1 day ago Pods.php 1 day ago PodsAPI.php 1 day ago PodsAdmin.php 1 day ago PodsArray.php 1 day ago PodsComponent.php 1 day ago PodsComponents.php 1 day ago PodsData.php 1 day ago PodsField.php 1 day ago PodsForm.php 1 day ago PodsI18n.php 1 day ago PodsInit.php 1 day ago PodsMeta.php 1 day ago PodsMigrate.php 1 day ago PodsRESTFields.php 1 day ago PodsRESTHandlers.php 1 day ago PodsTermSplitting.php 1 day ago PodsUI.php 1 day ago PodsView.php 1 day ago
PodsView.php
767 lines
1 <?php
2
3 use Pods\Static_Cache;
4
5 /**
6 * @package Pods
7 */
8 class PodsView {
9
10 /**
11 * @var array $cache_modes Array of available cache modes
12 */
13 public static $cache_modes = [
14 'none' => true,
15 'transient' => true,
16 'site-transient' => true,
17 'cache' => true,
18 'static-cache' => true,
19 'option-cache' => true,
20 ];
21
22 /**
23 * @return \PodsView
24 */
25 private function __construct() {
26
27 // !nope
28 }
29
30 /**
31 * @static
32 *
33 * @param string $view Path of the view file
34 * @param array|null $data (optional) Data to pass on to the template
35 * @param bool|int|array $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
36 * @param string $cache_mode (optional) Decides the caching method to use for the view.
37 * @param bool $limited (optional) Whether to limit the view to only the theme directory, defaults to false
38 *
39 * @return bool|mixed|null|string|void
40 *
41 * @since 2.0.0
42 */
43 public static function view( $view, $data = null, $expires = false, $cache_mode = 'cache', $limited = false ) {
44
45 /**
46 * Override the value of $view. For example, using Pods AJAX View.
47 *
48 * To use, set first param to true. If that param in not null, this method returns its value.
49 *
50 * @param null|bool If not set to null, this filter overrides the rest of the method.
51 * @param string $view Path of the view file
52 * @param array|null $data (optional) Data to pass on to the template
53 * @param bool|int|array $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
54 * @param string $cache_mode (optional) Decides the caching method to use for the view.
55 * @param bool $limited (optional) Whether to limit the view to only the theme directory, defaults to false
56 *
57 * @since 2.4.1
58 */
59 $filter_check = apply_filters( 'pods_view_alt_view', null, $view, $data, $expires, $cache_mode );
60
61 if ( null !== $filter_check ) {
62 return $filter_check;
63 }
64
65 // Advanced $expires handling
66 $expires = self::expires( $expires, $cache_mode );
67
68 if ( ! self::is_cache_mode_valid( $cache_mode ) ) {
69 $cache_mode = 'cache';
70 }
71
72 // Support my-view.php?custom-key=X#hash keying for cache
73 $view_id = '';
74
75 if ( ! is_array( $view ) ) {
76 $view_q = explode( '?', $view );
77
78 if ( 1 < count( $view_q ) ) {
79 $view_id = '?' . $view_q[1];
80
81 $view = $view_q[0];
82 }
83
84 $view_h = explode( '#', $view );
85
86 if ( 1 < count( $view_h ) ) {
87 $view_id .= '#' . $view_h[1];
88
89 $view = $view_h[0];
90 }
91
92 // Support dynamic tags!
93 $view_id = pods_evaluate_tags( $view_id );
94 }
95
96 $view = apply_filters( 'pods_view_inc', $view, $data, $expires, $cache_mode, $limited );
97
98 $view_key = $view;
99
100 if ( is_array( $view_key ) ) {
101 $view_key = implode( '-', $view_key ) . '.php';
102 }
103
104 if ( false !== realpath( $view_key ) ) {
105 $view_key = realpath( $view_key );
106 }
107
108 $pods_ui_dir = realpath( PODS_DIR . 'ui/' );
109 $pods_components_dir = realpath( PODS_DIR . 'components/' );
110 $abspath_dir = realpath( ABSPATH );
111
112 $cache_key = pods_str_replace( $abspath_dir, '/', $view_key, 1 );
113
114 $output = false;
115
116 $caching = false;
117
118 if ( false !== $expires && false === strpos( $view_key, $pods_ui_dir ) && false === strpos( $view_key, $pods_components_dir ) ) {
119 $caching = true;
120 }
121
122 if ( $caching ) {
123 $output = self::get( 'pods-view-' . $cache_key . $view_id, $cache_mode, 'pods_view' );
124 }
125
126 if ( false === $output || null === $output ) {
127 $output = self::get_template_part( $view, $data );
128 }
129
130 if ( false !== $output && $caching ) {
131 self::set( 'pods-view-' . $cache_key . $view_id, $output, $expires, $cache_mode, 'pods_view' );
132 }
133
134 $output = apply_filters( "pods_view_output_{$cache_key}", $output, $view, $data, $expires, $cache_mode );
135 $output = apply_filters( 'pods_view_output', $output, $view, $data, $expires, $cache_mode );
136
137 return $output;
138 }
139
140 /**
141 * Get the full path of the view if it exists.
142 *
143 * @since 3.1.0
144 *
145 * @param string $view Path of the view file
146 * @param bool $limited (optional) Whether to limit the view to only the theme directory, defaults to false
147 *
148 * @return string|false The full path of the view if it exists.
149 */
150 public static function view_get_path( $view, $limited = false ) {
151 // Support my-view.php?custom-key=X#hash keying for cache
152 if ( ! is_array( $view ) ) {
153 $view_q = explode( '?', $view );
154
155 if ( 1 < count( $view_q ) ) {
156 $view = $view_q[0];
157 }
158
159 $view_h = explode( '#', $view );
160
161 if ( 1 < count( $view_h ) ) {
162 $view = $view_h[0];
163 }
164 }
165
166 $view = apply_filters( 'pods_view_inc', $view, null, false, 'cache', $limited );
167
168 $view_key = $view;
169
170 if ( is_array( $view_key ) ) {
171 $view_key = implode( '-', $view_key ) . '.php';
172 }
173
174 if ( false !== realpath( $view_key ) ) {
175 $view_key = realpath( $view_key );
176 }
177
178 $view_path = self::locate_template( $view_key, $limited );
179
180 if ( empty( $view_path ) ) {
181 return false;
182 }
183
184 return $view_path;
185 }
186
187 /**
188 * Get the cache key, salted with current Pods version, peppered with md5 if too long
189 *
190 * @param string $key
191 * @param string $group_key
192 *
193 * @return string
194 *
195 * @since 2.6.2
196 */
197 public static function get_key( $key, $group_key = '' ) {
198
199 // Add some salt
200 $key .= '-' . sanitize_key( PODS_VERSION );
201
202 // Patch for limitations in DB
203 if ( is_string( $group_key ) && 44 < strlen( $group_key . $key ) ) {
204 $key = md5( $key );
205 }
206
207 return $key;
208
209 }
210
211 /**
212 * @static
213 *
214 * @param string $key Key for the cache
215 * @param string $cache_mode (optional) Decides the caching method to use for the view.
216 * @param string $group (optional) Set the group of the value.
217 * @param string $callback (optional) Callback function to run to set the value if not cached.
218 *
219 * @return bool|mixed|null|void
220 *
221 * @since 2.0.0
222 */
223 public static function get( $key, $cache_mode = 'cache', $group = '', $callback = null ) {
224 $external_object_cache = wp_using_ext_object_cache();
225
226 $object_cache_enabled = (
227 (
228 isset( $GLOBALS['wp_object_cache'] )
229 && is_object( $GLOBALS['wp_object_cache'] )
230 )
231 || $external_object_cache
232 );
233
234 if ( ! self::is_cache_mode_valid( $cache_mode ) ) {
235 $cache_mode = 'cache';
236 }
237
238 $group_key = 'pods_';
239
240 if ( ! empty( $group ) ) {
241 $group_key = $group . '_';
242 }
243
244 $original_key = $key;
245
246 // Get proper cache key
247 $key = self::get_key( $key, $group_key );
248
249 $value = null;
250
251 $called = false;
252
253 $pods_nocache = pods_v( 'pods_nocache' );
254 $nocache = array();
255
256 if ( null !== $pods_nocache && pods_is_admin() ) {
257 if ( is_string( $pods_nocache ) && 1 < strlen( $pods_nocache ) ) {
258 $nocache = explode( ',', $pods_nocache );
259 $nocache = array_flip( $nocache );
260 } else {
261 $nocache = self::$cache_modes;
262 }
263 }
264
265 $cache_enabled = ! isset( $nocache[ $cache_mode ] );
266
267 if ( apply_filters( 'pods_view_cache_alt_get', false, $cache_mode, $group_key . $key, $original_key, $group ) ) {
268 $value = apply_filters( 'pods_view_cache_alt_get_value', $value, $cache_mode, $group_key . $key, $original_key, $group );
269 } elseif ( $cache_enabled ) {
270 if ( 'transient' === $cache_mode ) {
271 $value = get_transient( $group_key . $key );
272 } elseif ( 'site-transient' === $cache_mode ) {
273 $value = get_site_transient( $group_key . $key );
274 } elseif ( 'cache' === $cache_mode && $object_cache_enabled ) {
275 $value = wp_cache_get( $key, ( empty( $group ) ? 'pods_view' : $group ) );
276 } elseif ( 'option-cache' === $cache_mode ) {
277 $pre = apply_filters( "pre_transient_{$key}", false );
278
279 if ( false !== $pre ) {
280 $value = $pre;
281 } elseif ( $external_object_cache ) {
282 $cache_found = false;
283
284 $value = wp_cache_get( $key, ( empty( $group ) ? 'pods_option_cache' : $group ), false, $cache_found );
285
286 if ( false === $value || ! $cache_found ) {
287 if ( is_callable( $callback ) ) {
288 // Callback function should do it's own set/update for cache
289 $callback_value = call_user_func( $callback, $original_key, $group, $cache_mode );
290
291 if ( null !== $callback_value && false !== $callback_value ) {
292 $value = $callback_value;
293 }
294
295 $called = true;
296 }
297 }
298 } else {
299 $transient_option = '_pods_option_' . $key;
300 $transient_timeout = '_pods_option_timeout_' . $key;
301
302 $value = get_option( $transient_option );
303 $timeout = get_option( $transient_timeout );
304
305 if ( ! empty( $timeout ) && $timeout < time() ) {
306 if ( is_callable( $callback ) ) {
307 // Callback function should do it's own set/update for cache
308 $callback_value = call_user_func( $callback, $original_key, $group, $cache_mode );
309
310 if ( null !== $callback_value && false !== $callback_value ) {
311 $value = $callback_value;
312 }
313
314 $called = true;
315 } else {
316 $value = false;
317
318 delete_option( $transient_option );
319 delete_option( $transient_timeout );
320 }
321 }
322 }//end if
323
324 if ( false !== $value ) {
325 $value = apply_filters( "transient_{$key}", $value );
326 }
327 } elseif ( 'static-cache' === $cache_mode ) {
328 $static_cache = pods_container( Static_Cache::class );
329
330 if ( $static_cache ) {
331 $value = $static_cache->get( $key, ( empty( $group ) ? 'pods_view' : $group ) );
332 } else {
333 $value = false;
334 }
335 } else {
336 $value = false;
337 }//end if
338 } else {
339 $value = false;
340 }//end if
341
342 if ( false === $value && is_callable( $callback ) && ! $called ) {
343 // Callback function should do it's own set/update for cache
344 $callback_value = call_user_func( $callback, $original_key, $group, $cache_mode );
345
346 if ( null !== $callback_value && false !== $callback_value ) {
347 $value = $callback_value;
348 }
349 }
350
351 $value = apply_filters( "pods_view_get_{$cache_mode}", $value, $original_key, $group );
352
353 return $value;
354 }
355
356 /**
357 * @static
358 *
359 * Set a cached value
360 *
361 * @param string $key Key for the cache
362 * @param mixed $value Value to add to the cache
363 * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration.
364 * @param string $cache_mode (optional) Decides the caching method to use for the view.
365 * @param string $group (optional) Set the group of the value.
366 *
367 * @return bool|mixed|null|string|void
368 *
369 * @since 2.0.0
370 */
371 public static function set( $key, $value, $expires = 0, $cache_mode = null, $group = '' ) {
372 $external_object_cache = wp_using_ext_object_cache();
373
374 $object_cache_enabled = (
375 (
376 isset( $GLOBALS['wp_object_cache'] )
377 && is_object( $GLOBALS['wp_object_cache'] )
378 )
379 || $external_object_cache
380 );
381
382 // Advanced $expires handling
383 $expires = self::expires( $expires, $cache_mode );
384
385 if ( ! self::is_cache_mode_valid( $cache_mode ) ) {
386 $cache_mode = 'cache';
387 }
388
389 $group_key = 'pods_';
390
391 if ( ! empty( $group ) ) {
392 $group_key = $group . '_';
393 }
394
395 $original_key = $key;
396
397 // Get proper cache key
398 $key = self::get_key( $key, $group_key );
399
400 if ( apply_filters( 'pods_view_cache_alt_set', false, $cache_mode, $group_key . $key, $original_key, $value, $expires, $group ) ) {
401 return $value;
402 } elseif ( 'transient' === $cache_mode ) {
403 set_transient( $group_key . $key, $value, $expires );
404 } elseif ( 'site-transient' === $cache_mode ) {
405 set_site_transient( $group_key . $key, $value, $expires );
406 } elseif ( 'cache' === $cache_mode && $object_cache_enabled ) {
407 wp_cache_set( $key, $value, ( empty( $group ) ? 'pods_view' : $group ), $expires );
408 } elseif ( 'option-cache' === $cache_mode ) {
409 $value = apply_filters( "pre_set_transient_{$key}", $value );
410
411 if ( $external_object_cache ) {
412 $result = wp_cache_set( $key, $value, ( empty( $group ) ? 'pods_option_cache' : $group ), $expires );
413 } else {
414 $transient_timeout = '_pods_option_timeout_' . $key;
415 $key = '_pods_option_' . $key;
416
417 if ( false === get_option( $key ) ) {
418 if ( $expires ) {
419 add_option( $transient_timeout, time() + $expires, '', 'no' );
420 }
421
422 $result = add_option( $key, $value, '', 'no' );
423 } else {
424 if ( $expires ) {
425 update_option( $transient_timeout, time() + $expires );
426 }
427
428 $result = update_option( $key, $value );
429 }
430 }//end if
431
432 if ( $result ) {
433 do_action( "set_transient_{$key}" );
434 do_action( 'setted_transient', $key );
435 }
436 } elseif ( 'static-cache' === $cache_mode ) {
437 $static_cache = pods_container( Static_Cache::class );
438
439 if ( $static_cache ) {
440 $static_cache->set( $key, $value, ( empty( $group ) ? __CLASS__ : $group ) );
441 }
442 }//end if
443
444 do_action( "pods_view_set_{$cache_mode}", $original_key, $value, $expires, $group );
445
446 return $value;
447 }
448
449 /**
450 * @static
451 *
452 * Clear a cached value
453 *
454 * @param string|bool $key Key for the cache
455 * @param string $cache_mode (optional) Decides the caching method to use for the view.
456 * @param string $group (optional) Set the group.
457 *
458 * @return bool
459 *
460 * @since 2.0.0
461 */
462 public static function clear( $key = true, $cache_mode = null, $group = '' ) {
463 $external_object_cache = wp_using_ext_object_cache();
464
465 $object_cache_enabled = (
466 (
467 isset( $GLOBALS['wp_object_cache'] )
468 && is_object( $GLOBALS['wp_object_cache'] )
469 )
470 || $external_object_cache
471 );
472
473 global $wpdb;
474
475 if ( ! self::is_cache_mode_valid( $cache_mode ) ) {
476 $cache_mode = 'cache';
477 }
478
479 $group_key = 'pods_';
480
481 if ( ! empty( $group ) ) {
482 $group_key = $group . '_';
483 }
484
485 $full_key = $key;
486 $original_key = $key;
487
488 if ( true !== $key ) {
489 // Get proper cache key
490 $key = self::get_key( $key, $group_key );
491
492 $full_key = $group_key . $key;
493 }
494
495 if ( apply_filters( 'pods_view_cache_alt_set', false, $cache_mode, $full_key, $original_key, '', 0, $group ) ) {
496 return true;
497 } elseif ( 'transient' === $cache_mode ) {
498 if ( true === $key ) {
499 $group_key = pods_sanitize_like( $group_key );
500
501 $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_transient_{$group_key}%'" );
502
503 if ( $object_cache_enabled ) {
504 wp_cache_flush();
505 }
506 } else {
507 delete_transient( $group_key . $key );
508 }
509 } elseif ( 'site-transient' === $cache_mode ) {
510 if ( true === $key ) {
511 $group_key = pods_sanitize_like( $group_key );
512
513 $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_site_transient_{$group_key}%'" );
514
515 if ( $object_cache_enabled ) {
516 wp_cache_flush();
517 }
518 } else {
519 delete_site_transient( $group_key . $key );
520 }
521 } elseif ( 'cache' === $cache_mode && $object_cache_enabled ) {
522 if ( true === $key ) {
523 wp_cache_flush();
524 } else {
525 wp_cache_delete( ( empty( $key ) ? 'pods_view' : $key ), ( empty( $group ) ? 'pods_view' : $group ) );
526 }
527 } elseif ( 'option-cache' === $cache_mode ) {
528 do_action( "delete_transient_{$key}", $key );
529
530 if ( $external_object_cache ) {
531 $result = wp_cache_delete( $key, ( empty( $group ) ? 'pods_option_cache' : $group ) );
532
533 wp_cache_delete( '_timeout_' . $key, ( empty( $group ) ? 'pods_option_cache' : $group ) );
534 } else {
535 $option_timeout = '_pods_option_timeout_' . $key;
536 $option = '_pods_option_' . $key;
537
538 $result = delete_option( $option );
539
540 if ( $result ) {
541 delete_option( $option_timeout );
542 }
543 }
544
545 if ( $result ) {
546 do_action( 'deleted_transient', $key );
547 }
548 } elseif ( 'static-cache' === $cache_mode ) {
549 $static_cache = pods_container( Static_Cache::class );
550
551 if ( $static_cache ) {
552 if ( true === $key ) {
553 $static_cache->flush( ( empty( $group ) ? 'pods_view' : $group ) );
554 } else {
555 $static_cache->delete( ( empty( $key ) ? 'pods_view' : $key ), ( empty( $group ) ? 'pods_view' : $group ) );
556 }
557 }
558 }//end if
559
560 do_action( "pods_view_clear_{$cache_mode}", $original_key, $group );
561
562 return true;
563 }
564
565 /**
566 * @static
567 *
568 * @param $_view
569 * @param null|array $_data
570 * @param bool $limited (optional) Whether to limit the view to only the theme directory, defaults to false
571 *
572 * @return bool|mixed|string|void
573 */
574 public static function get_template_part( $_view, $_data = null, $limited = false ) {
575
576 /*
577 To be reviewed later, should have more checks and restrictions like a whitelist etc.
578
579 if ( 0 === strpos( $_view, 'http://' ) || 0 === strpos( $_view, 'https://' ) ) {
580 $_view = apply_filters( 'pods_view_url_include', $_view );
581
582 if ( empty( $_view ) || ( defined( 'PODS_REMOTE_VIEWS' ) && PODS_REMOTE_VIEWS ) )
583 return '';
584
585 $response = wp_remote_get( $_view );
586
587 return wp_remote_retrieve_body( $response );
588 }
589 */
590
591 $_view = self::locate_template( $_view, $limited );
592
593 if ( empty( $_view ) ) {
594 return $_view;
595 }
596
597 if ( ! empty( $_data ) && is_array( $_data ) ) {
598 // Only expose array entries whose keys are valid PHP variable names as template variables (EXTR_SKIP prevents overwriting existing scope), to help prevent security issues.
599 $_safe_data = array_filter(
600 $_data,
601 static function ( $key ) {
602 return is_string( $key ) && preg_match( '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $key );
603 },
604 ARRAY_FILTER_USE_KEY
605 );
606
607 extract( $_safe_data, EXTR_SKIP );
608 }
609
610 ob_start();
611 require $_view;
612 $output = ob_get_clean();
613
614 return $output;
615 }
616
617 /**
618 * @static
619 *
620 * @param array|string $_view
621 * @param bool $limited (optional) Whether to limit the view to only the theme directory, defaults to false
622 *
623 * @return bool|mixed|string|void
624 */
625 private static function locate_template( $_view, $limited = false ) {
626 if ( is_array( $_view ) ) {
627 $_views = [];
628
629 if ( isset( $_view[0] ) && false === strpos( $_view[0], '.php' ) ) {
630 $_view_count = count( $_view );
631
632 for ( $_view_x = $_view_count; 0 < $_view_x; $_view_x -- ) {
633 $_view_v = array_slice( $_view, 0, $_view_x );
634
635 $_views[] = implode( '-', $_view_v ) . '.php';
636 }
637 } else {
638 $_views = $_view;
639 }
640
641 $_view = false;
642
643 foreach ( $_views as $_view_check ) {
644 $_view = self::locate_template( $_view_check );
645
646 if ( ! empty( $_view ) ) {
647 break;
648 }
649 }
650
651 return $_view;
652 }//end if
653
654 $paths_to_check = [ 'plugins', 'pods', 'theme' ];
655
656 if ( $limited ) {
657 $paths_to_check = [ 'theme' ];
658 }
659
660 // Is the view's file somewhere within the plugin directory tree?
661 // Note: we include PODS_DIR for the case of symlinks (see issue #2945).
662 $located = pods_validate_safe_path( $_view, $paths_to_check );
663
664 /**
665 * Allow filtering the validated view file path to use.
666 *
667 * @since unknown
668 *
669 * @param string|false $located The validated view file path to use, or false if it was not valid.
670 * @param string $_view The original view file path to use.
671 */
672 $located = apply_filters( 'pods_view_locate_template', $located, $_view );
673
674 if ( ! $located ) {
675 return false;
676 }
677
678 return $located;
679
680 }
681
682 /**
683 * Advanced $expires handling
684 *
685 * @param array|bool|int $expires
686 * @param string $cache_mode
687 *
688 * @return bool|int
689 *
690 * @since 2.7.0
691 * @static
692 */
693 public static function expires( $expires, $cache_mode = 'cache' ) {
694
695 // Different $expires if user is anonymous or logged in or specific capability
696 if ( is_array( $expires ) ) {
697 if ( ( isset( $expires['anonymous'] ) || isset( $expires['user_with_access'] ) ) && isset( $expires['user'] ) ) {
698 if ( isset( $expires['user_with_access'] ) ) {
699 $expires = array(
700 pods_v( 'anonymous', $expires, false ),
701 pods_v( 'user', $expires, false ),
702 pods_v( 'user_with_access', $expires, false ),
703 pods_v( 'capability', $expires, null, null, true ),
704 );
705 } elseif ( isset( $expires['anonymous'] ) ) {
706 $expires = array(
707 pods_v( 'anonymous', $expires, false ),
708 pods_v( 'user', $expires, false ),
709 pods_v( 'capability', $expires, null, null, true ),
710 );
711 }
712 } else {
713 $expires = array_values( $expires );
714 }
715
716 if ( 4 === count( $expires ) ) {
717 if ( ! is_user_logged_in() ) {
718 $expires = pods_v( 0, $expires, false );
719 } else {
720 $user_no_access = pods_v( 1, $expires, false );
721 $user_with_access = pods_v( 2, $expires, false );
722 $capability = pods_v( 3, $expires, null, true );
723
724 $expires = pods_var_user( $user_no_access, $user_with_access, $capability );
725 }
726 } else {
727 $anon = pods_v( 0, $expires, false );
728 $user = pods_v( 1, $expires, false );
729 $capability = pods_v( 2, $expires, null, true );
730
731 $expires = pods_var_user( $anon, $user, $capability );
732 }
733 }//end if
734
735 if ( 'none' === $cache_mode ) {
736 $expires = false;
737 } elseif ( false !== $expires ) {
738 $expires = (int) $expires;
739
740 if ( $expires < 1 ) {
741 $expires = 0;
742 }
743 }
744
745 return $expires;
746
747 }
748
749 /**
750 * Determine whether the cache mode is valid.
751 *
752 * @since 2.9.14
753 *
754 * @param string|mixed $cache_mode The cache mode.
755 *
756 * @return bool Whether the cache mode is valid.
757 */
758 public static function is_cache_mode_valid( $cache_mode ) {
759 return (
760 $cache_mode
761 && is_string( $cache_mode )
762 && isset( self::$cache_modes[ $cache_mode ] )
763 );
764 }
765
766 }
767