PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.8
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.8
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / public / class-charitable-ghost-page.php

class-charitable-ghost-page.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.8, at includes/public/class-charitable-ghost-page.php

159 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file contains the class in charge of our ghost posts.
4 *
5 * This is based on the IT_Exchange_Casper class in iThemes Exchange.
6 *
7 * @version 1.0.0
8 * @package Charitable/Classes/Charitable_Ghost_Page
9 * @author Eric Daams
10 * @copyright Copyright (c) 2019, Studio 164a
11 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
12 */
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) { exit; }
16
17 if ( ! class_exists( 'Charitable_Ghost_Page' ) ) :
18
19 /**
20 * Charitable_Ghost_Page class.
21 *
22 * It is used when viewing a frontend Charitable view other than a campaign.
23 *
24 * @since 1.0.0
25 */
26 class Charitable_Ghost_Page {
27
28 /**
29 * @var string $current_view The current Charitable frontend view. Should never be campaign.
30 * @since 1.0.0
31 */
32 private $current_view;
33
34 /**
35 * @var array $args
36 * @since 1.0.0
37 */
38 private $args;
39
40 /**
41 * @var WP_Query $wp_query
42 * @since 1.0.0
43 */
44 private $wp_query;
45
46 /**
47 * Constructor. Sets $current_view and $wp_query properties.
48 *
49 * @since 1.0.0
50 *
51 * @param string $current_view
52 * @param array $args
53 */
54 public function __construct( $current_view, $args = array() ) {
55 if ( 'campaign' == $current_view ) {
56 throw new Exception( 'Charitable_Ghost_Page should not be constructed when $current_view is "campaign".' );
57 }
58
59 $this->current_view = $current_view;
60
61 $defaults = array(
62 'title' => '',
63 'content' => ''
64 );
65
66 $this->args = wp_parse_args( $args, $defaults );
67 $this->modify_wp_query();
68
69 /* Remove wpautop filter on Ghost pages */
70 remove_filter( 'the_content', 'wpautop' );
71 }
72
73 /**
74 * Modifies the WP Query.
75 *
76 * @since 1.0.0
77 *
78 * @return void
79 */
80 private function modify_wp_query() {
81 $wp_query = $GLOBALS['wp_query'];
82
83 $wp_query->posts_per_page = 1;
84 $wp_query->nopaging = true;
85 $wp_query->post_count = 1;
86
87 // If we don't have a post, load an empty one
88 if ( empty( $wp_query->post ) ) {
89 $wp_query->post = new WP_Post( new stdClass() );
90 }
91
92 $wp_query->post->ID = 0;
93 $wp_query->post->post_date = current_time( 'mysql' );
94 $wp_query->post->post_date_gmt = current_time( 'mysql', 1 );
95 $wp_query->post->post_content = $this->args[ 'content' ];
96 $wp_query->post->post_title = $this->args[ 'title' ];
97 $wp_query->post->post_excerpt = '';
98 $wp_query->post->post_status = 'publish';
99 $wp_query->post->comment_status = false;
100 $wp_query->post->ping_status = false;
101 $wp_query->post->post_password = '';
102 $wp_query->post->post_name = 'charitable-ghost-' . $this->current_view;
103 $wp_query->post->to_ping = '';
104 $wp_query->post->pinged = '';
105 $wp_query->post->post_modified = $wp_query->post->post_date;
106 $wp_query->post->post_modified_gmt = $wp_query->post->post_date_gmt;
107 $wp_query->post->post_content_filtered = '';
108 $wp_query->post->post_parent = 0;
109 $wp_query->post->guid = get_home_url() . '/' . $this->get_guid();
110 $wp_query->post->menu_order = 0;
111 $wp_query->post->post_type = 'page';
112 $wp_query->post->post_mime_type = '';
113 $wp_query->post->comment_count = 0;
114 $wp_query->post->filter = 'raw';
115
116 $wp_query->posts = array( $wp_query->post );
117 $wp_query->found_posts = 1;
118 $wp_query->is_single = false; //false -- so comments_template() doesn't add comments
119 $wp_query->is_preview = false;
120 $wp_query->is_page = false; //false -- so comments_template() doesn't add comments
121 $wp_query->is_archive = false;
122 $wp_query->is_date = false;
123 $wp_query->is_year = false;
124 $wp_query->is_month = false;
125 $wp_query->is_day = false;
126 $wp_query->is_time = false;
127 $wp_query->is_author = false;
128 $wp_query->is_category = false;
129 $wp_query->is_tag = false;
130 $wp_query->is_tax = false;
131 $wp_query->is_search = false;
132 $wp_query->is_feed = false;
133 $wp_query->is_comment_feed = false;
134 $wp_query->is_trackback = false;
135 $wp_query->is_home = false;
136 $wp_query->is_404 = false;
137 $wp_query->is_comments_popup = false;
138 $wp_query->is_paged = false;
139 $wp_query->is_admin = false;
140 $wp_query->is_attachment = false;
141 $wp_query->is_singular = false;
142 $wp_query->is_posts_page = false;
143 $wp_query->is_post_type_archive = false;
144
145 $GLOBALS['wp_query'] = $wp_query;
146 }
147
148 /**
149 * Creates a guid based on the current view.
150 *
151 * @since 1.0.0
152 *
153 * @return string
154 */
155 private function get_guid() {
156 }
157 }
158
159 endif;