PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.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 / components / Pages.php
pods / components Last commit date
Builder 2 days ago I18n 2 days ago Migrate-CPTUI 2 days ago Migrate-Packages 2 days ago Roles 2 days ago Templates 2 days ago Advanced-Content-Types.php 2 days ago Advanced-Relationships.php 2 days ago Markdown.php 2 days ago Pages.php 2 days ago Table-Storage.php 2 days ago
Pages.php
1580 lines
1 <?php
2 /**
3 * Name: Pages
4 *
5 * Menu Name: Pod Pages
6 *
7 * Description: Creates advanced URL structures using wildcards in order to enable the front-end display of Pods Advanced Content Types. Not recommended for use with other content types.
8 *
9 * Version: 2.3
10 *
11 * Category: Advanced
12 *
13 * Menu Page: edit.php?post_type=_pods_page
14 * Menu Add Page: post-new.php?post_type=_pods_page
15 *
16 * @package Pods\Components
17 * @subpackage Pages
18 */
19
20 use Illuminate\Contracts\View\Factory as ViewFactory;
21 use Pods\Whatsit\Field;
22 use Pods\Whatsit\Storage;
23
24 if ( class_exists( 'Pods_Pages' ) ) {
25 return;
26 }
27
28 /**
29 * Class Pods_Pages
30 */
31 class Pods_Pages extends PodsComponent {
32
33 /**
34 * Current Pod Page
35 *
36 * @var array
37 *
38 * @since 2.0.0
39 */
40 public static $exists = null;
41
42 /**
43 * Object type
44 *
45 * @var string
46 *
47 * @since 2.0.0
48 */
49 private $object_type = '_pods_page';
50
51 /**
52 * Whether the page has been checked already
53 *
54 * @var bool
55 *
56 * @since 2.1.0
57 */
58 public static $checked = false;
59
60 /**
61 * Keep track of if pods_content has been called yet
62 *
63 * @var bool
64 *
65 * @since 2.3.0
66 */
67 public static $content_called = false;
68
69 /**
70 * The capability type.
71 *
72 * @link https://codex.wordpress.org/Function_Reference/register_post_type
73 * @var string
74 */
75 private $capability_type = 'pods_page';
76
77 /**
78 * {@inheritdoc}
79 */
80 public function init() {
81
82 add_shortcode( 'pods-content', array( $this, 'shortcode' ) );
83
84 $args = array(
85 'label' => 'Pod Pages',
86 'labels' => array( 'singular_name' => 'Pod Page' ),
87 'public' => false,
88 'can_export' => false,
89 'show_ui' => true,
90 'show_in_menu' => false,
91 'query_var' => false,
92 'rewrite' => false,
93 'has_archive' => false,
94 'hierarchical' => false,
95 'supports' => array( 'title', 'author', 'revisions' ),
96 'menu_icon' => pods_svg_icon( 'pods' ),
97 );
98
99 if ( ! pods_is_admin() ) {
100 $args['capability_type'] = $this->capability_type;
101 }
102
103 $args = PodsInit::object_label_fix( $args, 'post_type' );
104
105 register_post_type( $this->object_type, apply_filters( 'pods_internal_register_post_type_object_page', $args ) );
106
107 add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 );
108
109 if ( ! is_admin() ) {
110 add_action( 'load_textdomain', array( $this, 'page_check' ), 12 );
111 } else {
112 add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
113
114 add_action( 'add_meta_boxes_' . $this->object_type, array( $this, 'edit_page_form' ) );
115
116 add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
117 add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 );
118 add_filter( 'update_post_metadata', array( $this, 'save_meta' ), 10, 4 );
119
120 add_action( 'pods_meta_save_pre_post__pods_page', array( $this, 'fix_filters' ), 10, 5 );
121 add_action( 'post_updated', array( $this, 'clear_cache' ), 10, 3 );
122 add_action( 'delete_post', array( $this, 'clear_cache' ), 10, 1 );
123 add_filter( 'post_row_actions', array( $this, 'remove_row_actions' ), 10, 2 );
124 add_filter( 'bulk_actions-edit-' . $this->object_type, array( $this, 'remove_bulk_actions' ) );
125
126 add_filter( 'builder_layout_filter_non_layout_post_types', array( $this, 'disable_builder_layout' ) );
127 }
128
129 add_filter( 'members_get_capabilities', array( $this, 'get_capabilities' ) );
130 }
131
132 /**
133 * @param $caps
134 *
135 * @return array
136 */
137 public function get_capabilities( $caps ) {
138
139 $caps = array_merge(
140 $caps, array(
141 'edit_' . $this->capability_type,
142 'read_' . $this->capability_type,
143 'delete_' . $this->capability_type,
144 'edit_' . $this->capability_type . 's',
145 'edit_others_' . $this->capability_type . 's',
146 'publish_' . $this->capability_type . 's',
147 'read_private_' . $this->capability_type . 's',
148 'edit_' . $this->capability_type . 's',
149 )
150 );
151
152 return $caps;
153 }
154
155 /**
156 * Pod Page Content Shortcode support for use anywhere that supports WP Shortcodes
157 *
158 * @param array $tags An associative array of shortcode properties
159 * @param string $content Not currently used
160 *
161 * @return string
162 * @since 2.3.9
163 */
164 public function shortcode( $tags, $content = null ) {
165
166 if ( ! isset( $tags['page'] ) || empty( $tags['page'] ) ) {
167 $tags['page'] = null;
168 }
169
170 $pods_page = self::exists( $tags['page'] );
171
172 if ( empty( $pods_page ) ) {
173 return '<p>Pods Page not found</p>';
174 }
175
176 return self::content( true, $pods_page );
177 }
178
179 /**
180 * Disable this Post Type from appearing in the Builder layouts list
181 *
182 * @param array $post_types
183 *
184 * @return array
185 */
186 public function disable_builder_layout( $post_types ) {
187
188 $post_types[] = $this->object_type;
189
190 return $post_types;
191 }
192
193 /**
194 * Update Post Type messages
195 *
196 * @param array $messages
197 *
198 * @return array
199 * @since 2.0.2
200 */
201 public function setup_updated_messages( $messages ) {
202
203 global $post, $post_ID;
204
205 $post_type = get_post_type_object( $this->object_type );
206
207 $labels = $post_type->labels;
208
209 $messages[ $post_type->name ] = array(
210 1 => sprintf( __( '%1$s updated. <a href="%2$s">%3$s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ),
211 2 => __( 'Custom field updated.', 'pods' ),
212 3 => __( 'Custom field deleted.', 'pods' ),
213 4 => sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ),
214 /* translators: %s: date and time of the revision */
215 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'pods' ), $labels->singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
216 6 => sprintf( __( '%1$s published. <a href="%2$s">%3$s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ),
217 7 => sprintf( __( '%s saved.', 'pods' ), $labels->singular_name ),
218 8 => sprintf( __( '%1$s submitted. <a target="_blank" rel="noopener noreferrer" href="%2$s">Preview %3$s</a>', 'pods' ), $labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels->singular_name ),
219 9 => sprintf(
220 __( '%1$s scheduled for: <strong>%2$s</strong>. <a target="_blank" rel="noopener noreferrer" href="%3$s">Preview %4$s</a>', 'pods' ), $labels->singular_name,
221 // translators: Publish box date format, see http://php.net/date
222 date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $labels->singular_name
223 ),
224 10 => sprintf( __( '%1$s draft updated. <a target="_blank" rel="noopener noreferrer" href="%2$s">Preview %3$s</a>', 'pods' ), $labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels->singular_name ),
225 );
226
227 if ( false === (boolean) $post_type->public ) {
228 $messages[ $post_type->name ][1] = sprintf( __( '%s updated.', 'pods' ), $labels->singular_name );
229 $messages[ $post_type->name ][6] = sprintf( __( '%s published.', 'pods' ), $labels->singular_name );
230 $messages[ $post_type->name ][8] = sprintf( __( '%s submitted.', 'pods' ), $labels->singular_name );
231 $messages[ $post_type->name ][9] = sprintf(
232 __( '%1$s scheduled for: <strong>%2$s</strong>.', 'pods' ), $labels->singular_name,
233 // translators: Publish box date format, see http://php.net/date
234 date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) )
235 );
236 $messages[ $post_type->name ][10] = sprintf( __( '%s draft updated.', 'pods' ), $labels->singular_name );
237 }
238
239 return $messages;
240 }
241
242 /**
243 * Enqueue styles
244 *
245 * @since 2.0.0
246 */
247 public function admin_assets() {
248 wp_enqueue_script( 'pods-dfv' );
249 wp_enqueue_style( 'pods-styles' );
250 }
251
252 /**
253 * Fix filters, specifically removing balanceTags
254 *
255 * @since 2.0.1
256 *
257 * @param $data
258 * @param null $pod
259 * @param null $id
260 * @param null $groups
261 * @param null $post
262 */
263 public function fix_filters( $data, $pod = null, $id = null, $groups = null, $post = null ) {
264
265 remove_filter( 'content_save_pre', 'balanceTags', 50 );
266 }
267
268 /**
269 * Remove unused row actions
270 *
271 * @since 2.0.5
272 *
273 * @param $actions
274 * @param $post
275 *
276 * @return
277 */
278 public function remove_row_actions( $actions, $post ) {
279
280 global $current_screen;
281
282 if ( ! is_object( $current_screen ) || $this->object_type != $current_screen->post_type ) {
283 return $actions;
284 }
285
286 if ( isset( $actions['view'] ) ) {
287 unset( $actions['view'] );
288 }
289
290 if ( isset( $actions['inline hide-if-no-js'] ) ) {
291 unset( $actions['inline hide-if-no-js'] );
292 }
293
294 // W3 Total Cache
295 if ( isset( $actions['pgcache_purge'] ) ) {
296 unset( $actions['pgcache_purge'] );
297 }
298
299 return $actions;
300 }
301
302 /**
303 * Remove unused bulk actions
304 *
305 * @since 2.0.5
306 *
307 * @param $actions
308 *
309 * @return
310 */
311 public function remove_bulk_actions( $actions ) {
312
313 if ( isset( $actions['edit'] ) ) {
314 unset( $actions['edit'] );
315 }
316
317 return $actions;
318 }
319
320 /**
321 * Clear cache on save
322 *
323 * @since 2.0.0
324 *
325 * @param $data
326 * @param null $pod
327 * @param null $id
328 * @param null $groups
329 * @param null $post
330 */
331 public function clear_cache( $data, $pod = null, $id = null, $groups = null, $post = null ) {
332
333 $old_post = $id;
334
335 if ( ! is_object( $id ) ) {
336 $old_post = null;
337 }
338
339 if ( is_object( $post ) && $this->object_type != $post->post_type ) {
340 return;
341 }
342
343 if ( ! is_array( $data ) && 0 < $data ) {
344 $post = $data;
345 $post = get_post( $post );
346 }
347
348 if ( $this->object_type == $post->post_type ) {
349 pods_transient_clear( 'pods_object_pages' );
350
351 if ( is_object( $old_post ) && $this->object_type == $old_post->post_type ) {
352 pods_cache_clear( $old_post->post_title, 'pods_object_page_wildcard' );
353 }
354
355 pods_cache_clear( $post->post_title, 'pods_object_page_wildcard' );
356
357 self::flush_rewrites();
358 }
359 }
360
361 /**
362 * Change post title placeholder text
363 *
364 * @since 2.0.0
365 *
366 * @param $text
367 * @param $post
368 *
369 * @return string|void
370 */
371 public function set_title_text( $text, $post ) {
372
373 return __( 'Enter URL here', 'pods' );
374 }
375
376 /**
377 * Edit page form
378 *
379 * @since 2.0.0
380 */
381 public function edit_page_form() {
382
383 global $post_type;
384
385 if ( $this->object_type !== $post_type ) {
386 return;
387 }
388
389 add_filter( 'enter_title_here', array( $this, 'set_title_text' ), 10, 2 );
390 }
391
392 /**
393 * Filter permalinks and adjust for pod pages
394 *
395 * @param $post_link
396 * @param $post
397 *
398 * @return mixed
399 */
400 public function post_type_link( $post_link, $post ) {
401
402 if ( empty( $post ) || $this->object_type != $post->post_type ) {
403 return $post_link;
404 }
405
406 $post_link = get_site_url() . '/';
407
408 if ( false === strpos( $post->post_title, '*' ) ) {
409 $post_link .= trim( $post->post_title, '/ ' ) . '/';
410 }
411
412 return $post_link;
413 }
414
415 /**
416 * Add meta boxes to the page
417 *
418 * @since 2.0.0
419 */
420 public function add_meta_boxes() {
421 $pod = [
422 'name' => $this->object_type,
423 'type' => 'post_type',
424 ];
425
426 if ( isset( PodsMeta::$post_types[ $pod['name'] ] ) ) {
427 return;
428 }
429
430 add_action( 'admin_enqueue_scripts', [ $this, 'admin_assets' ], 21 );
431
432 if ( ! function_exists( 'get_page_templates' ) ) {
433 include_once ABSPATH . 'wp-admin/includes/theme.php';
434 }
435
436 $wp_page_templates = apply_filters( 'pods_page_templates', get_page_templates() );
437
438 $page_templates = [];
439
440 foreach ( $wp_page_templates as $page_template => $file ) {
441 $page_templates[ $page_template . ' - ' . $file ] = $file;
442 }
443
444 $page_templates[ __( '-- Select a Page Template --', 'pods' ) ] = '';
445
446 $page_templates[ __( 'Custom (uses only Pod Page content)', 'pods' ) ] = '_custom';
447
448 if ( ! in_array( 'pods.php', $page_templates, true ) && locate_template( [ 'pods.php', false ] ) ) {
449 $page_templates[ __( 'Pods (Pods Default)', 'pods' ) . ' - pods.php' ] = 'pods.php';
450 }
451
452 if ( ! in_array( 'page.php', $page_templates, true ) && locate_template( [ 'page.php', false ] ) ) {
453 $page_templates[ __( 'Page (WP Default)', 'pods' ) . ' - page.php' ] = 'page.php';
454 }
455
456 if ( ! in_array( 'index.php', $page_templates, true ) && locate_template( [ 'index.php', false ] ) ) {
457 $page_templates[ __( 'Index (WP Fallback)', 'pods' ) . ' - index.php' ] = 'index.php';
458 }
459
460 ksort( $page_templates );
461
462 $page_templates = array_flip( $page_templates );
463
464 $page_fields = [
465 [
466 'name' => 'page_title',
467 'label' => __( 'Page Title', 'pods' ),
468 'type' => 'text',
469 ],
470 [
471 'name' => 'code',
472 'label' => __( 'Page Code', 'pods' ),
473 'type' => 'code',
474 'attributes' => [
475 'id' => 'content',
476 ],
477 'label_options' => [
478 'attributes' => [
479 'for' => 'content',
480 ],
481 ],
482 ],
483 [
484 'name' => 'precode',
485 'label' => __( 'Page Precode', 'pods' ),
486 'type' => 'code',
487 'help' => __( 'Precode will run before your theme outputs the page. It is expected that this value will be a block of PHP. You must open the PHP tag here, as we do not open it for you by default.', 'pods' ),
488 ],
489 [
490 'name' => 'page_template',
491 'label' => __( 'Page Template', 'pods' ),
492 'default' => '',
493 'type' => 'pick',
494 'pick_object' => 'custom-simple',
495 'pick_format_type' => 'single',
496 'data' => $page_templates,
497 'override_object_field' => true,
498 ],
499 ];
500
501 $associated_pods = [
502 0 => __( '-- Select a Pod --', 'pods' ),
503 ];
504
505 $all_pods = pods_api()->load_pods( [ 'labels' => true ] );
506
507 if ( ! empty( $all_pods ) ) {
508 foreach ( $all_pods as $pod_name => $pod_label ) {
509 $associated_pods[ $pod_name ] = $pod_label . ' (' . $pod_name . ')';
510 }
511 } else {
512 $associated_pods[0] = __( 'None Found', 'pods' );
513 }
514
515 $association_fields = [
516 [
517 'name' => 'pod',
518 'label' => __( 'Associated Pod', 'pods' ),
519 'default' => 0,
520 'type' => 'pick',
521 'pick_object' => 'custom-simple',
522 'pick_format_type' => 'single',
523 'placeholder' => __( 'Select Pod', 'pods' ),
524 'data' => $associated_pods,
525 'dependency' => true,
526 ],
527 [
528 'name' => 'pod_slug',
529 'label' => __( 'Wildcard Slug', 'pods' ),
530 'help' => __( 'Setting the Wildcard Slug is an easy way to setup a detail page. You can use the special tag {@url.2} to match the *third* level of the URL of a Pod Page named "first/second/*" part of the pod page. This is functionally the same as using pods_v_sanitized( 2, "url" ) in PHP.', 'pods' ),
531 'type' => 'text',
532 'excludes-on' => [ 'pod' => 0 ],
533 ],
534 ];
535
536 $restrict_fields = [
537 [
538 'name' => 'admin_only',
539 'label' => __( 'Restrict access to Admins', 'pods' ),
540 'default' => 0,
541 'type' => 'boolean',
542 'dependency' => true,
543 ],
544 [
545 'name' => 'restrict_role',
546 'label' => __( 'Restrict access by Role', 'pods' ),
547 'help' => [
548 __( '<h6>Roles</h6> Roles are assigned to users to provide them access to specific functionality in WordPress. Please see the Roles and Capabilities component in Pods for an easy tool to add your own roles and edit existing ones.', 'pods' ),
549 'http://codex.wordpress.org/Roles_and_Capabilities',
550 ],
551 'default' => 0,
552 'type' => 'boolean',
553 'dependency' => true,
554 ],
555 [
556 'name' => 'roles_allowed',
557 'label' => __( 'Role(s) Allowed', 'pods' ),
558 'type' => 'pick',
559 'pick_object' => 'role',
560 'pick_format_type' => 'multi',
561 'pick_format_multi' => 'autocomplete',
562 'pick_ajax' => false,
563 'default' => '',
564 'depends-on' => [
565 'pods_meta_restrict_role' => true,
566 ],
567 ],
568 [
569 'name' => 'restrict_capability',
570 'label' => __( 'Restrict access by Capability', 'pods' ),
571 'help' => [
572 __( '<h6>Capabilities</h6> Capabilities denote access to specific functionality in WordPress, and are assigned to specific User Roles. Please see the Roles and Capabilities component in Pods for an easy tool to add your own capabilities and roles.', 'pods' ),
573 'http://codex.wordpress.org/Roles_and_Capabilities',
574 ],
575 'default' => 0,
576 'type' => 'boolean',
577 'dependency' => true,
578 ],
579 [
580 'name' => 'capability_allowed',
581 'label' => __( 'Capability Allowed', 'pods' ),
582 'type' => 'pick',
583 'pick_object' => 'capability',
584 'pick_format_type' => 'multi',
585 'pick_format_multi' => 'autocomplete',
586 'pick_ajax' => false,
587 'default' => '',
588 'depends-on' => [
589 'pods_meta_restrict_capability' => true,
590 ],
591 ],
592 [
593 'name' => 'restrict_redirect',
594 'label' => __( 'Redirect if Restricted', 'pods' ),
595 'default' => 0,
596 'type' => 'boolean',
597 'dependency' => true,
598 ],
599 [
600 'name' => 'restrict_redirect_login',
601 'label' => __( 'Redirect to WP Login page', 'pods' ),
602 'default' => 0,
603 'type' => 'boolean',
604 'dependency' => true,
605 'depends-on' => [
606 'pods_meta_restrict_redirect' => true,
607 ],
608 ],
609 [
610 'name' => 'restrict_redirect_url',
611 'label' => __( 'Redirect to a Custom URL', 'pods' ),
612 'default' => '',
613 'type' => 'text',
614 'depends-on' => [
615 'pods_meta_restrict_redirect' => true,
616 'pods_meta_restrict_redirect_login' => false,
617 ],
618 ],
619 ];
620
621 $fields = array_merge( $page_fields, $association_fields, $restrict_fields );
622
623 $object_collection = Pods\Whatsit\Store::get_instance();
624
625 /** @var Storage $storage */
626 $storage = $object_collection->get_storage_object( 'collection' );
627
628 foreach ( $fields as $field ) {
629 $field['parent'] = $pod['name'];
630
631 $field = new Field( $field );
632
633 $storage->add( $field );
634 }
635
636 pods_group_add( $pod, __( 'Page', 'pods' ), $page_fields, 'normal', 'high' );
637 pods_group_add( $pod, __( 'Pod Association', 'pods' ), $association_fields, 'normal', 'high' );
638 pods_group_add( $pod, __( 'Restrict Access', 'pods' ), $restrict_fields, 'normal', 'high' );
639 }
640
641 /**
642 * Get the fields
643 *
644 * @param null $_null
645 * @param int $post_ID
646 * @param string $meta_key
647 * @param bool $single
648 *
649 * @return array|bool|int|mixed|null|string|void
650 */
651 public function get_meta( $_null, $post_ID = null, $meta_key = null, $single = false ) {
652 if ( 'code' !== $meta_key ) {
653 return $_null;
654 }
655
656 $post = get_post( $post_ID );
657
658 if ( ! is_object( $post ) || $this->object_type !== $post->post_type ) {
659 return $_null;
660 }
661
662 return $post->post_content;
663 }
664
665 /**
666 * Save the fields
667 *
668 * @param $_null
669 * @param int $post_ID
670 * @param string $meta_key
671 * @param string $meta_value
672 *
673 * @return bool|int|null
674 */
675 public function save_meta( $_null, $post_ID = null, $meta_key = null, $meta_value = null ) {
676 if ( 'code' !== $meta_key ) {
677 return $_null;
678 }
679
680 $post = get_post( $post_ID );
681
682 if ( ! is_object( $post ) || $this->object_type !== $post->post_type ) {
683 return $_null;
684 }
685
686 $postdata = array(
687 'ID' => $post_ID,
688 'post_content' => $meta_value,
689 );
690
691 remove_filter( current_filter(), array( $this, __FUNCTION__ ) );
692
693 $revisions = false;
694
695 if ( has_action( 'pre_post_update', 'wp_save_post_revision' ) ) {
696 remove_action( 'pre_post_update', 'wp_save_post_revision' );
697
698 $revisions = true;
699 }
700
701 wp_update_post( (object) $postdata );
702
703 // objects will be automatically sanitized
704 if ( $revisions ) {
705 add_action( 'pre_post_update', 'wp_save_post_revision' );
706 }
707
708 return true;
709 }
710
711 /**
712 * Flush Pod Page Rewrite cache
713 *
714 * @return array Pod Page Rewrites
715 *
716 * @since 2.3.4
717 */
718 public static function flush_rewrites() {
719
720 $args = array(
721 'post_type' => '_pods_page',
722 'nopaging' => true,
723 'posts_per_page' => - 1,
724 'post_status' => 'publish',
725 'order' => 'ASC',
726 'orderby' => 'title',
727 );
728
729 $pod_pages = get_posts( $args );
730
731 $pod_page_rewrites = array();
732
733 foreach ( $pod_pages as $pod_page ) {
734 $pod_page_rewrites[ $pod_page->ID ] = $pod_page->post_title;
735 }
736
737 uksort( $pod_page_rewrites, 'pods_page_length_sort' );
738
739 pods_transient_set( 'pods_object_page_rewrites', $pod_page_rewrites, WEEK_IN_SECONDS );
740
741 $pod_page_rewrites = array_flip( $pod_page_rewrites );
742
743 return $pod_page_rewrites;
744 }
745
746 /**
747 * Check to see if Pod Page exists and return data
748 *
749 * $uri not required, if NULL then returns REQUEST_URI matching Pod Page
750 *
751 * @param string $uri The Pod Page URI to check if exists
752 *
753 * @return array|bool
754 */
755 public static function exists( $uri = null ) {
756 if ( null === $uri ) {
757 $uri = pods_current_path();
758 }
759
760 if ( empty( $uri ) ) {
761 return false;
762 }
763
764 $uri = explode( '?', $uri );
765 $uri = explode( '#', $uri[0] );
766 $uri = $uri[0];
767
768 $home_path = wp_parse_url( get_home_url(), PHP_URL_PATH );
769
770 if ( ! empty( $home_path ) && '/' !== $home_path ) {
771 $uri = substr( $uri, strlen( $home_path ) );
772 }
773
774 $uri = trim( $uri, '/' );
775 $uri_depth = count( array_filter( explode( '/', $uri ) ) ) - 1;
776
777 $pods_page_exclusions = array(
778 'wp-admin',
779 'wp-content',
780 'wp-includes',
781 'index.php',
782 'wp-login.php',
783 'wp-signup.php',
784 );
785
786 $pods_page_exclusions = apply_filters( 'pods_page_exclusions', $pods_page_exclusions );
787
788 if ( is_admin() || empty( $uri ) ) {
789 return false;
790 }
791
792 foreach ( $pods_page_exclusions as $exclusion ) {
793 if ( 0 === strpos( $uri, $exclusion ) ) {
794 return false;
795 }
796 }
797
798 $object = apply_filters( 'pods_page_exists', false, $uri );
799 if ( ! empty( $object ) ) {
800 return $object;
801 }
802
803 if ( false === strpos( $uri, '*' ) && ! apply_filters( 'pods_page_regex_matching', false ) ) {
804 $object = pods_by_title( $uri, ARRAY_A, '_pods_page', 'publish' );
805 }
806
807 $wildcard = false;
808
809 if ( empty( $object ) ) {
810 if ( false === strpos( $uri, '*' ) ) {
811 $object = pods_cache_get( $uri, 'pods_object_page_wildcard' );
812
813 if ( ! empty( $object ) ) {
814 return $object;
815 }
816 }
817
818 $pod_page_rewrites = pods_transient_get( 'pods_object_page_rewrites' );
819
820 if ( empty( $pod_page_rewrites ) ) {
821 $pod_page_rewrites = self::flush_rewrites();
822 } else {
823 $pod_page_rewrites = array_flip( $pod_page_rewrites );
824 }
825
826 $found_rewrite_page_id = 0;
827
828 if ( ! empty( $pod_page_rewrites ) ) {
829 foreach ( $pod_page_rewrites as $pod_page => $pod_page_id ) {
830 if ( ! apply_filters( 'pods_page_regex_matching', false ) ) {
831 if ( false === strpos( $pod_page, '*' ) ) {
832 continue;
833 }
834
835 $depth_check = strlen( $pod_page ) - strlen( str_replace( '/', '', $pod_page ) );
836
837 $pod_page = preg_quote( $pod_page, '/' );
838
839 $pod_page = str_replace( '\\*', '(.*)', $pod_page );
840
841 if ( $uri_depth == $depth_check && preg_match( '/^' . $pod_page . '$/', $uri ) ) {
842 $found_rewrite_page_id = $pod_page_id;
843
844 break;
845 }
846 } elseif ( preg_match( '/^' . str_replace( '/', '\\/', $pod_page ) . '$/', $uri ) ) {
847 $found_rewrite_page_id = $pod_page_id;
848
849 break;
850 }//end if
851 }//end foreach
852
853 if ( ! empty( $found_rewrite_page_id ) ) {
854 $object = get_post( $found_rewrite_page_id, ARRAY_A );
855
856 if ( empty( $object ) || '_pods_page' !== $object['post_type'] ) {
857 $object = false;
858 }
859 }
860 }//end if
861
862 $wildcard = true;
863 }//end if
864
865 if ( ! empty( $object ) ) {
866 $object = array(
867 'id' => $object['ID'],
868 'uri' => $object['post_title'],
869 'code' => $object['post_content'],
870 'phpcode' => $object['post_content'],
871 // phpcode is deprecated
872 'precode' => get_post_meta( $object['ID'], 'precode', true ),
873 'page_template' => get_post_meta( $object['ID'], 'page_template', true ),
874 'title' => get_post_meta( $object['ID'], 'page_title', true ),
875 'options' => array(
876 'admin_only' => (boolean) get_post_meta( $object['ID'], 'admin_only', true ),
877 'restrict_role' => (boolean) get_post_meta( $object['ID'], 'restrict_role', true ),
878 'restrict_capability' => (boolean) get_post_meta( $object['ID'], 'restrict_capability', true ),
879 'roles_allowed' => get_post_meta( $object['ID'], 'roles_allowed', true ),
880 'capability_allowed' => get_post_meta( $object['ID'], 'capability_allowed', true ),
881 'restrict_redirect' => (boolean) get_post_meta( $object['ID'], 'restrict_redirect', true ),
882 'restrict_redirect_login' => (boolean) get_post_meta( $object['ID'], 'restrict_redirect_login', true ),
883 'restrict_redirect_url' => get_post_meta( $object['ID'], 'restrict_redirect_url', true ),
884 'pod' => get_post_meta( $object['ID'], 'pod', true ),
885 'pod_slug' => get_post_meta( $object['ID'], 'pod_slug', true ),
886 ),
887 );
888
889 if ( $wildcard ) {
890 pods_cache_set( $uri, $object, 'pods_object_page_wildcard', 3600 );
891 }
892
893 return $object;
894 }//end if
895
896 return false;
897 }
898
899 /**
900 * Check if a Pod Page exists
901 */
902 public function page_check() {
903
904 if ( self::$checked ) {
905 return;
906 }
907
908 global $pods;
909
910 // Fix any global confusion wherever this runs
911 if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) {
912 $GLOBALS['pods'] =& $pods;
913 } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) {
914 $pods =& $GLOBALS['pods'];
915 }
916
917 if ( ! defined( 'PODS_DISABLE_POD_PAGE_CHECK' ) || ! PODS_DISABLE_POD_PAGE_CHECK ) {
918 if ( null === self::$exists ) {
919 self::$exists = pod_page_exists();
920 }
921
922 if ( false !== self::$exists ) {
923 $pods = apply_filters( 'pods_global', $pods, self::$exists );
924
925 if ( ! is_wp_error( $pods ) && ( is_object( $pods ) || 404 != $pods ) ) {
926 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
927 add_filter( 'redirect_canonical', '__return_false' );
928 add_action( 'wp_head', array( $this, 'wp_head' ) );
929 add_filter( 'wp_title', array( $this, 'wp_title' ), 0, 3 );
930 add_filter( 'body_class', array( $this, 'body_class' ), 0, 1 );
931 add_filter( 'status_header', array( $this, 'status_header' ) );
932 add_action( 'after_setup_theme', array( $this, 'precode' ) );
933 add_action( 'wp', array( $this, 'silence_404' ), 1 );
934
935 // Genesis theme integration.
936 add_action( 'genesis_loop', 'pods_content', 11 );
937 }
938 }
939
940 self::$checked = true;
941 }//end if
942 }
943
944 /**
945 * Output Pod Page Content
946 *
947 * @param bool $return Whether to return or not (default is to echo)
948 *
949 * @param bool $pods_page
950 *
951 * @return string
952 */
953 public static function content( $return = false, $pods_page = false ) {
954
955 if ( empty( $pods_page ) ) {
956 $pods_page = self::$exists;
957 }
958
959 $content = false;
960
961 if ( $pods_page == self::$exists && self::$content_called ) {
962 return $content;
963 }
964
965 if ( ! empty( $pods_page ) ) {
966 /**
967 * @var $pods \Pods
968 */
969 global $pods;
970
971 // Fix any global confusion wherever this runs
972 if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) {
973 $GLOBALS['pods'] =& $pods;
974 } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) {
975 $pods =& $GLOBALS['pods'];
976 }
977
978 if ( 0 < strlen( trim( $pods_page['code'] ) ) ) {
979 $content = trim( $pods_page['code'] );
980 }
981
982 ob_start();
983
984 do_action( 'pods_content_pre', $pods_page, $content );
985
986 if ( 0 < strlen( $content ) ) {
987 if ( false !== strpos( $content, '<?' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
988 pods_deprecated( 'Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' );
989
990 eval( "?>$content" );
991 } elseif ( is_object( $pods ) && ! empty( $pods->id ) ) {
992 echo $pods->do_magic_tags( $content );
993 } else {
994 echo $content;
995 }
996 }
997
998 do_action( 'pods_content_post', $pods_page, $content );
999
1000 $content = ob_get_clean();
1001
1002 if ( $pods_page == self::$exists ) {
1003 self::$content_called = true;
1004 }
1005 }//end if
1006
1007 $content = apply_filters( 'pods_content', $content, $pods_page );
1008
1009 if ( $return ) {
1010 return $content;
1011 }
1012
1013 echo $content;
1014 }
1015
1016 /**
1017 * Run any precode for current Pod Page
1018 */
1019 public function precode() {
1020
1021 global $pods;
1022
1023 // Fix any global confusion wherever this runs
1024 if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) {
1025 $GLOBALS['pods'] =& $pods;
1026 } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) {
1027 $pods =& $GLOBALS['pods'];
1028 }
1029
1030 if ( false !== self::$exists ) {
1031 $permission = pods_permission( self::$exists );
1032
1033 $permission = (boolean) apply_filters( 'pods_pages_permission', $permission, self::$exists );
1034
1035 if ( $permission ) {
1036 $content = false;
1037
1038 if ( ! is_object( $pods ) && 404 != $pods && 0 < strlen( pods_var( 'pod', self::$exists['options'] ) ) ) {
1039 $slug = pods_var_raw( 'pod_slug', self::$exists['options'], null, null, true );
1040
1041 $has_slug = 0 < strlen( $slug );
1042
1043 // Handle special magic tags
1044 if ( $has_slug ) {
1045 $slug = pods_evaluate_tags( $slug, true );
1046 }
1047
1048 $pods = pods( pods_var( 'pod', self::$exists['options'] ), $slug );
1049
1050 // Auto 404 handling if item doesn't exist
1051 if ( $has_slug && ( empty( $slug ) || ! $pods->exists() ) && apply_filters( 'pods_pages_auto_404', true, $slug, $pods, self::$exists ) ) {
1052 $pods = 404;
1053 }
1054 }
1055
1056 if ( 0 < strlen( trim( self::$exists['precode'] ) ) ) {
1057 $content = self::$exists['precode'];
1058 }
1059
1060 if ( false !== $content && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
1061 pods_deprecated( 'Pod Page Precode has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' );
1062
1063 eval( "?>$content" );
1064 }
1065
1066 do_action( 'pods_page_precode', self::$exists, $pods, $content );
1067 } elseif ( self::$exists['options']['restrict_redirect'] ) {
1068 $redirect_url = '';
1069
1070 if ( self::$exists['options']['restrict_redirect_login'] ) {
1071 $redirect_url = wp_login_url( pods_current_url() );
1072 } elseif ( ! empty( self::$exists['options']['restrict_redirect_url'] ) ) {
1073 $redirect_url = self::$exists['options']['restrict_redirect_url'];
1074 }
1075
1076 if ( ! empty( $redirect_url ) ) {
1077 wp_redirect( $redirect_url );
1078 die();
1079 }
1080 }//end if
1081
1082 if ( ! $permission || ( ! is_object( $pods ) && ( 404 == $pods || is_wp_error( $pods ) ) ) ) {
1083 remove_action( 'template_redirect', array( $this, 'template_redirect' ) );
1084 remove_action( 'wp_head', array( $this, 'wp_head' ) );
1085 remove_filter( 'redirect_canonical', '__return_false' );
1086 remove_filter( 'wp_title', array( $this, 'wp_title' ) );
1087 remove_filter( 'body_class', array( $this, 'body_class' ) );
1088 remove_filter( 'status_header', array( $this, 'status_header' ) );
1089 remove_action( 'wp', array( $this, 'silence_404' ), 1 );
1090 }
1091 }//end if
1092 }
1093
1094 /**
1095 *
1096 */
1097 public function wp_head() {
1098
1099 global $pods;
1100
1101 do_action( 'pods_wp_head' );
1102
1103 if ( ! defined( 'PODS_DISABLE_VERSION_OUTPUT' ) || ! PODS_DISABLE_VERSION_OUTPUT ) {
1104 ?>
1105 <!-- Pods Framework <?php echo esc_html( PODS_VERSION ); ?> -->
1106 <?php
1107 }
1108 if ( ( ! defined( 'PODS_DISABLE_META' ) || ! PODS_DISABLE_META ) && is_object( $pods ) && ! is_wp_error( $pods ) ) {
1109
1110 if ( isset( $pods->meta ) && is_array( $pods->meta ) && ! empty( $pods->meta ) ) {
1111 foreach ( $pods->meta as $name => $content ) {
1112 if ( 'title' === $name ) {
1113 continue;
1114 }
1115 ?>
1116 <meta name="<?php echo esc_attr( $name ); ?>" content="<?php echo esc_attr( $content ); ?>" />
1117 <?php
1118 }
1119 }
1120
1121 if ( isset( $pods->meta_properties ) && is_array( $pods->meta_properties ) && ! empty( $pods->meta_properties ) ) {
1122 foreach ( $pods->meta_properties as $property => $content ) {
1123 ?>
1124 <meta property="<?php echo esc_attr( $property ); ?>" content="<?php echo esc_attr( $content ); ?>" />
1125 <?php
1126 }
1127 }
1128
1129 if ( isset( $pods->meta_extra ) && 0 < strlen( $pods->meta_extra ) ) {
1130 echo $pods->meta_extra;
1131 }
1132 }//end if
1133 }
1134
1135 /**
1136 * @param $title
1137 * @param $sep
1138 * @param $seplocation
1139 *
1140 * @return mixed|void
1141 */
1142 public function wp_title( $title, $sep, $seplocation ) {
1143
1144 global $pods;
1145
1146 $page_title = trim( self::$exists['title'] );
1147
1148 if ( 0 < strlen( $page_title ) ) {
1149 if ( is_object( $pods ) && ! is_wp_error( $pods ) ) {
1150 $page_title = $pods->do_magic_tags( $page_title );
1151 }
1152
1153 $title = ( 'right' === $seplocation ) ? "{$page_title} {$sep} " : " {$sep} {$page_title}";
1154 } elseif ( strlen( trim( $title ) ) < 1 ) {
1155 $uri = explode( '?', $_SERVER['REQUEST_URI'] );
1156 $uri = preg_replace( '@^([/]?)(.*?)([/]?)$@', '$2', $uri[0] );
1157 $uri = preg_replace( '@(-|_)@', ' ', $uri );
1158 $uri = explode( '/', $uri );
1159
1160 $title = '';
1161
1162 foreach ( $uri as $key => $page_title ) {
1163 $title .= ( 'right' === $seplocation ) ? ucwords( $page_title ) . " {$sep} " : " {$sep} " . ucwords( $page_title );
1164 }
1165 }
1166
1167 if ( ( ! defined( 'PODS_DISABLE_META' ) || ! PODS_DISABLE_META ) && is_object( $pods ) && ! is_wp_error( $pods ) && isset( $pods->meta ) && is_array( $pods->meta ) && isset( $pods->meta['title'] ) ) {
1168 $title = $pods->meta['title'];
1169 }
1170
1171 return apply_filters( 'pods_title', $title, $sep, $seplocation, self::$exists );
1172 }
1173
1174 /**
1175 * @param $classes
1176 *
1177 * @return mixed|void
1178 */
1179 public function body_class( $classes ) {
1180
1181 global $pods;
1182
1183 if ( defined( 'PODS_DISABLE_BODY_CLASSES' ) && PODS_DISABLE_BODY_CLASSES ) {
1184 return $classes;
1185 }
1186
1187 $classes[] = 'pods';
1188
1189 $uri = explode( '?', self::$exists['uri'] );
1190 $uri = explode( '#', $uri[0] );
1191
1192 $class = str_replace( array( '*', '/' ), array( '_w_', '-' ), $uri[0] );
1193 $class = sanitize_title( $class );
1194 $class = str_replace( array( '_', '--', '--' ), '-', $class );
1195 $class = trim( $class, '-' );
1196
1197 $classes[] = 'pod-page-' . $class;
1198
1199 if ( is_object( $pods ) && ! is_wp_error( $pods ) ) {
1200 $class = sanitize_title( $pods->pod );
1201 $class = str_replace( array( '_', '--', '--' ), '-', $class );
1202 $class = trim( $class, '-' );
1203 $classes[] = 'pod-' . $class;
1204 }
1205
1206 if ( is_object( $pods ) && ! is_wp_error( $pods ) && isset( $pods->body_classes ) ) {
1207 $classes[] = $pods->body_classes;
1208 }
1209
1210 return apply_filters( 'pods_body_class', $classes, $uri );
1211 }
1212
1213 /**
1214 * @return string
1215 */
1216 public function status_header() {
1217
1218 return $_SERVER['SERVER_PROTOCOL'] . ' 200 OK';
1219 }
1220
1221 /**
1222 *
1223 */
1224 public function silence_404() {
1225
1226 global $wp_query;
1227
1228 $wp_query->query_vars['error'] = '';
1229 $wp_query->is_404 = false;
1230 }
1231
1232 /**
1233 * Handle overriding the template used for a Pods Page.
1234 *
1235 * @since 2.8.11
1236 *
1237 * @param string $original_template The template to include.
1238 *
1239 * @return string The template to include.
1240 */
1241 public function template_include( $original_template ) {
1242 global $pods;
1243
1244 // Default to original template if pod page was not found.
1245 $template = $original_template;
1246
1247 if ( false !== self::$exists ) {
1248 /*
1249 * Create pods.php in your theme directory, and
1250 * style it to suit your needs. Some helpful functions:
1251 *
1252 * get_header()
1253 * pods_content()
1254 * get_sidebar()
1255 * get_footer()
1256 */
1257 $template = self::$exists['page_template'];
1258 $template = apply_filters( 'pods_page_template', $template, self::$exists );
1259
1260 $render_function = apply_filters( 'pods_template_redirect', null, $template, self::$exists );
1261
1262 if ( '_custom' === $template ) {
1263 pods_content();
1264 die();
1265 } elseif ( null !== $render_function && is_callable( $render_function ) ) {
1266 call_user_func( $render_function, $template, self::$exists );
1267 die();
1268 } elseif ( ( ! defined( 'PODS_DISABLE_DYNAMIC_TEMPLATE' ) || ! PODS_DISABLE_DYNAMIC_TEMPLATE ) && is_object( $pods ) && ! is_wp_error( $pods ) && ! empty( $pods->page_template ) ) {
1269 $template = $pods->page_template;
1270 // found the template and included it, we're good to go!
1271 } elseif ( ! empty( self::$exists['page_template'] ) ) {
1272 $template = self::$exists['page_template'];
1273 // found the template and included it, we're good to go!
1274 } else {
1275 $located_template = apply_filters( 'pods_page_locate_template', $template, self::$exists );
1276
1277 if ( $template !== $located_template ) {
1278 $template = $located_template;
1279 } else {
1280 $default_templates = array();
1281
1282 $uri = explode( '?', self::$exists['uri'] );
1283 $uri = explode( '#', $uri[0] );
1284
1285 $page_path = explode( '/', $uri[0] );
1286
1287 while ( $last = array_pop( $page_path ) ) {
1288 $file_name = str_replace( '*', '-w-', implode( '/', $page_path ) . '/' . $last );
1289 $sanitized = sanitize_title( $file_name );
1290
1291 $default_templates[] = 'pods/' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1292 $default_templates[] = 'pods-' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1293 }
1294
1295 $default_templates[] = 'pods.php';
1296
1297 $default_templates = apply_filters( 'pods_page_default_templates', $default_templates );
1298
1299 $template = locate_template( $default_templates );
1300
1301 if ( '' !== $template ) {
1302 // found the template and included it, we're good to go!
1303 } else {
1304 $template = false;
1305
1306 // templates not found in theme, default output
1307 do_action( 'pods_page_default', $template, self::$exists );
1308
1309 get_header();
1310 pods_content();
1311 get_sidebar();
1312 get_footer();
1313 die();
1314 }
1315 }//end if
1316 }//end if
1317 }
1318
1319 /**
1320 * Allow filtering the template to include for a Pods Page.
1321 *
1322 * @since 2.8.11
1323 *
1324 * @param string $template The template to use.
1325 * @param array $exists The Pods Page data.
1326 */
1327 $template = apply_filters( 'pods_page_template_include', $template, self::$exists );
1328
1329 // Attempt to set up a basic WP post object.
1330 if ( $template !== $original_template && function_exists( '\Roots\bootloader' ) && function_exists( 'resource_path' ) ) {
1331 $paths_to_check = [
1332 get_theme_file_path( '/resources/views' ),
1333 get_parent_theme_file_path( '/resources/views' ),
1334 resource_path( 'views' ),
1335 ];
1336
1337 foreach ( $paths_to_check as $path_to_check ) {
1338 $file_path = $path_to_check . DIRECTORY_SEPARATOR . $template;
1339
1340 // The page_template comes from stored admin config; confirm the resolved file stays within an allowed theme/content path before including it, to help prevent security issues.
1341 $safe_path = pods_validate_safe_path( $file_path, [ 'theme', 'content' ] );
1342
1343 if ( $safe_path ) {
1344 $template = $safe_path;
1345
1346 break;
1347 }
1348 }
1349 }
1350
1351 return $template;
1352 }
1353
1354 /**
1355 *
1356 */
1357 public function template_redirect() {
1358 global $pods;
1359
1360 // Support the Sage theme, eventually we can implement template_include everywhere else after more testing.
1361 if ( function_exists( '\Roots\bootloader' ) ) {
1362 if ( ! empty( $pods ) && 0 < $pods->id() && 'post_type' === $pods->pod_data['type'] ) {
1363 // Set up the post object using the pod.
1364 query_posts( 'p=' . $pods->id() . '&post_type=' . $pods->pod_data['name'] );
1365
1366 $pod_post = get_post( $pods->id() );
1367
1368 if ( $pod_post ) {
1369 setup_postdata( $pod_post );
1370 }
1371 } elseif ( null === get_queried_object() ) {
1372 // Maybe set up the post using the front page for now.
1373 $front_page = (int) get_option( 'page_on_front' );
1374
1375 if ( 0 < $front_page ) {
1376 query_posts( 'page_id=' . $front_page );
1377
1378 $front_page_post = get_post( $front_page );
1379
1380 if ( $front_page_post ) {
1381 setup_postdata( $front_page_post );
1382 }
1383 }
1384 }
1385
1386 add_filter( 'template_include', [ $this, 'template_include' ] );
1387
1388 return;
1389 }
1390
1391 if ( false !== self::$exists ) {
1392 /*
1393 * Create pods.php in your theme directory, and
1394 * style it to suit your needs. Some helpful functions:
1395 *
1396 * get_header()
1397 * pods_content()
1398 * get_sidebar()
1399 * get_footer()
1400 */
1401 $template = self::$exists['page_template'];
1402 $template = apply_filters( 'pods_page_template', $template, self::$exists );
1403
1404 $render_function = apply_filters( 'pods_template_redirect', null, $template, self::$exists );
1405
1406 do_action( 'pods_page', $template, self::$exists );
1407
1408 if ( '_custom' === $template ) {
1409 pods_content();
1410 } elseif ( null !== $render_function && is_callable( $render_function ) ) {
1411 call_user_func( $render_function, $template, self::$exists );
1412 } elseif ( ( ! defined( 'PODS_DISABLE_DYNAMIC_TEMPLATE' ) || ! PODS_DISABLE_DYNAMIC_TEMPLATE ) && is_object( $pods ) && ! is_wp_error( $pods ) && isset( $pods->page_template ) && ! empty( $pods->page_template ) && '' != locate_template( array( $pods->page_template ), true ) ) {
1413 $template = $pods->page_template;
1414 // found the template and included it, we're good to go!
1415 } elseif ( ! empty( self::$exists['page_template'] ) && '' != locate_template( array( self::$exists['page_template'] ), true ) ) {
1416 $template = self::$exists['page_template'];
1417 // found the template and included it, we're good to go!
1418 } else {
1419 $located_template = apply_filters( 'pods_page_locate_template', $template, self::$exists );
1420
1421 if ( $template !== $located_template ) {
1422 $template = $located_template;
1423 } else {
1424 $default_templates = array();
1425
1426 $uri = explode( '?', self::$exists['uri'] );
1427 $uri = explode( '#', $uri[0] );
1428
1429 $page_path = explode( '/', $uri[0] );
1430
1431 while ( $last = array_pop( $page_path ) ) {
1432 $file_name = str_replace( '*', '-w-', implode( '/', $page_path ) . '/' . $last );
1433 $sanitized = sanitize_title( $file_name );
1434
1435 $default_templates[] = 'pods/' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1436 $default_templates[] = 'pods-' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1437 }
1438
1439 $default_templates[] = 'pods.php';
1440
1441 $default_templates = apply_filters( 'pods_page_default_templates', $default_templates );
1442
1443 $template = locate_template( $default_templates, true );
1444
1445 if ( '' !== $template ) {
1446 // found the template and included it, we're good to go!
1447 } else {
1448 $template = false;
1449
1450 // templates not found in theme, default output
1451 do_action( 'pods_page_default', $template, self::$exists );
1452
1453 get_header();
1454 pods_content();
1455 get_sidebar();
1456 get_footer();
1457 }
1458 }//end if
1459 }//end if
1460
1461 do_action( 'pods_page_end', $template, self::$exists );
1462
1463 exit;
1464 }//end if
1465 }
1466 }
1467
1468 /**
1469 * Find out if the current page is a Pod Page
1470 *
1471 * @param string $uri The Pod Page URI to check if currently on
1472 *
1473 * @return bool
1474 * @since 1.7.5
1475 */
1476 function is_pod_page( $uri = null ) {
1477
1478 if ( false !== Pods_Pages::$exists && ( null === $uri || $uri == Pods_Pages::$exists['uri'] || $uri == Pods_Pages::$exists['id'] ) ) {
1479 return true;
1480 }
1481
1482 return false;
1483 }
1484
1485 /**
1486 * Check for a specific page template for the current pod page
1487 *
1488 * @param string $template The theme template file
1489 *
1490 * @return bool
1491 * @since 2.3.7
1492 */
1493 function is_pod_page_template( $template = null ) {
1494
1495 if ( false !== Pods_Pages::$exists && $template == Pods_Pages::$exists['page_template'] ) {
1496 return true;
1497 }
1498
1499 return false;
1500 }
1501
1502 /**
1503 * Get the current Pod Page URI
1504 *
1505 * @return string|bool
1506 * @since 2.3.3
1507 */
1508 function get_pod_page_uri() {
1509
1510 $pod_page = Pods_Pages::exists();
1511
1512 if ( ! empty( $pod_page ) ) {
1513 return $pod_page['uri'];
1514 }
1515
1516 return false;
1517 }
1518
1519 /**
1520 * Check to see if Pod Page exists and return data
1521 *
1522 * $uri not required, if NULL then returns REQUEST_URI matching Pod Page
1523 *
1524 * @param string $uri The Pod Page URI to check if exists
1525 *
1526 * @return array
1527 *
1528 * @since 1.7.5
1529 */
1530 function pod_page_exists( $uri = null ) {
1531 return Pods_Pages::exists( $uri );
1532 }
1533
1534 /**
1535 * Output Pod Page Content
1536 *
1537 * @param bool $return Whether to return or not (default is to echo)
1538 *
1539 * @param bool $pods_page
1540 *
1541 * @return string
1542 * @since 1.7.0
1543 */
1544 function pods_content( $return = false, $pods_page = false ) {
1545
1546 return Pods_Pages::content( $return, $pods_page );
1547 }
1548
1549 /**
1550 * Sort an array by length of items, descending, for use with uksort()
1551 *
1552 * @param string $a First array item
1553 * @param string $b Second array item
1554 *
1555 * @return int Length difference
1556 *
1557 * @since 2.3.4
1558 */
1559 function pods_page_length_sort( $a, $b ) {
1560
1561 return strlen( $b ) - strlen( $a );
1562 }
1563
1564 /**
1565 * Flush Pod Page Rewrite cache
1566 *
1567 * @return array Pod Page Rewrites
1568 *
1569 * @since 2.3.4
1570 */
1571 function pods_page_flush_rewrites() {
1572
1573 return Pods_Pages::flush_rewrites();
1574 }
1575
1576 /*
1577 * Deprecated global variable
1578 */
1579 $GLOBALS['pod_page_exists'] =& Pods_Pages::$exists;
1580