PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.5
Pods – Custom Content Types and Fields v3.2.5
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 2 years ago Advanced-Content-Types.php 3 years ago Advanced-Relationships.php 3 years ago Markdown.php 2 years ago Pages.php 3 years ago Table-Storage.php 4 years ago
Pages.php
1620 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|void
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
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 ( 0 < strlen( $content ) ) {
1030 if ( false !== strpos( $content, '<?' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
1031 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' );
1032
1033 eval( "?>$content" );
1034 } elseif ( is_object( $pods ) && ! empty( $pods->id ) ) {
1035 echo $pods->do_magic_tags( $content );
1036 } else {
1037 echo $content;
1038 }
1039 }
1040
1041 do_action( 'pods_content_post', $pods_page, $content );
1042
1043 $content = ob_get_clean();
1044
1045 if ( $pods_page == self::$exists ) {
1046 self::$content_called = true;
1047 }
1048 }//end if
1049
1050 $content = apply_filters( 'pods_content', $content, $pods_page );
1051
1052 if ( $return ) {
1053 return $content;
1054 }
1055
1056 echo $content;
1057 }
1058
1059 /**
1060 * Run any precode for current Pod Page
1061 */
1062 public function precode() {
1063
1064 global $pods;
1065
1066 // Fix any global confusion wherever this runs
1067 if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) {
1068 $GLOBALS['pods'] =& $pods;
1069 } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) {
1070 $pods =& $GLOBALS['pods'];
1071 }
1072
1073 if ( false !== self::$exists ) {
1074 $permission = pods_permission( self::$exists );
1075
1076 $permission = (boolean) apply_filters( 'pods_pages_permission', $permission, self::$exists );
1077
1078 if ( $permission ) {
1079 $content = false;
1080
1081 if ( ! is_object( $pods ) && 404 != $pods && 0 < strlen( (string) pods_var( 'pod', self::$exists['options'] ) ) ) {
1082 $slug = pods_var_raw( 'pod_slug', self::$exists['options'], null, null, true );
1083
1084 $has_slug = 0 < strlen( $slug );
1085
1086 // Handle special magic tags
1087 if ( $has_slug ) {
1088 $slug = pods_evaluate_tags( $slug, true );
1089 }
1090
1091 $pods = pods_get_instance( pods_var( 'pod', self::$exists['options'] ), $slug );
1092
1093 // Auto 404 handling if item doesn't exist
1094 if ( $has_slug && ( empty( $slug ) || ! $pods->exists() ) && apply_filters( 'pods_pages_auto_404', true, $slug, $pods, self::$exists ) ) {
1095 $pods = 404;
1096 }
1097 }
1098
1099 if ( 0 < strlen( trim( self::$exists['precode'] ) ) ) {
1100 $content = self::$exists['precode'];
1101 }
1102
1103 if ( false !== $content && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
1104 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' );
1105
1106 eval( "?>$content" );
1107 }
1108
1109 do_action( 'pods_page_precode', self::$exists, $pods, $content );
1110 } elseif ( self::$exists['options']['restrict_redirect'] ) {
1111 $redirect_url = '';
1112
1113 if ( self::$exists['options']['restrict_redirect_login'] ) {
1114 $redirect_url = wp_login_url( pods_current_url() );
1115 } elseif ( ! empty( self::$exists['options']['restrict_redirect_url'] ) ) {
1116 $redirect_url = self::$exists['options']['restrict_redirect_url'];
1117 }
1118
1119 if ( ! empty( $redirect_url ) ) {
1120 wp_redirect( $redirect_url );
1121 die();
1122 }
1123 }//end if
1124
1125 if ( ! $permission || ( ! is_object( $pods ) && ( 404 == $pods || is_wp_error( $pods ) ) ) ) {
1126 remove_action( 'template_redirect', array( $this, 'template_redirect' ) );
1127 remove_action( 'wp_head', array( $this, 'wp_head' ) );
1128 remove_filter( 'redirect_canonical', '__return_false' );
1129 remove_filter( 'wp_title', array( $this, 'wp_title' ) );
1130 remove_filter( 'body_class', array( $this, 'body_class' ) );
1131 remove_filter( 'status_header', array( $this, 'status_header' ) );
1132 remove_action( 'wp', array( $this, 'silence_404' ), 1 );
1133 }
1134 }//end if
1135 }
1136
1137 /**
1138 *
1139 */
1140 public function wp_head() {
1141
1142 global $pods;
1143
1144 do_action( 'pods_wp_head' );
1145
1146 if ( ! defined( 'PODS_DISABLE_VERSION_OUTPUT' ) || ! PODS_DISABLE_VERSION_OUTPUT ) {
1147 ?>
1148 <!-- Pods Framework <?php echo esc_html( PODS_VERSION ); ?> -->
1149 <?php
1150 }
1151 if ( ( ! defined( 'PODS_DISABLE_META' ) || ! PODS_DISABLE_META ) && is_object( $pods ) && ! is_wp_error( $pods ) ) {
1152
1153 if ( isset( $pods->meta ) && is_array( $pods->meta ) && ! empty( $pods->meta ) ) {
1154 foreach ( $pods->meta as $name => $content ) {
1155 if ( 'title' === $name ) {
1156 continue;
1157 }
1158 ?>
1159 <meta name="<?php echo esc_attr( $name ); ?>" content="<?php echo esc_attr( $content ); ?>" />
1160 <?php
1161 }
1162 }
1163
1164 if ( isset( $pods->meta_properties ) && is_array( $pods->meta_properties ) && ! empty( $pods->meta_properties ) ) {
1165 foreach ( $pods->meta_properties as $property => $content ) {
1166 ?>
1167 <meta property="<?php echo esc_attr( $property ); ?>" content="<?php echo esc_attr( $content ); ?>" />
1168 <?php
1169 }
1170 }
1171
1172 if ( isset( $pods->meta_extra ) && 0 < strlen( $pods->meta_extra ) ) {
1173 echo $pods->meta_extra;
1174 }
1175 }//end if
1176 }
1177
1178 /**
1179 * @param $title
1180 * @param $sep
1181 * @param $seplocation
1182 *
1183 * @return mixed|void
1184 */
1185 public function wp_title( $title, $sep, $seplocation ) {
1186
1187 global $pods;
1188
1189 $page_title = trim( self::$exists['title'] );
1190
1191 if ( 0 < strlen( $page_title ) ) {
1192 if ( is_object( $pods ) && ! is_wp_error( $pods ) ) {
1193 $page_title = $pods->do_magic_tags( $page_title );
1194 }
1195
1196 $title = ( 'right' === $seplocation ) ? "{$page_title} {$sep} " : " {$sep} {$page_title}";
1197 } elseif ( strlen( trim( $title ) ) < 1 ) {
1198 $uri = explode( '?', $_SERVER['REQUEST_URI'] );
1199 $uri = preg_replace( '@^([/]?)(.*?)([/]?)$@', '$2', $uri[0] );
1200 $uri = preg_replace( '@(-|_)@', ' ', $uri );
1201 $uri = explode( '/', $uri );
1202
1203 $title = '';
1204
1205 foreach ( $uri as $key => $page_title ) {
1206 $title .= ( 'right' === $seplocation ) ? ucwords( $page_title ) . " {$sep} " : " {$sep} " . ucwords( $page_title );
1207 }
1208 }
1209
1210 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'] ) ) {
1211 $title = $pods->meta['title'];
1212 }
1213
1214 return apply_filters( 'pods_title', $title, $sep, $seplocation, self::$exists );
1215 }
1216
1217 /**
1218 * @param $classes
1219 *
1220 * @return mixed|void
1221 */
1222 public function body_class( $classes ) {
1223
1224 global $pods;
1225
1226 if ( defined( 'PODS_DISABLE_BODY_CLASSES' ) && PODS_DISABLE_BODY_CLASSES ) {
1227 return $classes;
1228 }
1229
1230 $classes[] = 'pods';
1231
1232 $uri = explode( '?', self::$exists['uri'] );
1233 $uri = explode( '#', $uri[0] );
1234
1235 $class = str_replace( array( '*', '/' ), array( '_w_', '-' ), $uri[0] );
1236 $class = sanitize_title( $class );
1237 $class = str_replace( array( '_', '--', '--' ), '-', $class );
1238 $class = trim( $class, '-' );
1239
1240 $classes[] = 'pod-page-' . $class;
1241
1242 if ( is_object( $pods ) && ! is_wp_error( $pods ) ) {
1243 $class = sanitize_title( $pods->pod );
1244 $class = str_replace( array( '_', '--', '--' ), '-', $class );
1245 $class = trim( $class, '-' );
1246 $classes[] = 'pod-' . $class;
1247 }
1248
1249 if ( is_object( $pods ) && ! is_wp_error( $pods ) && isset( $pods->body_classes ) ) {
1250 $classes[] = $pods->body_classes;
1251 }
1252
1253 return apply_filters( 'pods_body_class', $classes, $uri );
1254 }
1255
1256 /**
1257 * @return string
1258 */
1259 public function status_header() {
1260
1261 return $_SERVER['SERVER_PROTOCOL'] . ' 200 OK';
1262 }
1263
1264 /**
1265 *
1266 */
1267 public function silence_404() {
1268
1269 global $wp_query;
1270
1271 $wp_query->query_vars['error'] = '';
1272 $wp_query->is_404 = false;
1273 }
1274
1275 /**
1276 * Handle overriding the template used for a Pods Page.
1277 *
1278 * @since 2.8.11
1279 *
1280 * @param string $original_template The template to include.
1281 *
1282 * @return string The template to include.
1283 */
1284 public function template_include( $original_template ) {
1285 global $pods;
1286
1287 // Default to original template if pod page was not found.
1288 $template = $original_template;
1289
1290 if ( false !== self::$exists ) {
1291 /*
1292 * Create pods.php in your theme directory, and
1293 * style it to suit your needs. Some helpful functions:
1294 *
1295 * get_header()
1296 * pods_content()
1297 * get_sidebar()
1298 * get_footer()
1299 */
1300 $template = self::$exists['page_template'];
1301 $template = apply_filters( 'pods_page_template', $template, self::$exists );
1302
1303 $render_function = apply_filters( 'pods_template_redirect', null, $template, self::$exists );
1304
1305 if ( '_custom' === $template ) {
1306 pods_content();
1307 die();
1308 } elseif ( null !== $render_function && is_callable( $render_function ) ) {
1309 call_user_func( $render_function, $template, self::$exists );
1310 die();
1311 } elseif ( ( ! defined( 'PODS_DISABLE_DYNAMIC_TEMPLATE' ) || ! PODS_DISABLE_DYNAMIC_TEMPLATE ) && is_object( $pods ) && ! is_wp_error( $pods ) && ! empty( $pods->page_template ) ) {
1312 $template = $pods->page_template;
1313 // found the template and included it, we're good to go!
1314 } elseif ( ! empty( self::$exists['page_template'] ) ) {
1315 $template = self::$exists['page_template'];
1316 // found the template and included it, we're good to go!
1317 } else {
1318 $located_template = apply_filters( 'pods_page_locate_template', $template, self::$exists );
1319
1320 if ( $template !== $located_template ) {
1321 $template = $located_template;
1322 } else {
1323 $default_templates = array();
1324
1325 $uri = explode( '?', self::$exists['uri'] );
1326 $uri = explode( '#', $uri[0] );
1327
1328 $page_path = explode( '/', $uri[0] );
1329
1330 while ( $last = array_pop( $page_path ) ) {
1331 $file_name = str_replace( '*', '-w-', implode( '/', $page_path ) . '/' . $last );
1332 $sanitized = sanitize_title( $file_name );
1333
1334 $default_templates[] = 'pods/' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1335 $default_templates[] = 'pods-' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1336 }
1337
1338 $default_templates[] = 'pods.php';
1339
1340 $default_templates = apply_filters( 'pods_page_default_templates', $default_templates );
1341
1342 $template = locate_template( $default_templates );
1343
1344 if ( '' !== $template ) {
1345 // found the template and included it, we're good to go!
1346 } else {
1347 $template = false;
1348
1349 // templates not found in theme, default output
1350 do_action( 'pods_page_default', $template, self::$exists );
1351
1352 get_header();
1353 pods_content();
1354 get_sidebar();
1355 get_footer();
1356 die();
1357 }
1358 }//end if
1359 }//end if
1360 }
1361
1362 /**
1363 * Allow filtering the template to include for a Pods Page.
1364 *
1365 * @since 2.8.11
1366 *
1367 * @param string $template The template to use.
1368 * @param array $exists The Pods Page data.
1369 */
1370 $template = apply_filters( 'pods_page_template_include', $template, self::$exists );
1371
1372 // Attempt to set up a basic WP post object.
1373 if ( $template !== $original_template && function_exists( '\Roots\bootloader' ) && function_exists( 'resource_path' ) ) {
1374 $paths_to_check = [
1375 get_theme_file_path( '/resources/views' ),
1376 get_parent_theme_file_path( '/resources/views' ),
1377 resource_path( 'views' ),
1378 ];
1379
1380 foreach ( $paths_to_check as $path_to_check ) {
1381 $file_path = $path_to_check . DIRECTORY_SEPARATOR . $template;
1382
1383 if ( file_exists( $file_path ) ) {
1384 $template = $file_path;
1385
1386 break;
1387 }
1388 }
1389 }
1390
1391 return $template;
1392 }
1393
1394 /**
1395 *
1396 */
1397 public function template_redirect() {
1398 global $pods;
1399
1400 // Support the Sage theme, eventually we can implement template_include everywhere else after more testing.
1401 if ( function_exists( '\Roots\bootloader' ) ) {
1402 if ( ! empty( $pods ) && 0 < $pods->id() && 'post_type' === $pods->pod_data['type'] ) {
1403 // Set up the post object using the pod.
1404 query_posts( 'p=' . $pods->id() . '&post_type=' . $pods->pod_data['name'] );
1405
1406 $pod_post = get_post( $pods->id() );
1407
1408 if ( $pod_post ) {
1409 setup_postdata( $pod_post );
1410 }
1411 } elseif ( null === get_queried_object() ) {
1412 // Maybe set up the post using the front page for now.
1413 $front_page = (int) get_option( 'page_on_front' );
1414
1415 if ( 0 < $front_page ) {
1416 query_posts( 'page_id=' . $front_page );
1417
1418 $front_page_post = get_post( $front_page );
1419
1420 if ( $front_page_post ) {
1421 setup_postdata( $front_page_post );
1422 }
1423 }
1424 }
1425
1426 add_filter( 'template_include', [ $this, 'template_include' ] );
1427
1428 return;
1429 }
1430
1431 if ( false !== self::$exists ) {
1432 /*
1433 * Create pods.php in your theme directory, and
1434 * style it to suit your needs. Some helpful functions:
1435 *
1436 * get_header()
1437 * pods_content()
1438 * get_sidebar()
1439 * get_footer()
1440 */
1441 $template = self::$exists['page_template'];
1442 $template = apply_filters( 'pods_page_template', $template, self::$exists );
1443
1444 $render_function = apply_filters( 'pods_template_redirect', null, $template, self::$exists );
1445
1446 do_action( 'pods_page', $template, self::$exists );
1447
1448 if ( '_custom' === $template ) {
1449 pods_content();
1450 } elseif ( null !== $render_function && is_callable( $render_function ) ) {
1451 call_user_func( $render_function, $template, self::$exists );
1452 } 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 ) ) {
1453 $template = $pods->page_template;
1454 // found the template and included it, we're good to go!
1455 } elseif ( ! empty( self::$exists['page_template'] ) && '' != locate_template( array( self::$exists['page_template'] ), true ) ) {
1456 $template = self::$exists['page_template'];
1457 // found the template and included it, we're good to go!
1458 } else {
1459 $located_template = apply_filters( 'pods_page_locate_template', $template, self::$exists );
1460
1461 if ( $template !== $located_template ) {
1462 $template = $located_template;
1463 } else {
1464 $default_templates = array();
1465
1466 $uri = explode( '?', self::$exists['uri'] );
1467 $uri = explode( '#', $uri[0] );
1468
1469 $page_path = explode( '/', $uri[0] );
1470
1471 while ( $last = array_pop( $page_path ) ) {
1472 $file_name = str_replace( '*', '-w-', implode( '/', $page_path ) . '/' . $last );
1473 $sanitized = sanitize_title( $file_name );
1474
1475 $default_templates[] = 'pods/' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1476 $default_templates[] = 'pods-' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php';
1477 }
1478
1479 $default_templates[] = 'pods.php';
1480
1481 $default_templates = apply_filters( 'pods_page_default_templates', $default_templates );
1482
1483 $template = locate_template( $default_templates, true );
1484
1485 if ( '' !== $template ) {
1486 // found the template and included it, we're good to go!
1487 } else {
1488 $template = false;
1489
1490 // templates not found in theme, default output
1491 do_action( 'pods_page_default', $template, self::$exists );
1492
1493 get_header();
1494 pods_content();
1495 get_sidebar();
1496 get_footer();
1497 }
1498 }//end if
1499 }//end if
1500
1501 do_action( 'pods_page_end', $template, self::$exists );
1502
1503 exit;
1504 }//end if
1505 }
1506 }
1507
1508 /**
1509 * Find out if the current page is a Pod Page
1510 *
1511 * @param string $uri The Pod Page URI to check if currently on
1512 *
1513 * @return bool
1514 * @since 1.7.5
1515 */
1516 function is_pod_page( $uri = null ) {
1517
1518 if ( false !== Pods_Pages::$exists && ( null === $uri || $uri == Pods_Pages::$exists['uri'] || $uri == Pods_Pages::$exists['id'] ) ) {
1519 return true;
1520 }
1521
1522 return false;
1523 }
1524
1525 /**
1526 * Check for a specific page template for the current pod page
1527 *
1528 * @param string $template The theme template file
1529 *
1530 * @return bool
1531 * @since 2.3.7
1532 */
1533 function is_pod_page_template( $template = null ) {
1534
1535 if ( false !== Pods_Pages::$exists && $template == Pods_Pages::$exists['page_template'] ) {
1536 return true;
1537 }
1538
1539 return false;
1540 }
1541
1542 /**
1543 * Get the current Pod Page URI
1544 *
1545 * @return string|bool
1546 * @since 2.3.3
1547 */
1548 function get_pod_page_uri() {
1549
1550 $pod_page = Pods_Pages::exists();
1551
1552 if ( ! empty( $pod_page ) ) {
1553 return $pod_page['uri'];
1554 }
1555
1556 return false;
1557 }
1558
1559 /**
1560 * Check to see if Pod Page exists and return data
1561 *
1562 * $uri not required, if NULL then returns REQUEST_URI matching Pod Page
1563 *
1564 * @param string $uri The Pod Page URI to check if exists
1565 *
1566 * @return array
1567 *
1568 * @since 1.7.5
1569 */
1570 function pod_page_exists( $uri = null ) {
1571 return Pods_Pages::exists( $uri );
1572 }
1573
1574 /**
1575 * Output Pod Page Content
1576 *
1577 * @param bool $return Whether to return or not (default is to echo)
1578 *
1579 * @param bool $pods_page
1580 *
1581 * @return string
1582 * @since 1.7.0
1583 */
1584 function pods_content( $return = false, $pods_page = false ) {
1585
1586 return Pods_Pages::content( $return, $pods_page );
1587 }
1588
1589 /**
1590 * Sort an array by length of items, descending, for use with uksort()
1591 *
1592 * @param string $a First array item
1593 * @param string $b Second array item
1594 *
1595 * @return int Length difference
1596 *
1597 * @since 2.3.4
1598 */
1599 function pods_page_length_sort( $a, $b ) {
1600
1601 return strlen( $b ) - strlen( $a );
1602 }
1603
1604 /**
1605 * Flush Pod Page Rewrite cache
1606 *
1607 * @return array Pod Page Rewrites
1608 *
1609 * @since 2.3.4
1610 */
1611 function pods_page_flush_rewrites() {
1612
1613 return Pods_Pages::flush_rewrites();
1614 }
1615
1616 /*
1617 * Deprecated global variable
1618 */
1619 $GLOBALS['pod_page_exists'] =& Pods_Pages::$exists;
1620