PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.7
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 / forms / class-charitable-donation-amount-form.php

class-charitable-donation-amount-form.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.7, at includes/forms/class-charitable-donation-amount-form.php

173 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Donation amount form model class.
4 *
5 * @package Charitable/Classes/Charitable_Donation_Amount_Form
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.0.0
10 * @version 1.5.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Donation_Amount_Form' ) ) :
19
20 /**
21 * Charitable_Donation_Amount_Form
22 *
23 * @since 1.0.0
24 */
25 class Charitable_Donation_Amount_Form extends Charitable_Donation_Form implements Charitable_Donation_Form_Interface {
26
27 /**
28 * @var Charitable_Campaign
29 */
30 protected $campaign;
31
32 /**
33 * @var array
34 */
35 protected $form_fields;
36
37 /**
38 * @var string
39 */
40 protected $nonce_action = 'charitable_donation_amount';
41
42 /**
43 * @var string
44 */
45 protected $nonce_name = '_charitable_donation_amount_nonce';
46
47 /**
48 * Action to be executed upon form submission.
49 *
50 * @var string
51 */
52 protected $form_action = 'make_donation_streamlined';
53
54 /**
55 * Return the donation form fields.
56 *
57 * @since 1.0.0
58 *
59 * @return array[]
60 */
61 public function get_fields() {
62 return $this->get_donation_fields();
63 }
64
65 /**
66 * Validate the form submission.
67 *
68 * @since 1.4.4
69 *
70 * @return boolean
71 */
72 public function validate_submission() {
73 /* If we have already validated the submission, return the value. */
74 if ( $this->validated ) {
75 return $this->valid;
76 }
77
78 $this->validated = true;
79
80 $this->valid = $this->validate_security_check()
81 && $this->check_required_fields( $this->get_merged_fields() )
82 && $this->validate_amount();
83
84 $this->valid = apply_filters( 'charitable_validate_donation_amount_form_submission', $this->valid, $this );
85
86 return $this->valid;
87 }
88
89 /**
90 * Return the donation values.
91 *
92 * @since 1.0.0
93 *
94 * @return array
95 */
96 public function get_donation_values() {
97 $submitted = $this->get_submitted_values();
98
99 $values = array(
100 'campaign_id' => $submitted['campaign_id'],
101 'amount' => self::get_donation_amount( $submitted ),
102 );
103
104 /**
105 * Filter the donation widget form submission amount.
106 *
107 * @since 1.0.0
108 *
109 * @param array $values The donation values, including a campaign_id and amount.
110 * @param array $submitted All the submitted values.
111 * @param Charitable_Donation_Amount_Form $form The form object.
112 */
113 return apply_filters( 'charitable_donation_amount_form_submission_values', $values, $submitted, $this );
114 }
115
116 /**
117 * Redirect to payment form after submission.
118 *
119 * @since 1.0.0
120 *
121 * @param int $campaign_id The campaign we are donating to.
122 * @param int $amount The donation amount.
123 * @return void
124 */
125 public function redirect_after_submission( $campaign_id, $amount ) {
126 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
127 return;
128 }
129
130 $redirect_url = charitable_get_permalink( 'campaign_donation_page', array( 'campaign_id' => $campaign_id ) );
131
132 if ( 'same_page' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
133 $redirect_url .= '#charitable-donation-form';
134 }
135
136 $redirect_url = apply_filters( 'charitable_donation_amount_form_redirect', $redirect_url, $campaign_id, $amount );
137
138 wp_redirect( esc_url_raw( $redirect_url ) );
139
140 die();
141 }
142
143 /**
144 * Render the donation form.
145 *
146 * @since 1.0.0
147 *
148 * @return void
149 */
150 public function render() {
151 /* Load the script if it hasn't been loaded yet. */
152 if ( ! wp_script_is( 'charitable-script', 'enqueued' ) ) {
153
154 if ( ! class_exists( 'Charitable_Public' ) ) {
155 require_once( charitable()->get_path( 'public' ) . 'class-charitable-public.php' );
156 }
157
158 Charitable_Public::get_instance()->enqueue_donation_form_scripts();
159 }
160
161 charitable_template(
162 'donation-form/form-donation.php',
163 array(
164 'campaign' => $this->get_campaign(),
165 'form' => $this,
166 'form_id' => 'charitable-donation-amount-form',
167 )
168 );
169 }
170 }
171
172 endif;
173