PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.6
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.6
1.8.13.1 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 All 212 releases
charitable / includes / endpoints / class-charitable-campaign-endpoint.php

class-charitable-campaign-endpoint.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.6, at includes/endpoints/class-charitable-campaign-endpoint.php

175 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Campaign endpoint.
4 *
5 * @package Charitable/Classes/Charitable_Campaign_Endpoint
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.5.0
10 * @version 1.6.55
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Campaign_Endpoint' ) ) :
18
19 /**
20 * Charitable_Campaign_Endpoint
21 *
22 * @since 1.5.0
23 */
24 class Charitable_Campaign_Endpoint extends Charitable_Endpoint {
25
26 /** Endpoint ID. */
27 const ID = 'campaign';
28
29 /**
30 * Endpoint class constructor.
31 *
32 * @since 1.6.36
33 */
34 public function __construct() {
35 $this->comments_disabled = false;
36 }
37
38 /**
39 * Return the endpoint ID.
40 *
41 * @since 1.5.0
42 *
43 * @return string
44 */
45 public static function get_endpoint_id() {
46 return self::ID;
47 }
48
49 /**
50 * Return the endpoint URL.
51 *
52 * @since 1.5.0
53 *
54 * @global WP_Rewrite $wp_rewrite
55 * @param array $args Mixed args.
56 * @return string
57 */
58 public function get_page_url( $args = array() ) {
59 $campaign_id = array_key_exists( 'campaign_id', $args ) ? $args['campaign_id'] : get_the_ID();
60
61 return get_permalink( $campaign_id );
62 }
63
64 /**
65 * Return whether we are currently viewing the endpoint.
66 *
67 * @since 1.5.0
68 *
69 * @global WP_Query $wp_query
70 * @param array $args Mixed arguments.
71 * @return boolean
72 */
73 public function is_page( $args = array() ) {
74 global $wp_query;
75
76 if ( is_null( $wp_query->get_queried_object() ) ) {
77 return false;
78 }
79
80 if ( ! $wp_query->is_singular( Charitable::CAMPAIGN_POST_TYPE ) ) {
81 return false;
82 }
83
84 return ! array_key_exists( 'donate', $wp_query->query_vars );
85 }
86
87 /**
88 * Prepare the template.
89 *
90 * @since 1.6.55
91 *
92 * @return void
93 */
94 public function setup_template() {
95 $donation_id = get_query_var( 'donation_id', false );
96
97 /* If a donation ID is included, make sure it belongs to the current user. */
98 if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) {
99 wp_safe_redirect( charitable_get_permalink( 'campaign_donation' ) );
100 exit();
101 }
102 }
103
104 /**
105 * Get the content to display for the endpoint.
106 *
107 * @since 1.5.0
108 *
109 * @param string $content Default content.
110 * @return string
111 */
112 public function get_content( $content ) {
113 if ( ! charitable_is_main_loop() ) {
114 return $content;
115 }
116
117 /**
118 * If this is the donation form, and it's showing on a separate page, return the content.
119 */
120 if ( charitable_is_page( 'campaign_donation_page' ) ) {
121 if ( 'separate_page' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
122 return $content;
123 }
124
125 if ( false !== get_query_var( 'donate', false ) ) {
126 return $content;
127 }
128 }
129
130 /**
131 * If you do not want to use the default campaign template, use this filter and return false.
132 *
133 * @uses charitable_use_campaign_template
134 */
135 if ( ! apply_filters( 'charitable_use_campaign_template', true ) ) {
136 return $content;
137 }
138
139 /**
140 * Remove ourselves as a filter to prevent eternal recursion if apply_filters( 'the_content' )
141 * is called by one of the templates.
142 */
143 remove_filter( 'the_content', array( charitable()->endpoints(), 'get_content' ) );
144
145 ob_start();
146
147 charitable_template(
148 'content-campaign.php',
149 array(
150 'content' => $content,
151 'campaign' => charitable_get_current_campaign(),
152 )
153 );
154
155 $content = ob_get_clean();
156
157 add_filter( 'the_content', array( charitable()->endpoints(), 'get_content' ) );
158
159 return $content;
160 }
161
162 /**
163 * Return the body class to add for the endpoint.
164 *
165 * @since 1.5.0
166 *
167 * @return string
168 */
169 public function get_body_class() {
170 return 'campaign-donation-page';
171 }
172 }
173
174 endif;
175