PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.12.2
GiveWP – Donation Plugin and Fundraising Platform v2.12.2
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / Views / Form / Templates / Sequoia / Actions.php
give / src / Views / Form / Templates / Sequoia Last commit date
assets 4 years ago sections 5 years ago views 5 years ago Actions.php 5 years ago Sequoia.php 5 years ago optionConfig.php 5 years ago
Actions.php
320 lines
1 <?php
2
3 namespace Give\Views\Form\Templates\Sequoia;
4
5 use Give_Donate_Form;
6 use Give\Helpers\Form\Template as FormTemplateUtils;
7
8 /**
9 * Class Actions
10 *
11 * @since 2.7.0
12 * @package Give\Views\Form\Templates\Sequoia
13 */
14 class Actions {
15
16 protected $templateOptions;
17
18 /**
19 * Initialize
20 *
21 * @since 2.7.0
22 */
23 public function init() {
24 // Get Template options
25 $this->templateOptions = FormTemplateUtils::getOptions();
26
27 // Get decimal numbers option
28 $decimalNumbersOption = isset( $this->templateOptions['payment_amount']['decimals_enabled'] )
29 ? $this->templateOptions['payment_amount']['decimals_enabled']
30 : 'disabled';
31
32 // Set zero number of decimal.
33 if ( 'disabled' === $decimalNumbersOption ) {
34 add_filter( 'give_get_currency_formatting_settings', [ $this, 'setupZeroNumberOfDecimalInCurrencyFormattingSetting' ], 1 );
35 add_filter( 'give_get_option_number_decimals', [ $this, 'setupZeroNumberOfDecimal' ], 1 );
36 }
37
38 // Handle personal section html template.
39 add_action( 'wp_ajax_give_cancel_login', [ $this, 'cancelLoginAjaxHanleder' ], 9 );
40 add_action( 'wp_ajax_nopriv_give_cancel_login', [ $this, 'cancelLoginAjaxHanleder' ], 9 );
41 add_action( 'wp_ajax_nopriv_give_checkout_register', [ $this, 'cancelLoginAjaxHanleder' ], 9 );
42
43 // Handle common hooks.
44 add_action( 'give_donation_form', [ $this, 'loadCommonHooks' ], 9, 2 );
45
46 // Setup hooks.
47 add_action( 'give_pre_form_output', [ $this, 'loadHooks' ], 1, 3 );
48
49 // Setup Stripe font Styles
50 add_filter( 'give_stripe_get_element_font_styles', [ $this, 'setupStripeFontStyles' ], 1 );
51
52 // Setup Stripe base styles
53 add_filter( 'give_stripe_get_element_base_styles', [ $this, 'setupStripeBaseStyles' ], 1 );
54
55 }
56
57 /** Set Stripe base styles consistent with Sequoia form template
58 *
59 * As per design requirement, we want to format Stripe elements to use Montserrat, with the same styling options as other text inputs.
60 *
61 * @since 2.7.0
62 * @param object $styles
63 * @return object
64 */
65 public function setupStripeBaseStyles( $styles ) {
66 $styles = '{
67 "fontFamily": "Montserrat",
68 "color": "#8d8e8e",
69 "fontWeight": 400,
70 "fontSize": "14px",
71 "::placeholder": {
72 "color": "#8d8e8e"
73 },
74 ":-webkit-autofill": {
75 "color": "#e39f48"
76 }
77 }';
78 return json_decode( $styles );
79 }
80
81 /** Set Stripe Font styles consistent with Sequoia form template
82 *
83 * As per design requirement, we want to format Stripe elements to use Montserrat, with the same styling options as other text inputs.
84 *
85 * @since 2.7.0
86 * @param array $fontStyles
87 * @return array
88 */
89 public function setupStripeFontStyles( $fontStyles ) {
90 return [
91 'cssSrc' => 'https://fonts.googleapis.com/css2?family=Montserrat&display=swap',
92 ];
93 }
94
95 /**
96 * Set zero as number of decimals in currency formatting setting.
97 *
98 * As per design requirement we want to format donation amount with zero decimal whether or not number of decimal admin setting set to zero.
99 *
100 * @since 2.7.0
101 * @param array $currencyFormattingSettings
102 * @return array
103 */
104 public function setupZeroNumberOfDecimalInCurrencyFormattingSetting( $currencyFormattingSettings ) {
105 $currencyFormattingSettings['number_decimals'] = 0;
106 return $currencyFormattingSettings;
107 }
108
109
110 /**
111 * Return zero as number of decimals setting value or currency formatting value.
112 *
113 * As per design requirement we want to format donation amount with zero decimal whether or not number of decimal admin setting set to zero.
114 *
115 * @since 2.7.0
116 * @return int|array
117 */
118 public function setupZeroNumberOfDecimal() {
119 return 0;
120 }
121
122 /**
123 * Handle cancel login and checkout register ajax request.
124 *
125 * @since 2.7.0
126 * @return void
127 */
128 public function cancelLoginAjaxHanleder() {
129 // add_action( 'give_donation_form_before_personal_info', [ $this, 'getIntroductionSectionTextSubSection' ] );
130 }
131
132 /**
133 * Setup common hooks
134 *
135 * @param int $formId
136 * @param array $args
137 */
138 public function loadCommonHooks( $formId, $args ) {
139 remove_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
140 }
141
142 /**
143 * Setup hooks
144 *
145 * @param int $formId
146 * @param array $args
147 * @param Give_Donate_Form $form
148 */
149 public function loadHooks( $formId, $args, $form ) {
150 /**
151 * Add hooks
152 */
153 add_action( 'give_pre_form', [ $this, 'getNavigator' ], 0, 3 );
154 add_action( 'give_post_form', [ $this, 'getFooterSection' ], 99998, 0 );
155 add_action( 'give_donation_form_top', [ $this, 'getIntroductionSection' ], 0, 3 );
156 add_action( 'give_donation_form_top', [ $this, 'getStartWrapperHTMLForAmountSection' ], 0 );
157 add_action( 'give_donation_form_top', [ $this, 'getCloseWrapperHTMLForAmountSection' ], 99998 );
158 add_action( 'give_payment_mode_top', 'give_show_register_login_fields' );
159 add_action( 'give_payment_mode_top', [ $this, 'getStartWrapperHTMLForPaymentSection' ], 0 );
160 add_action( 'give_donation_form_after_submit', [ $this, 'getCloseWrapperHTMLForPaymentSection' ], 999 );
161
162 /**
163 * Remove actions
164 */
165 // Remove goal.
166 remove_action( 'give_pre_form', 'give_show_goal_progress', 10 );
167
168 // Remove intermediate continue button which appear when display style set to other then onpage.
169 remove_action( 'give_after_donation_levels', 'give_display_checkout_button', 10 );
170
171 // Hide title.
172 add_filter( 'give_form_title', '__return_empty_string' );
173
174 // Append "Donate with " to gateway labels
175 add_filter( 'give_enabled_payment_gateways', [ $this, 'modifyGatewayLabels' ] );
176
177 }
178
179 /**
180 * Add form navigator / header
181 *
182 * @since 2.7.0
183 *
184 * @param $formId
185 * @param $args
186 * @param $form
187 */
188 public function getNavigator( $formId, $args, $form ) {
189 include 'sections/form-navigator.php';
190 }
191
192 /**
193 * Add introduction form section
194 *
195 * @since 2.7.0
196 *
197 * @param $formId
198 * @param $args
199 * @param $form
200 */
201 public function getIntroductionSection( $formId, $args, $form ) {
202 include 'sections/introduction.php';
203 }
204
205 /**
206 * Add form footer
207 *
208 * @since 2.7.0
209 */
210 public function getFooterSection() {
211 include 'sections/footer.php';
212 }
213
214 /**
215 * Add checkout button
216 *
217 * @since 2.7.0
218 */
219 public function getCheckoutButton() {
220
221 $label = isset( $this->templateOptions['payment_information']['checkout_label'] ) ? $this->templateOptions['payment_information']['checkout_label'] : __( 'Donate Now', 'give' );
222
223 return sprintf(
224 '<div class="give-submit-button-wrap give-clearfix">
225 <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" value="%1$s" data-before-validation-label="Donate Now">
226 <span class="give-loading-animation"></span>
227 </div>',
228 $label
229 );
230 }
231
232 /**
233 * Add wrapper and introduction text to payment information section
234 *
235 * @since 2.7.0
236 *
237 * @param int $formId
238 */
239 public function getStartWrapperHTMLForPaymentSection( $formId ) {
240 $headline = isset( $this->templateOptions['payment_information']['headline'] ) ? $this->templateOptions['payment_information']['headline'] : __( "Who's giving today?", 'give' );
241 $description = isset( $this->templateOptions['payment_information']['description'] ) ? $this->templateOptions['payment_information']['description'] : __( 'We’ll never share this information with anyone.', 'give' );
242
243 printf(
244 '<div class="give-section payment"><div class="heading">%1$s</div><div class="subheading">%2$s</div>',
245 $headline,
246 $description
247 );
248 }
249
250 /**
251 * Close wrapper for payment information section
252 *
253 * @since 2.7.0
254 */
255 public function getCloseWrapperHTMLForPaymentSection() {
256 echo '</div>';
257 }
258
259 /**
260 * Start choose amount section
261 *
262 * @since 2.7.0
263 */
264 public function getStartWrapperHTMLForAmountSection() {
265 $content = isset( $this->templateOptions['payment_amount']['content'] ) && ! empty( $this->templateOptions['payment_amount']['content'] ) ? $this->templateOptions['payment_amount']['content'] : sprintf( __( 'How much would you like to donate? As a contributor to %s we make sure your donation goes directly to supporting our cause. Thank you for your generosity!', 'give' ), get_bloginfo( 'sitename' ) );
266 $label = ! empty( $this->templateOptions['introduction']['donate_label'] ) ? $this->templateOptions['introduction']['donate_label'] : __( 'Donate Now', 'give' );
267 $arrow = is_rtl() ? 'left' : 'right';
268 printf(
269 '<button class="give-btn advance-btn">%1$s<i class="fas fa-chevron-%2$s"></i></button></div>',
270 $label,
271 $arrow
272 );
273
274 if ( ! empty( $content ) ) {
275 printf(
276 '<div class="give-section choose-amount"><p class="content">%1$s</p>',
277 $content
278 );
279 } else {
280 echo "<div class='give-section choose-amount'>";
281 }
282 }
283
284 /**
285 * Close choose amount section
286 *
287 * @since 2.7.0
288 */
289 public function getCloseWrapperHTMLForAmountSection() {
290 $label = isset( $this->templateOptions['payment_amount']['next_label'] ) ? $this->templateOptions['payment_amount']['next_label'] : __( 'Continue', 'give' );
291 $arrow = is_rtl() ? 'left' : 'right';
292
293 printf(
294 '<button class="give-btn advance-btn">%1$s<i class="fas fa-chevron-%2$s"></i></button></div>',
295 $label,
296 $arrow
297 );
298 }
299
300 /**
301 * Append gateway labels with "Donate with "
302 *
303 * Modify gateways array returned give_get_enabled_payment_gateways, before printing
304 *
305 * @param array $gateways Array of enabled gateways
306 *
307 * @return array $gateways Array of modified enabled gateways
308 */
309 public function modifyGatewayLabels( array $gateways ) {
310 foreach ( $gateways as $key => $value ) {
311 $gateways[ $key ]['checkout_label'] = sprintf(
312 __( 'Donate with %1$s', 'give' ),
313 $gateways[ $key ]['checkout_label']
314 );
315 }
316 return $gateways;
317 }
318
319 }
320