PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.15.0
GiveWP – Donation Plugin and Fundraising Platform v3.15.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 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 All 253 releases
← All changes | includes/forms/functions.php +175 -84 2.3.03.15.0 View file →
@@ -1,11 +1,11 @@
1 1 <?php
2 2 /**
3 3 * Give Form Functions
4 4 *
5 - * @package WordImpress
5 + * @package GiveWP
6 6 * @subpackage Includes/Forms
7 - * @copyright Copyright (c) 2016, WordImpress
7 + * @copyright Copyright (c) 2016, GiveWP
8 8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 9 * @since 1.1
10 10 */
11 11
@@ -13,8 +13,11 @@
13 13 if ( ! defined( 'ABSPATH' ) ) {
14 14 exit;
15 15 }
16 16
17 +use Give\DonationForms\DonationQuery;
18 +use Give\Helpers\Form\Utils as FormUtils;
19 +
17 20 /**
18 21 * Filter: Do not show the Give shortcut button on Give Forms CPT
19 22 *
20 23 * @return bool
@@ -74,8 +77,13 @@
74 77 if ( empty( $float_labels ) || ( 'global' === $float_labels ) ) {
75 78 $float_labels = give_get_option( 'floatlabels', 'disabled' );
76 79 }
77 80
81 + // If the form is using a non-legacy form template, do not use floating labels
82 + if ( ! FormUtils::isLegacyForm( $args['form_id'] ) ) {
83 + $float_labels = 'disabled';
84 + }
85 +
78 86 return give_is_setting_enabled( $float_labels );
79 87 }
80 88
81 89 /**
@@ -104,9 +112,11 @@
104 112 */
105 113 function give_get_success_page_uri() {
106 114 $give_options = give_get_settings();
107 115
108 - $success_page = isset( $give_options['success_page'] ) ? get_permalink( absint( $give_options['success_page'] ) ) : get_bloginfo( 'url' );
116 + $success_page = isset( $give_options['success_page'] )
117 + ? get_permalink( absint( $give_options['success_page'] ) )
118 + : get_bloginfo( 'url' );
109 119
110 120 return apply_filters( 'give_get_success_page_uri', $success_page );
111 121 }
112 122
@@ -117,9 +127,13 @@
117 127 *
118 128 * @return bool True if on the Success page, false otherwise.
119 129 */
120 130 function give_is_success_page() {
121 - return apply_filters( 'give_is_success_page', is_page( give_get_success_page_uri() ) );
131 + $give_options = give_get_settings();
132 +
133 + $success_page = isset( $give_options['success_page'] ) ? is_page( $give_options['success_page'] ) : false;
134 +
135 + return apply_filters( 'give_is_success_page', $success_page );
122 136 }
123 137
124 138 /**
125 139 * Send To Success Page
@@ -132,9 +146,8 @@
132 146 * @since 1.0
133 147 * @return void
134 148 */
135 149 function give_send_to_success_page( $query_string = null ) {
136 -
137 150 $redirect = give_get_success_page_uri();
138 151
139 152 if ( $query_string ) {
140 153 $redirect .= $query_string;
@@ -139,9 +152,9 @@
139 152 if ( $query_string ) {
140 153 $redirect .= $query_string;
141 154 }
142 155
143 - $gateway = isset( $_REQUEST['give-gateway'] ) ? $_REQUEST['give-gateway'] : '';
156 + $gateway = isset( $_REQUEST['give-gateway'] ) ? give_clean( $_REQUEST['give-gateway'] ) : '';
144 157
145 158 wp_redirect( apply_filters( 'give_success_page_redirect', $redirect, $gateway, $query_string ) );
146 159 give_die();
147 160 }
@@ -154,21 +167,28 @@
154 167 *
155 168 * @param array|string $args
156 169 *
157 170 * @access public
171 + * @since 2.21.0 Auto set "payment-mode" in redirect url.
158 172 * @since 1.0
159 173 * @return Void
160 174 */
161 -function give_send_back_to_checkout( $args = array() ) {
175 +function give_send_back_to_checkout( $args = [] ) {
162 176
163 177 $url = isset( $_POST['give-current-url'] ) ? sanitize_text_field( $_POST['give-current-url'] ) : '';
164 178 $form_id = 0;
179 + $defaults = [];
165 180
166 181 // Set the form_id.
167 182 if ( isset( $_POST['give-form-id'] ) ) {
168 - $form_id = sanitize_text_field( $_POST['give-form-id'] );
183 + $defaults['form-id'] = (int) sanitize_text_field( $_POST['give-form-id'] );
169 184 }
170 185
186 + // Set the payment mode.
187 + if ( isset( $_POST['payment-mode'] ) ) {
188 + $defaults['payment-mode'] = sanitize_text_field( $_POST['payment-mode'] );
189 + }
190 +
171 191 // Need a URL to continue. If none, redirect back to single form.
172 192 if ( empty( $url ) ) {
173 193 wp_safe_redirect( get_permalink( $form_id ) );
174 194 give_die();
@@ -173,15 +193,16 @@
173 193 wp_safe_redirect( get_permalink( $form_id ) );
174 194 give_die();
175 195 }
176 196
177 - $defaults = array(
178 - 'form-id' => (int) $form_id,
179 - );
180 -
181 197 // Set the $level_id.
182 198 if ( isset( $_POST['give-price-id'] ) ) {
183 199 $defaults['level-id'] = sanitize_text_field( $_POST['give-price-id'] );
200 +
201 + // If custom, set amount
202 + if( 'custom' === $defaults[ 'level-id' ] ) {
203 + $defaults['custom-amount'] = sanitize_text_field( $_POST['give-amount'] );
204 + }
184 205 }
185 206
186 207 // Check for backward compatibility.
187 208 if ( is_string( $args ) ) {
@@ -190,33 +211,22 @@
190 211
191 212 $args = wp_parse_args( $args, $defaults );
192 213
193 214 // Merge URL query with $args to maintain third-party URL parameters after redirect.
194 - $url_data = wp_parse_url( $url );
215 + $redirect = add_query_arg( $args, $url );
195 216
196 - // Check if an array to prevent notices before parsing.
197 - if ( isset( $url_data['query'] ) && ! empty( $url_data['query'] ) ) {
198 - parse_str( $url_data['query'], $query );
217 + // Precaution: don't allow any CC info.
218 + $redirect = remove_query_arg( [ 'card_number', 'card_cvc' ], $redirect );
199 219
200 - // Precaution: don't allow any CC info.
201 - unset( $query['card_number'] );
202 - unset( $query['card_cvc'] );
220 + // Redirect them.
221 + $redirect .= "#give-form-{$form_id}-wrap";
203 222
204 - } else {
205 - // No $url_data so pass empty array.
206 - $query = array();
207 - }
223 + /**
224 + * Filter the redirect url
225 + */
226 + wp_safe_redirect( esc_url_raw( apply_filters( 'give_send_back_to_checkout', $redirect, $args ) ) );
208 227
209 - $new_query = array_merge( $args, $query );
210 - $new_query_string = http_build_query( $new_query );
211 -
212 - // Assemble URL parts.
213 - $redirect = home_url( '/' . $url_data['path'] . '?' . $new_query_string . '#give-form-' . $form_id . '-wrap' );
214 -
215 - // Redirect them.
216 - wp_safe_redirect( apply_filters( 'give_send_back_to_checkout', $redirect, $args ) );
217 228 give_die();
218 -
219 229 }
220 230
221 231 /**
222 232 * Get Success Page URL
@@ -229,12 +239,10 @@
229 239 * @since 1.0
230 240 * @return string
231 241 */
232 242 function give_get_success_page_url( $query_string = null ) {
243 + $success_page = give_get_success_page_uri();
233 244
234 - $success_page = give_get_option( 'success_page', 0 );
235 - $success_page = get_permalink( $success_page );
236 -
237 245 if ( $query_string ) {
238 246 $success_page .= $query_string;
239 247 }
240 248
@@ -270,9 +278,8 @@
270 278 $uri = ! empty( $give_options['failure_page'] ) ?
271 279 trailingslashit( get_permalink( $give_options['failure_page'] ) ) :
272 280 home_url();
273 281
274 -
275 282 if ( $extras ) {
276 283 $uri .= "?{$extras}";
277 284 }
278 285
@@ -300,28 +307,21 @@
300 307 *
301 308 * @return bool
302 309 */
303 310 function give_listen_for_failed_payments() {
311 + $payment_id = ! empty( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : 0;
312 + $nonce = ! empty( $_GET['_wpnonce'] ) ? give_clean( $_GET['_wpnonce'] ) : false;
304 313
305 - $failed_page = give_get_option( 'failure_page', 0 );
306 - $payment_id = ! empty( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : 0;
307 - $nonce = ! empty( $_GET['_wpnonce'] ) ? give_clean( $_GET['_wpnonce'] ) : false;
308 -
309 314 // Bailout.
310 - if ( ! $failed_page || ! is_page( $failed_page ) || ! $payment_id || ! $nonce ) {
315 + if ( ! $payment_id || ! wp_verify_nonce( $nonce, "give-failed-donation-{$payment_id}" ) ) {
311 316 return false;
312 317 }
313 318
314 - // Security check.
315 - if ( ! wp_verify_nonce( $nonce, "give-failed-donation-{$payment_id}" ) ) {
316 - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ) );
317 - }
318 -
319 319 // Set payment status to failure
320 320 give_update_payment_status( $payment_id, 'failed' );
321 321 }
322 322
323 -add_action( 'template_redirect', 'give_listen_for_failed_payments' );
323 +add_action( 'template_redirect', 'give_listen_for_failed_payments', 0 );
324 324
325 325 /**
326 326 * Retrieve the Donation History page URI
327 327 *
@@ -338,8 +338,23 @@
338 338 return apply_filters( 'give_get_history_page_uri', $history_page );
339 339 }
340 340
341 341 /**
342 + * Determines if we're currently on the History page.
343 + *
344 + * @since 1.0
345 + *
346 + * @return bool True if on the History page, false otherwise.
347 + */
348 +function give_is_history_page() {
349 + $give_options = give_get_settings();
350 +
351 + $history_page = isset( $give_options['history_page'] ) ? absint( $give_options['history_page'] ) : 0;
352 +
353 + return apply_filters( 'give_is_history_page', is_page( $history_page ) );
354 +}
355 +
356 +/**
342 357 * Check if a field is required
343 358 *
344 359 * @param string $field
345 360 * @param int $form_id
@@ -347,9 +362,9 @@
347 362 * @access public
348 363 * @since 1.0
349 364 * @return bool
350 365 */
351 -function give_field_is_required( $field = '', $form_id ) {
366 +function give_field_is_required( $field, $form_id ) {
352 367
353 368 $required_fields = give_get_required_fields( $form_id );
354 369
355 370 return array_key_exists( $field, $required_fields );
@@ -366,22 +381,25 @@
366 381 * @param int $payment_id Payment ID.
367 382 * @param bool|int $price_id Price ID, if any.
368 383 * @param string|null $donation_date The date of the donation.
369 384 *
385 + * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings.
386 + *
370 387 * @return void
371 388 */
372 -function give_record_donation_in_log( $give_form_id = 0, $payment_id, $price_id = false, $donation_date = null ) {
373 - $log_data = array(
389 +function give_record_donation_in_log( $give_form_id, $payment_id, $price_id = false, $donation_date = null ) {
390 + $log_data = [
391 + 'log_content' => 'Payment log info',
374 392 'log_parent' => $payment_id,
375 393 'log_type' => 'sale',
376 394 'log_date' => isset( $donation_date ) ? $donation_date : null,
377 395 'log_date_gmt' => isset( $donation_date ) ? $donation_date : null,
378 - );
396 + ];
379 397
380 - $log_meta = array(
398 + $log_meta = [
381 399 'form_id' => $give_form_id,
382 400 'price_id' => (int) $price_id,
383 - );
401 + ];
384 402
385 403 Give()->logs->insert_log( $log_data, $log_meta );
386 404 }
387 405
@@ -405,8 +423,33 @@
405 423 return $form->increase_sales( $quantity );
406 424 }
407 425
408 426 /**
427 + * Update the goal progress count of a donation form.
428 + *
429 + * @since 2.4.0
430 + *
431 + * @param int $form_id Give Form ID
432 + *
433 + * @return void
434 + */
435 +function give_update_goal_progress( $form_id = 0 ) {
436 +
437 + // Get goal option meta key
438 + $is_goal_enabled = give_is_setting_enabled( give_get_meta( $form_id, '_give_goal_option', true, 'disabled' ) );
439 +
440 + // Check, if the form goal is enabled.
441 + if ( $is_goal_enabled ) {
442 + $goal_stats = give_goal_progress_stats( $form_id );
443 + $form_goal_progress_value = ! empty( $goal_stats['progress'] ) ? $goal_stats['progress'] : 0;
444 + } else {
445 + $form_goal_progress_value = -1;
446 + }
447 +
448 + give_update_meta( $form_id, '_give_form_goal_progress', $form_goal_progress_value );
449 +}
450 +
451 +/**
409 452 * Decreases the sale count of a form. Primarily for when a donation is refunded.
410 453 *
411 454 * @since 1.0
412 455 *
@@ -434,11 +477,13 @@
434 477 * @param int $give_form_id Give Form ID
435 478 * @param int $amount Earnings
436 479 * @param int $payment_id Donation ID.
437 480 *
481 + * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings.
482 + *
438 483 * @return bool|int
439 484 */
440 -function give_increase_earnings( $give_form_id = 0, $amount, $payment_id = 0 ) {
485 +function give_increase_earnings( $give_form_id, $amount, $payment_id = 0 ) {
441 486 /** @var \Give_Donate_Form $form */
442 487 $form = new Give_Donate_Form( $give_form_id );
443 488
444 489 return $form->increase_earnings( $amount, $payment_id );
@@ -456,11 +501,13 @@
456 501 * @param int $form_id Give Form ID
457 502 * @param int $amount Earnings
458 503 * @param int $payment_id Donation ID.
459 504 *
505 + * @since 2.12.0 default value for the $form_id parameter is removed to prevent PHP8 warnings.
506 + *
460 507 * @return bool|int
461 508 */
462 -function give_decrease_form_earnings( $form_id = 0, $amount, $payment_id = 0 ) {
509 +function give_decrease_form_earnings( $form_id, $amount, $payment_id = 0 ) {
463 510 /** @var \Give_Donate_Form $form */
464 511 $form = new Give_Donate_Form( $form_id );
465 512
466 513 return $form->decrease_earnings( $amount, $payment_id );
@@ -572,9 +619,9 @@
572 619
573 620 $prices = give_get_variable_prices( $form_id );
574 621 $price_name = '';
575 622
576 - if ( false === $prices ) {
623 + if ( ! $prices ) {
577 624 return $price_name;
578 625 }
579 626
580 627 foreach ( $prices as $price ) {
@@ -580,16 +627,16 @@
580 627 foreach ( $prices as $price ) {
581 628
582 629 if ( intval( $price['_give_id']['level_id'] ) === intval( $price_id ) ) {
583 630
584 - $price_text = isset( $price['_give_text'] ) ? $price['_give_text'] : '';
631 + $price_text = apply_filters( 'give_form_level_text', isset( $price['_give_text'] ) ? $price['_give_text'] : '', $form_id, $price );
585 632 $price_fallback = $use_fallback ?
586 633 give_currency_filter(
587 634 give_format_amount(
588 635 $price['_give_amount'],
589 - array( 'sanitize' => false )
636 + [ 'sanitize' => false ]
590 637 ),
591 - array( 'decode_currency' => true )
638 + [ 'decode_currency' => true ]
592 639 ) : '';
593 640 $price_name = ! empty( $price_text ) ? $price_text : $price_fallback;
594 641
595 642 }
@@ -616,12 +663,11 @@
616 663
617 664 $range = sprintf(
618 665 '<span class="give_price_range_%1$s">%2$s</span><span class="give_price_range_sep">&nbsp;&ndash;&nbsp;</span><span class="give_price_range_%3$s">%4$s</span>',
619 666 'asc' === $order_type ? 'low' : 'high',
620 - 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, array( 'sanitize' => false ) ) ) : give_currency_filter( give_format_amount( $high, array( 'sanitize' => false ) ) ),
667 + 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ),
621 668 'asc' === $order_type ? 'high' : 'low',
622 - 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, array( 'sanitize' => false ) ) ) : give_currency_filter( give_format_amount( $low, array( 'sanitize' => false ) ) )
623 -
669 + 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) )
624 670 );
625 671
626 672 if ( ! $formatted ) {
627 673 $range = wp_strip_all_tags( $range );
@@ -868,12 +914,22 @@
868 914 foreach ( $prices as $price ) {
869 915 if ( isset( $price['_give_id']['level_id'] ) && $price['_give_id']['level_id'] == $price_id ) {
870 916 $amount = isset( $price['_give_amount'] ) ? $price['_give_amount'] : 0.00;
871 917 break;
872 - };
918 + }
873 919 }
874 920
875 - return apply_filters( 'give_get_price_option_amount', give_maybe_sanitize_amount( $amount ), $form_id, $price_id );
921 + /**
922 + * Filter the price amount
923 + *
924 + * @since 1.0
925 + */
926 + return apply_filters(
927 + 'give_get_price_option_amount',
928 + give_maybe_sanitize_amount( $amount, [ 'currency' => give_get_currency( $form_id ) ] ),
929 + $form_id,
930 + $price_id
931 + );
876 932 }
877 933
878 934 /**
879 935 * Returns the goal of a form
@@ -1008,9 +1064,9 @@
1008 1064 *
1009 1065 * @return array
1010 1066 */
1011 1067 function _give_get_prefill_form_field_values( $form_id ) {
1012 - $logged_in_donor_info = array();
1068 + $logged_in_donor_info = [];
1013 1069
1014 1070 if ( is_user_logged_in() ) :
1015 1071 $donor_data = get_userdata( get_current_user_id() );
1016 1072 $donor = new Give_Donor( get_current_user_id(), true );
@@ -1016,9 +1072,9 @@
1016 1072 $donor = new Give_Donor( get_current_user_id(), true );
1017 1073 $donor_address = $donor->get_donor_address();
1018 1074 $company_name = $donor->get_company_name();
1019 1075
1020 - $logged_in_donor_info = array(
1076 + $logged_in_donor_info = [
1021 1077 // First name.
1022 1078 'give_first' => $donor_data->first_name,
1023 1079
1024 1080 // Last name.
@@ -1049,9 +1105,9 @@
1049 1105 'card_city' => $donor_address['city'],
1050 1106
1051 1107 // Zipcode
1052 1108 'card_zip' => $donor_address['zip'],
1053 - );
1109 + ];
1054 1110 endif;
1055 1111
1056 1112 // Bailout: Auto fill form field values only form form which donor is donating.
1057 1113 if (
@@ -1066,9 +1122,9 @@
1066 1122 $give_purchase_data = Give()->session->get( 'give_purchase' );
1067 1123
1068 1124 // Get donor info from form data.
1069 1125 $give_donor_info_in_session = empty( $give_purchase_data['post_data'] )
1070 - ? array()
1126 + ? []
1071 1127 : $give_purchase_data['post_data'];
1072 1128
1073 1129 // Output.
1074 1130 return wp_parse_args( $give_donor_info_in_session, $logged_in_donor_info );
@@ -1083,9 +1139,9 @@
1083 1139 * @param array $args
1084 1140 *
1085 1141 * @return int
1086 1142 */
1087 -function give_get_form_donor_count( $form_id, $args = array() ) {
1143 +function give_get_form_donor_count( $form_id, $args = [] ) {
1088 1144 global $wpdb;
1089 1145
1090 1146 $cache_key = Give_Cache::get_key( "form_donor_count_{$form_id}", $args, false );
1091 1147 $donor_count = absint( Give_Cache::get_db_query( $cache_key ) );
@@ -1093,11 +1149,11 @@
1093 1149 if ( $form_id && ! $donor_count ) {
1094 1150 // Set arguments.
1095 1151 $args = wp_parse_args(
1096 1152 $args,
1097 - array(
1153 + [
1098 1154 'unique' => true,
1099 - )
1155 + ]
1100 1156 );
1101 1157
1102 1158 $donation_meta_table = Give()->payment_meta->table_name;
1103 1159 $donation_id_col_name = Give()->payment_meta->get_meta_type() . '_id';
@@ -1127,9 +1183,8 @@
1127 1183
1128 1184 $donor_count = absint( $wpdb->get_var( $query ) );
1129 1185 }
1130 1186
1131 -
1132 1187 /**
1133 1188 * Filter the donor count
1134 1189 *
1135 1190 * @since 2.1.0
@@ -1193,19 +1248,25 @@
1193 1248
1194 1249 /**
1195 1250 * Show Form Goal Stats in Admin ( Listing and Detail page )
1196 1251 *
1197 - * @param int $form_id Form ID.
1252 + * @since 3.14.0 Use the 'give_get_form_earnings_stats" filter to ensure the correct value will be displayed in the form progress bar
1253 + * @since 2.19.0 Prevent divide by zero issue in goal percentage calculation logic.
1198 1254 *
1199 1255 * @since 2.1.0
1200 1256 *
1257 + * @param int $form_id Form ID.
1258 + *
1201 1259 * @return string
1202 1260 */
1203 1261 function give_admin_form_goal_stats( $form_id ) {
1262 + add_filter('give_get_form_earnings_stats', function ($earnings, $donationFormId) {
1263 + return (new DonationQuery())->form($donationFormId)->sumAmount();
1264 + }, 10, 2);
1204 1265
1205 1266 $html = '';
1206 1267 $goal_stats = give_goal_progress_stats( $form_id );
1207 - $percent_complete = round( ( $goal_stats['raw_actual'] / $goal_stats['raw_goal'] ), 3 ) * 100;
1268 + $percent_complete = $goal_stats['raw_goal'] ? round( ( $goal_stats['raw_actual'] / $goal_stats['raw_goal'] ), 3 ) * 100 : 0;
1208 1269
1209 1270 $html .= sprintf(
1210 1271 '<div class="give-admin-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="%1$s">
1211 1272 <span style="width:%1$s%%;"></span>
@@ -1220,9 +1281,9 @@
1220 1281 ( 'percentage' !== $goal_stats['format'] ) ? $goal_stats['actual'] : $percent_complete . '%',
1221 1282 ( 'percentage' !== $goal_stats['format'] ) ? __( 'of', 'give' ) : '',
1222 1283 esc_url( admin_url( "post.php?post={$form_id}&action=edit&give_tab=donation_goal_options" ) ),
1223 1284 $goal_stats['goal'],
1224 - ( 'donors' === $goal_stats['format'] ? __( 'Donors', 'give' ) : ( 'donation' === $goal_stats['format'] ? __( 'Donations', 'give' ) : '' ) )
1285 + ( 'donors' === $goal_stats['format'] ? __( 'donors', 'give' ) : ( 'donation' === $goal_stats['format'] ? __( 'donations', 'give' ) : '' ) )
1225 1286 );
1226 1287
1227 1288 if ( $goal_stats['raw_actual'] >= $goal_stats['raw_goal'] ) {
1228 1289 $html .= sprintf( '<span class="give-admin-goal-achieved"><span class="dashicons dashicons-star-filled"></span> %s</span>', __( 'Goal achieved', 'give' ) );
@@ -1229,9 +1290,8 @@
1229 1290 }
1230 1291
1231 1292 $html .= '</div>';
1232 1293
1233 -
1234 1294 return $html;
1235 1295 }
1236 1296
1237 1297 /**
@@ -1250,9 +1310,8 @@
1250 1310 if ( give_has_variable_prices( $form_id ) ) {
1251 1311 /**
1252 1312 * Filter the variable pricing
1253 1313 *
1254 - *
1255 1314 * @since 1.0
1256 1315 * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices.
1257 1316 * Check Give_Donate_Form::get_prices().
1258 1317 *
@@ -1328,9 +1387,9 @@
1328 1387 * @param int $form_id Donation Form ID.
1329 1388 *
1330 1389 * @since 2.2.0
1331 1390 *
1332 - * @return mixed
1391 + * @return array
1333 1392 */
1334 1393 function give_get_name_title_prefixes( $form_id = 0 ) {
1335 1394
1336 1395 $name_title_prefix = give_is_name_title_prefix_enabled( $form_id );
@@ -1349,9 +1408,9 @@
1349 1408 }
1350 1409 }
1351 1410 }
1352 1411
1353 - return $title_prefixes;
1412 + return array_filter( (array) $title_prefixes );
1354 1413 }
1355 1414
1356 1415 /**
1357 1416 * Check whether the name title prefix is enabled or not.
@@ -1364,11 +1423,11 @@
1364 1423 * @return bool
1365 1424 */
1366 1425 function give_is_name_title_prefix_enabled( $form_id = 0, $status = '' ) {
1367 1426 if ( empty( $status ) ) {
1368 - $status = array( 'required', 'optional' );
1427 + $status = [ 'required', 'optional' ];
1369 1428 } else {
1370 - $status = array( $status );
1429 + $status = [ $status ];
1371 1430 }
1372 1431
1373 1432 $title_prefix_status = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status );
1374 1433
@@ -1448,13 +1507,13 @@
1448 1507 * @since 2.2.0
1449 1508 */
1450 1509 return apply_filters(
1451 1510 'give_get_default_title_prefixes',
1452 - array(
1511 + [
1453 1512 'Mr.' => __( 'Mr.', 'give' ),
1454 1513 'Mrs.' => __( 'Mrs.', 'give' ),
1455 1514 'Ms.' => __( 'Ms.', 'give' ),
1456 - )
1515 + ]
1457 1516 );
1458 1517 }
1459 1518
1460 1519 /**
@@ -1472,9 +1531,9 @@
1472 1531 if ( ! give_is_name_title_prefix_enabled( $form_id ) ) {
1473 1532 return false;
1474 1533 }
1475 1534
1476 - $status = array( 'optional' );
1535 + $status = [ 'optional' ];
1477 1536 $is_optional = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status );
1478 1537
1479 1538 if ( intval( $form_id ) > 0 ) {
1480 1539 $form_title_prefix = give_get_meta( $form_id, '_give_name_title_prefix', true );
@@ -1517,4 +1576,36 @@
1517 1576 }
1518 1577 }
1519 1578
1520 1579 add_action( 'before_delete_post', 'give_handle_form_meta_on_delete', 10, 1 );
1580 +
1581 +
1582 +/**
1583 + * Get the list of default parameters for the form shortcode.
1584 + *
1585 + * @since 3.2.1 Revert default display style to "onpage".
1586 + * @since 2.4.1
1587 + *
1588 + * @return array
1589 + */
1590 +function give_get_default_form_shortcode_args() {
1591 + $default = [
1592 + 'id' => '',
1593 + 'show_title' => true,
1594 + 'show_goal' => true,
1595 + 'show_content' => '',
1596 + 'float_labels' => '',
1597 + 'display_style' => '',
1598 + 'continue_button_title' => '',
1599 +
1600 + // This attribute belong to form template functionality.
1601 + // You can use this attribute to set modal open button background color.
1602 + 'button_color' => '#28C77B',
1603 + ];
1604 +
1605 + /**
1606 + * Fire the filter
1607 + */
1608 + $default = apply_filters( 'give_get_default_form_shortcode_args', $default );
1609 +
1610 + return $default;
1611 +}