← All changes
|
includes/request/class-charitable-request.php
+113
-29
1.7.0.11
→
1.8.13
View file →
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Class used to provide information about the current request. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Request |
| 6 | 6 | * @author David Bisset |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @since 1.0.0 |
| 10 | 10 | * @version 1.6.58 |
| 11 | 11 | */ |
| @@ -45,8 +45,15 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | private $original_campaign; |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | + * Original campaign ID. | |
| 50 | + * | |
| 51 | + * @var int | |
| 52 | + */ | |
| 53 | + private $original_campaign_id; | |
| 54 | + | |
| 55 | + /** | |
| 49 | 56 | * Campaign ID. |
| 50 | 57 | * |
| 51 | 58 | * @var int |
| 52 | 59 | */ |
| @@ -165,8 +172,76 @@ | ||
| 165 | 172 | return $this->campaign_id; |
| 166 | 173 | } |
| 167 | 174 | |
| 168 | 175 | /** |
| 176 | + * Returns the current campaign template. If there is no current template (like with legacy 1.x campaigns), return 0. | |
| 177 | + * | |
| 178 | + * @since 1.8.0 | |
| 179 | + * | |
| 180 | + * @global WP_Query $wp_query | |
| 181 | + * | |
| 182 | + * @return string | |
| 183 | + */ | |
| 184 | + public function get_current_campaign_template() { | |
| 185 | + | |
| 186 | + $campaign_settings = get_post_meta( $this->get_current_campaign_id(), 'campaign_settings_v2', true ); | |
| 187 | + | |
| 188 | + if ( false === $campaign_settings ) { // This is a legacy campaign. Probably. | |
| 189 | + return false; | |
| 190 | + } | |
| 191 | + | |
| 192 | + $campaign_template_id = ! empty( $campaign_settings['template_id'] ) ? esc_attr( $campaign_settings['template_id'] ) : false; | |
| 193 | + | |
| 194 | + $templates_data = get_option( 'charitable_campaign_builder_templates' ); | |
| 195 | + // if false, then the template data was not stored and we will need to get it manually. | |
| 196 | + if ( false === $templates_data ) { | |
| 197 | + require_once charitable()->get_path( 'includes' ) . 'admin/campaign-builder/templates/class-templates.php'; | |
| 198 | + $builder_template = new Charitable_Campaign_Builder_Templates(); | |
| 199 | + $templates_data = $builder_template->get_templates_data( $campaign_template_id, $campaign_settings ); | |
| 200 | + } | |
| 201 | + | |
| 202 | + $template_data = ! empty( $templates_data['templates'][ $campaign_template_id ] ) ? $templates_data['templates'][ $campaign_template_id ] : false; | |
| 203 | + | |
| 204 | + return $template_data; | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Returns the current campaign template. If there is no current template (like with legacy 1.x campaigns), return 0. | |
| 209 | + * | |
| 210 | + * @since 1.8.0 | |
| 211 | + * | |
| 212 | + * @global WP_Query $wp_query | |
| 213 | + * | |
| 214 | + * @return string | |
| 215 | + */ | |
| 216 | + public function get_current_campaign_template_id() { | |
| 217 | + | |
| 218 | + $campaign_settings = get_post_meta( $this->get_current_campaign_id(), 'campaign_settings_v2', true ); | |
| 219 | + $campaign_template_id = ! empty( $campaign_settings['template_id'] ) ? esc_attr( $campaign_settings['template_id'] ) : false; | |
| 220 | + | |
| 221 | + return $campaign_template_id; | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * Returns the current campaign template. If there is no current template (like with legacy 1.x campaigns), return 0. | |
| 226 | + * | |
| 227 | + * @since 1.8.0 | |
| 228 | + * | |
| 229 | + * @global WP_Query $wp_query | |
| 230 | + * | |
| 231 | + * @return string | |
| 232 | + */ | |
| 233 | + public function get_current_campaign_builder_data() { | |
| 234 | + global $wp_query; | |
| 235 | + | |
| 236 | + $campaign_settings = get_post_meta( $this->get_current_campaign_id(), 'campaign_settings_v2', true ); | |
| 237 | + | |
| 238 | + return $campaign_settings; | |
| 239 | + } | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + /** | |
| 169 | 244 | * Returns the campaign ID from a form submission. |
| 170 | 245 | * |
| 171 | 246 | * @since 1.0.0 |
| 172 | 247 | * |
| @@ -172,13 +247,15 @@ | ||
| 172 | 247 | * |
| 173 | 248 | * @return int |
| 174 | 249 | */ |
| 175 | 250 | public function get_campaign_id_from_submission() { |
| 251 | + // phpcs:disable WordPress.Security.NonceVerification.Missing | |
| 176 | 252 | if ( ! isset( $_POST['campaign_id'] ) ) { |
| 177 | 253 | return 0; |
| 178 | 254 | } |
| 179 | 255 | |
| 180 | - $campaign_id = absint( $_POST['campaign_id'] ); | |
| 256 | + $campaign_id = absint( sanitize_text_field( wp_unslash( $_POST['campaign_id'] ) ) ); | |
| 257 | + // phpcs:enable WordPress.Security.NonceVerification.Missing | |
| 181 | 258 | |
| 182 | 259 | if ( Charitable::CAMPAIGN_POST_TYPE !== get_post_type( $campaign_id ) ) { |
| 183 | 260 | return 0; |
| 184 | 261 | } |
| @@ -201,40 +278,47 @@ | ||
| 201 | 278 | |
| 202 | 279 | return $this->donation; |
| 203 | 280 | } |
| 204 | 281 | |
| 205 | - /** | |
| 206 | - * Returns the current donation ID. If there is no current donation, return 0. | |
| 207 | - * | |
| 208 | - * @since 1.0.0 | |
| 209 | - * | |
| 210 | - * @return int | |
| 211 | - */ | |
| 212 | - public function get_current_donation_id() { | |
| 213 | - $donation_id = get_query_var( 'donation_id', 0 ); | |
| 282 | + /** | |
| 283 | + * Returns the current donation ID. If there is no current donation, return 0. | |
| 284 | + * | |
| 285 | + * @since 1.0.0 | |
| 286 | + * @version 1.8.9.1 | |
| 287 | + * | |
| 288 | + * @return int | |
| 289 | + */ | |
| 290 | + public function get_current_donation_id() { | |
| 291 | + $donation_id = get_query_var( 'donation_id', 0 ); | |
| 214 | 292 | |
| 215 | - if ( ! $donation_id && isset( $_GET['donation_id'] ) ) { | |
| 216 | - $donation_id = $_GET['donation_id']; | |
| 217 | - } | |
| 293 | + // phpcs:disable WordPress.Security.NonceVerification.Recommended | |
| 294 | + if ( ! $donation_id && isset( $_GET['donation_id'] ) ) { | |
| 295 | + $donation_id = absint( sanitize_text_field( wp_unslash( $_GET['donation_id'] ) ) ); | |
| 296 | + } | |
| 297 | + // phpcs:enable WordPress.Security.NonceVerification.Recommended | |
| 218 | 298 | |
| 219 | - return $donation_id; | |
| 220 | - } | |
| 299 | + return $donation_id; | |
| 300 | + } | |
| 221 | 301 | |
| 222 | - /** | |
| 223 | - * If set, add supported donation parameters to the session. | |
| 224 | - * | |
| 225 | - * @since 1.6.25 | |
| 226 | - * | |
| 227 | - * @param int $campaign_id The campaign receiving the donation. | |
| 228 | - * @return void | |
| 229 | - */ | |
| 230 | - public function add_donation_params_to_session( $campaign_id ) { | |
| 231 | - if ( array_key_exists( 'amount', $_REQUEST ) ) { | |
| 232 | - $period = array_key_exists( 'period', $_REQUEST ) ? $_REQUEST['period'] : 'once'; | |
| 302 | + /** | |
| 303 | + * If set, add supported donation parameters to the session. | |
| 304 | + * | |
| 305 | + * @since 1.6.25 | |
| 306 | + * @version 1.8.9.1 | |
| 307 | + * | |
| 308 | + * @param int $campaign_id The campaign receiving the donation. | |
| 309 | + * @return void | |
| 310 | + */ | |
| 311 | + public function add_donation_params_to_session( $campaign_id ) { | |
| 312 | + // phpcs:disable WordPress.Security.NonceVerification.Recommended | |
| 313 | + if ( array_key_exists( 'amount', $_REQUEST ) ) { | |
| 314 | + $amount = sanitize_text_field( wp_unslash( $_REQUEST['amount'] ) ); | |
| 315 | + $period = array_key_exists( 'period', $_REQUEST ) ? sanitize_text_field( wp_unslash( $_REQUEST['period'] ) ) : 'once'; | |
| 233 | 316 | |
| 234 | - charitable_get_session()->add_donation( $campaign_id, $_REQUEST['amount'], $period ); | |
| 235 | - } | |
| 317 | + charitable_get_session()->add_donation( $campaign_id, $amount, $period ); | |
| 236 | 318 | } |
| 319 | + // phpcs:enable WordPress.Security.NonceVerification.Recommended | |
| 320 | + } | |
| 237 | 321 | |
| 238 | 322 | /** |
| 239 | 323 | * Temporarily set the current campaign to the one for the donation form. |
| 240 | 324 | * |