PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 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 All 255 releases
← All changes | includes/forms/functions.php +173 -86 2.3.24.16.9 View file →
@@ -13,8 +13,10 @@
13 13 if ( ! defined( 'ABSPATH' ) ) {
14 14 exit;
15 15 }
16 16
17 +use Give\Helpers\Form\Utils as FormUtils;
18 +
17 19 /**
18 20 * Filter: Do not show the Give shortcut button on Give Forms CPT
19 21 *
20 22 * @return bool
@@ -74,8 +76,13 @@
74 76 if ( empty( $float_labels ) || ( 'global' === $float_labels ) ) {
75 77 $float_labels = give_get_option( 'floatlabels', 'disabled' );
76 78 }
77 79
80 + // If the form is using a non-legacy form template, do not use floating labels
81 + if ( ! FormUtils::isLegacyForm( $args['form_id'] ) ) {
82 + $float_labels = 'disabled';
83 + }
84 +
78 85 return give_is_setting_enabled( $float_labels );
79 86 }
80 87
81 88 /**
@@ -104,9 +111,11 @@
104 111 */
105 112 function give_get_success_page_uri() {
106 113 $give_options = give_get_settings();
107 114
108 - $success_page = isset( $give_options['success_page'] ) ? get_permalink( absint( $give_options['success_page'] ) ) : get_bloginfo( 'url' );
115 + $success_page = isset( $give_options['success_page'] )
116 + ? get_permalink( absint( $give_options['success_page'] ) )
117 + : get_bloginfo( 'url' );
109 118
110 119 return apply_filters( 'give_get_success_page_uri', $success_page );
111 120 }
112 121
@@ -117,12 +126,26 @@
117 126 *
118 127 * @return bool True if on the Success page, false otherwise.
119 128 */
120 129 function give_is_success_page() {
121 - return apply_filters( 'give_is_success_page', is_page( give_get_success_page_uri() ) );
130 + $give_options = give_get_settings();
131 +
132 + $success_page = isset( $give_options['success_page'] ) ? is_page( $give_options['success_page'] ) : false;
133 +
134 + return apply_filters( 'give_is_success_page', $success_page );
122 135 }
123 136
124 137 /**
138 + * @since 4.0.0
139 + *
140 + * @return bool
141 + */
142 +function give_is_campaign_page() {
143 + $currentId = get_the_ID();
144 +
145 + return (bool)get_post_meta( $currentId, 'give_campaign_id', true );
146 +}
147 +/**
125 148 * Send To Success Page
126 149 *
127 150 * Sends the user to the success page.
128 151 *
@@ -132,9 +155,8 @@
132 155 * @since 1.0
133 156 * @return void
134 157 */
135 158 function give_send_to_success_page( $query_string = null ) {
136 -
137 159 $redirect = give_get_success_page_uri();
138 160
139 161 if ( $query_string ) {
140 162 $redirect .= $query_string;
@@ -139,9 +161,9 @@
139 161 if ( $query_string ) {
140 162 $redirect .= $query_string;
141 163 }
142 164
143 - $gateway = isset( $_REQUEST['give-gateway'] ) ? $_REQUEST['give-gateway'] : '';
165 + $gateway = isset( $_REQUEST['give-gateway'] ) ? give_clean( $_REQUEST['give-gateway'] ) : '';
144 166
145 167 wp_redirect( apply_filters( 'give_success_page_redirect', $redirect, $gateway, $query_string ) );
146 168 give_die();
147 169 }
@@ -154,21 +176,28 @@
154 176 *
155 177 * @param array|string $args
156 178 *
157 179 * @access public
180 + * @since 2.21.0 Auto set "payment-mode" in redirect url.
158 181 * @since 1.0
159 182 * @return Void
160 183 */
161 -function give_send_back_to_checkout( $args = array() ) {
184 +function give_send_back_to_checkout( $args = [] ) {
162 185
163 186 $url = isset( $_POST['give-current-url'] ) ? sanitize_text_field( $_POST['give-current-url'] ) : '';
164 187 $form_id = 0;
188 + $defaults = [];
165 189
166 190 // Set the form_id.
167 191 if ( isset( $_POST['give-form-id'] ) ) {
168 - $form_id = sanitize_text_field( $_POST['give-form-id'] );
192 + $defaults['form-id'] = (int) sanitize_text_field( $_POST['give-form-id'] );
169 193 }
170 194
195 + // Set the payment mode.
196 + if ( isset( $_POST['payment-mode'] ) ) {
197 + $defaults['payment-mode'] = sanitize_text_field( $_POST['payment-mode'] );
198 + }
199 +
171 200 // Need a URL to continue. If none, redirect back to single form.
172 201 if ( empty( $url ) ) {
173 202 wp_safe_redirect( get_permalink( $form_id ) );
174 203 give_die();
@@ -173,15 +202,16 @@
173 202 wp_safe_redirect( get_permalink( $form_id ) );
174 203 give_die();
175 204 }
176 205
177 - $defaults = array(
178 - 'form-id' => (int) $form_id,
179 - );
180 -
181 206 // Set the $level_id.
182 207 if ( isset( $_POST['give-price-id'] ) ) {
183 208 $defaults['level-id'] = sanitize_text_field( $_POST['give-price-id'] );
209 +
210 + // If custom, set amount
211 + if( 'custom' === $defaults[ 'level-id' ] ) {
212 + $defaults['custom-amount'] = sanitize_text_field( $_POST['give-amount'] );
213 + }
184 214 }
185 215
186 216 // Check for backward compatibility.
187 217 if ( is_string( $args ) ) {
@@ -190,33 +220,22 @@
190 220
191 221 $args = wp_parse_args( $args, $defaults );
192 222
193 223 // Merge URL query with $args to maintain third-party URL parameters after redirect.
194 - $url_data = wp_parse_url( $url );
224 + $redirect = add_query_arg( $args, $url );
195 225
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 );
226 + // Precaution: don't allow any CC info.
227 + $redirect = remove_query_arg( [ 'card_number', 'card_cvc' ], $redirect );
199 228
200 - // Precaution: don't allow any CC info.
201 - unset( $query['card_number'] );
202 - unset( $query['card_cvc'] );
229 + // Redirect them.
230 + $redirect .= "#give-form-{$form_id}-wrap";
203 231
204 - } else {
205 - // No $url_data so pass empty array.
206 - $query = array();
207 - }
232 + /**
233 + * Filter the redirect url
234 + */
235 + wp_safe_redirect( esc_url_raw( apply_filters( 'give_send_back_to_checkout', $redirect, $args ) ) );
208 236
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 237 give_die();
218 -
219 238 }
220 239
221 240 /**
222 241 * Get Success Page URL
@@ -229,12 +248,10 @@
229 248 * @since 1.0
230 249 * @return string
231 250 */
232 251 function give_get_success_page_url( $query_string = null ) {
252 + $success_page = give_get_success_page_uri();
233 253
234 - $success_page = give_get_option( 'success_page', 0 );
235 - $success_page = get_permalink( $success_page );
236 -
237 254 if ( $query_string ) {
238 255 $success_page .= $query_string;
239 256 }
240 257
@@ -270,9 +287,8 @@
270 287 $uri = ! empty( $give_options['failure_page'] ) ?
271 288 trailingslashit( get_permalink( $give_options['failure_page'] ) ) :
272 289 home_url();
273 290
274 -
275 291 if ( $extras ) {
276 292 $uri .= "?{$extras}";
277 293 }
278 294
@@ -300,28 +316,21 @@
300 316 *
301 317 * @return bool
302 318 */
303 319 function give_listen_for_failed_payments() {
320 + $payment_id = ! empty( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : 0;
321 + $nonce = ! empty( $_GET['_wpnonce'] ) ? give_clean( $_GET['_wpnonce'] ) : false;
304 322
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 323 // Bailout.
310 - if ( ! $failed_page || ! is_page( $failed_page ) || ! $payment_id || ! $nonce ) {
324 + if ( ! $payment_id || ! wp_verify_nonce( $nonce, "give-failed-donation-{$payment_id}" ) ) {
311 325 return false;
312 326 }
313 327
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 328 // Set payment status to failure
320 329 give_update_payment_status( $payment_id, 'failed' );
321 330 }
322 331
323 -add_action( 'template_redirect', 'give_listen_for_failed_payments' );
332 +add_action( 'template_redirect', 'give_listen_for_failed_payments', 0 );
324 333
325 334 /**
326 335 * Retrieve the Donation History page URI
327 336 *
@@ -362,9 +371,9 @@
362 371 * @access public
363 372 * @since 1.0
364 373 * @return bool
365 374 */
366 -function give_field_is_required( $field = '', $form_id ) {
375 +function give_field_is_required( $field, $form_id ) {
367 376
368 377 $required_fields = give_get_required_fields( $form_id );
369 378
370 379 return array_key_exists( $field, $required_fields );
@@ -381,22 +390,25 @@
381 390 * @param int $payment_id Payment ID.
382 391 * @param bool|int $price_id Price ID, if any.
383 392 * @param string|null $donation_date The date of the donation.
384 393 *
394 + * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings.
395 + *
385 396 * @return void
386 397 */
387 -function give_record_donation_in_log( $give_form_id = 0, $payment_id, $price_id = false, $donation_date = null ) {
388 - $log_data = array(
398 +function give_record_donation_in_log( $give_form_id, $payment_id, $price_id = false, $donation_date = null ) {
399 + $log_data = [
400 + 'log_content' => 'Payment log info',
389 401 'log_parent' => $payment_id,
390 402 'log_type' => 'sale',
391 403 'log_date' => isset( $donation_date ) ? $donation_date : null,
392 404 'log_date_gmt' => isset( $donation_date ) ? $donation_date : null,
393 - );
405 + ];
394 406
395 - $log_meta = array(
407 + $log_meta = [
396 408 'form_id' => $give_form_id,
397 409 'price_id' => (int) $price_id,
398 - );
410 + ];
399 411
400 412 Give()->logs->insert_log( $log_data, $log_meta );
401 413 }
402 414
@@ -420,8 +432,33 @@
420 432 return $form->increase_sales( $quantity );
421 433 }
422 434
423 435 /**
436 + * Update the goal progress count of a donation form.
437 + *
438 + * @since 2.4.0
439 + *
440 + * @param int $form_id Give Form ID
441 + *
442 + * @return void
443 + */
444 +function give_update_goal_progress( $form_id = 0 ) {
445 +
446 + // Get goal option meta key
447 + $is_goal_enabled = give_is_setting_enabled( give_get_meta( $form_id, '_give_goal_option', true, 'disabled' ) );
448 +
449 + // Check, if the form goal is enabled.
450 + if ( $is_goal_enabled ) {
451 + $goal_stats = give_goal_progress_stats( $form_id );
452 + $form_goal_progress_value = ! empty( $goal_stats['progress'] ) ? $goal_stats['progress'] : 0;
453 + } else {
454 + $form_goal_progress_value = -1;
455 + }
456 +
457 + give_update_meta( $form_id, '_give_form_goal_progress', $form_goal_progress_value );
458 +}
459 +
460 +/**
424 461 * Decreases the sale count of a form. Primarily for when a donation is refunded.
425 462 *
426 463 * @since 1.0
427 464 *
@@ -449,11 +486,13 @@
449 486 * @param int $give_form_id Give Form ID
450 487 * @param int $amount Earnings
451 488 * @param int $payment_id Donation ID.
452 489 *
490 + * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings.
491 + *
453 492 * @return bool|int
454 493 */
455 -function give_increase_earnings( $give_form_id = 0, $amount, $payment_id = 0 ) {
494 +function give_increase_earnings( $give_form_id, $amount, $payment_id = 0 ) {
456 495 /** @var \Give_Donate_Form $form */
457 496 $form = new Give_Donate_Form( $give_form_id );
458 497
459 498 return $form->increase_earnings( $amount, $payment_id );
@@ -471,11 +510,13 @@
471 510 * @param int $form_id Give Form ID
472 511 * @param int $amount Earnings
473 512 * @param int $payment_id Donation ID.
474 513 *
514 + * @since 2.12.0 default value for the $form_id parameter is removed to prevent PHP8 warnings.
515 + *
475 516 * @return bool|int
476 517 */
477 -function give_decrease_form_earnings( $form_id = 0, $amount, $payment_id = 0 ) {
518 +function give_decrease_form_earnings( $form_id, $amount, $payment_id = 0 ) {
478 519 /** @var \Give_Donate_Form $form */
479 520 $form = new Give_Donate_Form( $form_id );
480 521
481 522 return $form->decrease_earnings( $amount, $payment_id );
@@ -587,9 +628,9 @@
587 628
588 629 $prices = give_get_variable_prices( $form_id );
589 630 $price_name = '';
590 631
591 - if ( false === $prices ) {
632 + if ( ! $prices ) {
592 633 return $price_name;
593 634 }
594 635
595 636 foreach ( $prices as $price ) {
@@ -595,16 +636,16 @@
595 636 foreach ( $prices as $price ) {
596 637
597 638 if ( intval( $price['_give_id']['level_id'] ) === intval( $price_id ) ) {
598 639
599 - $price_text = isset( $price['_give_text'] ) ? $price['_give_text'] : '';
640 + $price_text = apply_filters( 'give_form_level_text', isset( $price['_give_text'] ) ? $price['_give_text'] : '', $form_id, $price );
600 641 $price_fallback = $use_fallback ?
601 642 give_currency_filter(
602 643 give_format_amount(
603 644 $price['_give_amount'],
604 - array( 'sanitize' => false )
645 + [ 'sanitize' => false ]
605 646 ),
606 - array( 'decode_currency' => true )
647 + [ 'decode_currency' => true ]
607 648 ) : '';
608 649 $price_name = ! empty( $price_text ) ? $price_text : $price_fallback;
609 650
610 651 }
@@ -631,12 +672,11 @@
631 672
632 673 $range = sprintf(
633 674 '<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>',
634 675 'asc' === $order_type ? 'low' : 'high',
635 - 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, array( 'sanitize' => false ) ) ) : give_currency_filter( give_format_amount( $high, array( 'sanitize' => false ) ) ),
676 + 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ),
636 677 'asc' === $order_type ? 'high' : 'low',
637 - 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, array( 'sanitize' => false ) ) ) : give_currency_filter( give_format_amount( $low, array( 'sanitize' => false ) ) )
638 -
678 + 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) )
639 679 );
640 680
641 681 if ( ! $formatted ) {
642 682 $range = wp_strip_all_tags( $range );
@@ -883,12 +923,22 @@
883 923 foreach ( $prices as $price ) {
884 924 if ( isset( $price['_give_id']['level_id'] ) && $price['_give_id']['level_id'] == $price_id ) {
885 925 $amount = isset( $price['_give_amount'] ) ? $price['_give_amount'] : 0.00;
886 926 break;
887 - };
927 + }
888 928 }
889 929
890 - return apply_filters( 'give_get_price_option_amount', give_maybe_sanitize_amount( $amount ), $form_id, $price_id );
930 + /**
931 + * Filter the price amount
932 + *
933 + * @since 1.0
934 + */
935 + return apply_filters(
936 + 'give_get_price_option_amount',
937 + give_maybe_sanitize_amount( $amount, [ 'currency' => give_get_currency( $form_id ) ] ),
938 + $form_id,
939 + $price_id
940 + );
891 941 }
892 942
893 943 /**
894 944 * Returns the goal of a form
@@ -1023,9 +1073,9 @@
1023 1073 *
1024 1074 * @return array
1025 1075 */
1026 1076 function _give_get_prefill_form_field_values( $form_id ) {
1027 - $logged_in_donor_info = array();
1077 + $logged_in_donor_info = [];
1028 1078
1029 1079 if ( is_user_logged_in() ) :
1030 1080 $donor_data = get_userdata( get_current_user_id() );
1031 1081 $donor = new Give_Donor( get_current_user_id(), true );
@@ -1031,9 +1081,9 @@
1031 1081 $donor = new Give_Donor( get_current_user_id(), true );
1032 1082 $donor_address = $donor->get_donor_address();
1033 1083 $company_name = $donor->get_company_name();
1034 1084
1035 - $logged_in_donor_info = array(
1085 + $logged_in_donor_info = [
1036 1086 // First name.
1037 1087 'give_first' => $donor_data->first_name,
1038 1088
1039 1089 // Last name.
@@ -1064,9 +1114,9 @@
1064 1114 'card_city' => $donor_address['city'],
1065 1115
1066 1116 // Zipcode
1067 1117 'card_zip' => $donor_address['zip'],
1068 - );
1118 + ];
1069 1119 endif;
1070 1120
1071 1121 // Bailout: Auto fill form field values only form form which donor is donating.
1072 1122 if (
@@ -1081,9 +1131,9 @@
1081 1131 $give_purchase_data = Give()->session->get( 'give_purchase' );
1082 1132
1083 1133 // Get donor info from form data.
1084 1134 $give_donor_info_in_session = empty( $give_purchase_data['post_data'] )
1085 - ? array()
1135 + ? []
1086 1136 : $give_purchase_data['post_data'];
1087 1137
1088 1138 // Output.
1089 1139 return wp_parse_args( $give_donor_info_in_session, $logged_in_donor_info );
@@ -1098,9 +1148,9 @@
1098 1148 * @param array $args
1099 1149 *
1100 1150 * @return int
1101 1151 */
1102 -function give_get_form_donor_count( $form_id, $args = array() ) {
1152 +function give_get_form_donor_count( $form_id, $args = [] ) {
1103 1153 global $wpdb;
1104 1154
1105 1155 $cache_key = Give_Cache::get_key( "form_donor_count_{$form_id}", $args, false );
1106 1156 $donor_count = absint( Give_Cache::get_db_query( $cache_key ) );
@@ -1108,11 +1158,11 @@
1108 1158 if ( $form_id && ! $donor_count ) {
1109 1159 // Set arguments.
1110 1160 $args = wp_parse_args(
1111 1161 $args,
1112 - array(
1162 + [
1113 1163 'unique' => true,
1114 - )
1164 + ]
1115 1165 );
1116 1166
1117 1167 $donation_meta_table = Give()->payment_meta->table_name;
1118 1168 $donation_id_col_name = Give()->payment_meta->get_meta_type() . '_id';
@@ -1142,9 +1192,8 @@
1142 1192
1143 1193 $donor_count = absint( $wpdb->get_var( $query ) );
1144 1194 }
1145 1195
1146 -
1147 1196 /**
1148 1197 * Filter the donor count
1149 1198 *
1150 1199 * @since 2.1.0
@@ -1208,19 +1257,24 @@
1208 1257
1209 1258 /**
1210 1259 * Show Form Goal Stats in Admin ( Listing and Detail page )
1211 1260 *
1212 - * @param int $form_id Form ID.
1261 + * @since 3.16.0 Remove "give_donate_form_get_sales" filter logic
1262 + * @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
1263 + * @since 2.19.0 Prevent divide by zero issue in goal percentage calculation logic.
1213 1264 *
1214 1265 * @since 2.1.0
1215 1266 *
1267 + * @param int $form_id Form ID.
1268 + *
1216 1269 * @return string
1217 1270 */
1218 1271 function give_admin_form_goal_stats( $form_id ) {
1219 -
1220 1272 $html = '';
1221 1273 $goal_stats = give_goal_progress_stats( $form_id );
1222 - $percent_complete = round( ( $goal_stats['raw_actual'] / $goal_stats['raw_goal'] ), 3 ) * 100;
1274 + $percent_complete = $goal_stats['raw_goal'] && is_numeric($goal_stats['raw_actual']) && is_numeric($goal_stats['raw_goal'])
1275 + ? round(($goal_stats['raw_actual'] / $goal_stats['raw_goal']), 3) * 100
1276 + : 0;
1223 1277
1224 1278 $html .= sprintf(
1225 1279 '<div class="give-admin-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="%1$s">
1226 1280 <span style="width:%1$s%%;"></span>
@@ -1235,18 +1289,20 @@
1235 1289 ( 'percentage' !== $goal_stats['format'] ) ? $goal_stats['actual'] : $percent_complete . '%',
1236 1290 ( 'percentage' !== $goal_stats['format'] ) ? __( 'of', 'give' ) : '',
1237 1291 esc_url( admin_url( "post.php?post={$form_id}&action=edit&give_tab=donation_goal_options" ) ),
1238 1292 $goal_stats['goal'],
1239 - ( 'donors' === $goal_stats['format'] ? __( 'Donors', 'give' ) : ( 'donation' === $goal_stats['format'] ? __( 'Donations', 'give' ) : '' ) )
1293 + ( 'donors' === $goal_stats['format'] ? __( 'donors', 'give' ) : ( 'donation' === $goal_stats['format'] ? __( 'donations', 'give' ) : '' ) )
1240 1294 );
1241 1295
1242 - if ( $goal_stats['raw_actual'] >= $goal_stats['raw_goal'] ) {
1243 - $html .= sprintf( '<span class="give-admin-goal-achieved"><span class="dashicons dashicons-star-filled"></span> %s</span>', __( 'Goal achieved', 'give' ) );
1244 - }
1296 + $opacity = $goal_stats['raw_actual'] >= $goal_stats['raw_goal'] ? 1 : 0;
1297 + $html .= sprintf(
1298 + '<span style="opacity:%s" class="give-admin-goal-achieved"><span class="dashicons dashicons-star-filled"></span> %s</span>',
1299 + apply_filters('give_admin_goal_progress_achieved_opacity', $opacity),
1300 + __('Goal achieved', 'give')
1301 + );
1245 1302
1246 1303 $html .= '</div>';
1247 1304
1248 -
1249 1305 return $html;
1250 1306 }
1251 1307
1252 1308 /**
@@ -1265,9 +1321,8 @@
1265 1321 if ( give_has_variable_prices( $form_id ) ) {
1266 1322 /**
1267 1323 * Filter the variable pricing
1268 1324 *
1269 - *
1270 1325 * @since 1.0
1271 1326 * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices.
1272 1327 * Check Give_Donate_Form::get_prices().
1273 1328 *
@@ -1343,9 +1398,9 @@
1343 1398 * @param int $form_id Donation Form ID.
1344 1399 *
1345 1400 * @since 2.2.0
1346 1401 *
1347 - * @return mixed
1402 + * @return array
1348 1403 */
1349 1404 function give_get_name_title_prefixes( $form_id = 0 ) {
1350 1405
1351 1406 $name_title_prefix = give_is_name_title_prefix_enabled( $form_id );
@@ -1364,9 +1419,9 @@
1364 1419 }
1365 1420 }
1366 1421 }
1367 1422
1368 - return $title_prefixes;
1423 + return array_filter( (array) $title_prefixes );
1369 1424 }
1370 1425
1371 1426 /**
1372 1427 * Check whether the name title prefix is enabled or not.
@@ -1379,11 +1434,11 @@
1379 1434 * @return bool
1380 1435 */
1381 1436 function give_is_name_title_prefix_enabled( $form_id = 0, $status = '' ) {
1382 1437 if ( empty( $status ) ) {
1383 - $status = array( 'required', 'optional' );
1438 + $status = [ 'required', 'optional' ];
1384 1439 } else {
1385 - $status = array( $status );
1440 + $status = [ $status ];
1386 1441 }
1387 1442
1388 1443 $title_prefix_status = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status );
1389 1444
@@ -1463,13 +1518,13 @@
1463 1518 * @since 2.2.0
1464 1519 */
1465 1520 return apply_filters(
1466 1521 'give_get_default_title_prefixes',
1467 - array(
1522 + [
1468 1523 'Mr.' => __( 'Mr.', 'give' ),
1469 1524 'Mrs.' => __( 'Mrs.', 'give' ),
1470 1525 'Ms.' => __( 'Ms.', 'give' ),
1471 - )
1526 + ]
1472 1527 );
1473 1528 }
1474 1529
1475 1530 /**
@@ -1487,9 +1542,9 @@
1487 1542 if ( ! give_is_name_title_prefix_enabled( $form_id ) ) {
1488 1543 return false;
1489 1544 }
1490 1545
1491 - $status = array( 'optional' );
1546 + $status = [ 'optional' ];
1492 1547 $is_optional = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status );
1493 1548
1494 1549 if ( intval( $form_id ) > 0 ) {
1495 1550 $form_title_prefix = give_get_meta( $form_id, '_give_name_title_prefix', true );
@@ -1532,4 +1587,36 @@
1532 1587 }
1533 1588 }
1534 1589
1535 1590 add_action( 'before_delete_post', 'give_handle_form_meta_on_delete', 10, 1 );
1591 +
1592 +
1593 +/**
1594 + * Get the list of default parameters for the form shortcode.
1595 + *
1596 + * @since 3.2.1 Revert default display style to "onpage".
1597 + * @since 2.4.1
1598 + *
1599 + * @return array
1600 + */
1601 +function give_get_default_form_shortcode_args() {
1602 + $default = [
1603 + 'id' => '',
1604 + 'show_title' => true,
1605 + 'show_goal' => true,
1606 + 'show_content' => '',
1607 + 'float_labels' => '',
1608 + 'display_style' => '',
1609 + 'continue_button_title' => '',
1610 +
1611 + // This attribute belong to form template functionality.
1612 + // You can use this attribute to set modal open button background color.
1613 + 'button_color' => '#28C77B',
1614 + ];
1615 +
1616 + /**
1617 + * Fire the filter
1618 + */
1619 + $default = apply_filters( 'give_get_default_form_shortcode_args', $default );
1620 +
1621 + return $default;
1622 +}