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