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 +190 -88 2.3.04.16.9 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,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 *
@@ -338,8 +347,23 @@
338 347 return apply_filters( 'give_get_history_page_uri', $history_page );
339 348 }
340 349
341 350 /**
351 + * Determines if we're currently on the History page.
352 + *
353 + * @since 1.0
354 + *
355 + * @return bool True if on the History page, false otherwise.
356 + */
357 +function give_is_history_page() {
358 + $give_options = give_get_settings();
359 +
360 + $history_page = isset( $give_options['history_page'] ) ? absint( $give_options['history_page'] ) : 0;
361 +
362 + return apply_filters( 'give_is_history_page', is_page( $history_page ) );
363 +}
364 +
365 +/**
342 366 * Check if a field is required
343 367 *
344 368 * @param string $field
345 369 * @param int $form_id
@@ -347,9 +371,9 @@
347 371 * @access public
348 372 * @since 1.0
349 373 * @return bool
350 374 */
351 -function give_field_is_required( $field = '', $form_id ) {
375 +function give_field_is_required( $field, $form_id ) {
352 376
353 377 $required_fields = give_get_required_fields( $form_id );
354 378
355 379 return array_key_exists( $field, $required_fields );
@@ -366,22 +390,25 @@
366 390 * @param int $payment_id Payment ID.
367 391 * @param bool|int $price_id Price ID, if any.
368 392 * @param string|null $donation_date The date of the donation.
369 393 *
394 + * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings.
395 + *
370 396 * @return void
371 397 */
372 -function give_record_donation_in_log( $give_form_id = 0, $payment_id, $price_id = false, $donation_date = null ) {
373 - $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',
374 401 'log_parent' => $payment_id,
375 402 'log_type' => 'sale',
376 403 'log_date' => isset( $donation_date ) ? $donation_date : null,
377 404 'log_date_gmt' => isset( $donation_date ) ? $donation_date : null,
378 - );
405 + ];
379 406
380 - $log_meta = array(
407 + $log_meta = [
381 408 'form_id' => $give_form_id,
382 409 'price_id' => (int) $price_id,
383 - );
410 + ];
384 411
385 412 Give()->logs->insert_log( $log_data, $log_meta );
386 413 }
387 414
@@ -405,8 +432,33 @@
405 432 return $form->increase_sales( $quantity );
406 433 }
407 434
408 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 +/**
409 461 * Decreases the sale count of a form. Primarily for when a donation is refunded.
410 462 *
411 463 * @since 1.0
412 464 *
@@ -434,11 +486,13 @@
434 486 * @param int $give_form_id Give Form ID
435 487 * @param int $amount Earnings
436 488 * @param int $payment_id Donation ID.
437 489 *
490 + * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings.
491 + *
438 492 * @return bool|int
439 493 */
440 -function give_increase_earnings( $give_form_id = 0, $amount, $payment_id = 0 ) {
494 +function give_increase_earnings( $give_form_id, $amount, $payment_id = 0 ) {
441 495 /** @var \Give_Donate_Form $form */
442 496 $form = new Give_Donate_Form( $give_form_id );
443 497
444 498 return $form->increase_earnings( $amount, $payment_id );
@@ -456,11 +510,13 @@
456 510 * @param int $form_id Give Form ID
457 511 * @param int $amount Earnings
458 512 * @param int $payment_id Donation ID.
459 513 *
514 + * @since 2.12.0 default value for the $form_id parameter is removed to prevent PHP8 warnings.
515 + *
460 516 * @return bool|int
461 517 */
462 -function give_decrease_form_earnings( $form_id = 0, $amount, $payment_id = 0 ) {
518 +function give_decrease_form_earnings( $form_id, $amount, $payment_id = 0 ) {
463 519 /** @var \Give_Donate_Form $form */
464 520 $form = new Give_Donate_Form( $form_id );
465 521
466 522 return $form->decrease_earnings( $amount, $payment_id );
@@ -572,9 +628,9 @@
572 628
573 629 $prices = give_get_variable_prices( $form_id );
574 630 $price_name = '';
575 631
576 - if ( false === $prices ) {
632 + if ( ! $prices ) {
577 633 return $price_name;
578 634 }
579 635
580 636 foreach ( $prices as $price ) {
@@ -580,16 +636,16 @@
580 636 foreach ( $prices as $price ) {
581 637
582 638 if ( intval( $price['_give_id']['level_id'] ) === intval( $price_id ) ) {
583 639
584 - $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 );
585 641 $price_fallback = $use_fallback ?
586 642 give_currency_filter(
587 643 give_format_amount(
588 644 $price['_give_amount'],
589 - array( 'sanitize' => false )
645 + [ 'sanitize' => false ]
590 646 ),
591 - array( 'decode_currency' => true )
647 + [ 'decode_currency' => true ]
592 648 ) : '';
593 649 $price_name = ! empty( $price_text ) ? $price_text : $price_fallback;
594 650
595 651 }
@@ -616,12 +672,11 @@
616 672
617 673 $range = sprintf(
618 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>',
619 675 '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 ) ) ),
676 + 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ),
621 677 '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 -
678 + 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) )
624 679 );
625 680
626 681 if ( ! $formatted ) {
627 682 $range = wp_strip_all_tags( $range );
@@ -868,12 +923,22 @@
868 923 foreach ( $prices as $price ) {
869 924 if ( isset( $price['_give_id']['level_id'] ) && $price['_give_id']['level_id'] == $price_id ) {
870 925 $amount = isset( $price['_give_amount'] ) ? $price['_give_amount'] : 0.00;
871 926 break;
872 - };
927 + }
873 928 }
874 929
875 - 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 + );
876 941 }
877 942
878 943 /**
879 944 * Returns the goal of a form
@@ -1008,9 +1073,9 @@
1008 1073 *
1009 1074 * @return array
1010 1075 */
1011 1076 function _give_get_prefill_form_field_values( $form_id ) {
1012 - $logged_in_donor_info = array();
1077 + $logged_in_donor_info = [];
1013 1078
1014 1079 if ( is_user_logged_in() ) :
1015 1080 $donor_data = get_userdata( get_current_user_id() );
1016 1081 $donor = new Give_Donor( get_current_user_id(), true );
@@ -1016,9 +1081,9 @@
1016 1081 $donor = new Give_Donor( get_current_user_id(), true );
1017 1082 $donor_address = $donor->get_donor_address();
1018 1083 $company_name = $donor->get_company_name();
1019 1084
1020 - $logged_in_donor_info = array(
1085 + $logged_in_donor_info = [
1021 1086 // First name.
1022 1087 'give_first' => $donor_data->first_name,
1023 1088
1024 1089 // Last name.
@@ -1049,9 +1114,9 @@
1049 1114 'card_city' => $donor_address['city'],
1050 1115
1051 1116 // Zipcode
1052 1117 'card_zip' => $donor_address['zip'],
1053 - );
1118 + ];
1054 1119 endif;
1055 1120
1056 1121 // Bailout: Auto fill form field values only form form which donor is donating.
1057 1122 if (
@@ -1066,9 +1131,9 @@
1066 1131 $give_purchase_data = Give()->session->get( 'give_purchase' );
1067 1132
1068 1133 // Get donor info from form data.
1069 1134 $give_donor_info_in_session = empty( $give_purchase_data['post_data'] )
1070 - ? array()
1135 + ? []
1071 1136 : $give_purchase_data['post_data'];
1072 1137
1073 1138 // Output.
1074 1139 return wp_parse_args( $give_donor_info_in_session, $logged_in_donor_info );
@@ -1083,9 +1148,9 @@
1083 1148 * @param array $args
1084 1149 *
1085 1150 * @return int
1086 1151 */
1087 -function give_get_form_donor_count( $form_id, $args = array() ) {
1152 +function give_get_form_donor_count( $form_id, $args = [] ) {
1088 1153 global $wpdb;
1089 1154
1090 1155 $cache_key = Give_Cache::get_key( "form_donor_count_{$form_id}", $args, false );
1091 1156 $donor_count = absint( Give_Cache::get_db_query( $cache_key ) );
@@ -1093,11 +1158,11 @@
1093 1158 if ( $form_id && ! $donor_count ) {
1094 1159 // Set arguments.
1095 1160 $args = wp_parse_args(
1096 1161 $args,
1097 - array(
1162 + [
1098 1163 'unique' => true,
1099 - )
1164 + ]
1100 1165 );
1101 1166
1102 1167 $donation_meta_table = Give()->payment_meta->table_name;
1103 1168 $donation_id_col_name = Give()->payment_meta->get_meta_type() . '_id';
@@ -1127,9 +1192,8 @@
1127 1192
1128 1193 $donor_count = absint( $wpdb->get_var( $query ) );
1129 1194 }
1130 1195
1131 -
1132 1196 /**
1133 1197 * Filter the donor count
1134 1198 *
1135 1199 * @since 2.1.0
@@ -1193,19 +1257,24 @@
1193 1257
1194 1258 /**
1195 1259 * Show Form Goal Stats in Admin ( Listing and Detail page )
1196 1260 *
1197 - * @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.
1198 1264 *
1199 1265 * @since 2.1.0
1200 1266 *
1267 + * @param int $form_id Form ID.
1268 + *
1201 1269 * @return string
1202 1270 */
1203 1271 function give_admin_form_goal_stats( $form_id ) {
1204 -
1205 1272 $html = '';
1206 1273 $goal_stats = give_goal_progress_stats( $form_id );
1207 - $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;
1208 1277
1209 1278 $html .= sprintf(
1210 1279 '<div class="give-admin-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="%1$s">
1211 1280 <span style="width:%1$s%%;"></span>
@@ -1220,18 +1289,20 @@
1220 1289 ( 'percentage' !== $goal_stats['format'] ) ? $goal_stats['actual'] : $percent_complete . '%',
1221 1290 ( 'percentage' !== $goal_stats['format'] ) ? __( 'of', 'give' ) : '',
1222 1291 esc_url( admin_url( "post.php?post={$form_id}&action=edit&give_tab=donation_goal_options" ) ),
1223 1292 $goal_stats['goal'],
1224 - ( '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' ) : '' ) )
1225 1294 );
1226 1295
1227 - if ( $goal_stats['raw_actual'] >= $goal_stats['raw_goal'] ) {
1228 - $html .= sprintf( '<span class="give-admin-goal-achieved"><span class="dashicons dashicons-star-filled"></span> %s</span>', __( 'Goal achieved', 'give' ) );
1229 - }
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 + );
1230 1302
1231 1303 $html .= '</div>';
1232 1304
1233 -
1234 1305 return $html;
1235 1306 }
1236 1307
1237 1308 /**
@@ -1250,9 +1321,8 @@
1250 1321 if ( give_has_variable_prices( $form_id ) ) {
1251 1322 /**
1252 1323 * Filter the variable pricing
1253 1324 *
1254 - *
1255 1325 * @since 1.0
1256 1326 * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices.
1257 1327 * Check Give_Donate_Form::get_prices().
1258 1328 *
@@ -1328,9 +1398,9 @@
1328 1398 * @param int $form_id Donation Form ID.
1329 1399 *
1330 1400 * @since 2.2.0
1331 1401 *
1332 - * @return mixed
1402 + * @return array
1333 1403 */
1334 1404 function give_get_name_title_prefixes( $form_id = 0 ) {
1335 1405
1336 1406 $name_title_prefix = give_is_name_title_prefix_enabled( $form_id );
@@ -1349,9 +1419,9 @@
1349 1419 }
1350 1420 }
1351 1421 }
1352 1422
1353 - return $title_prefixes;
1423 + return array_filter( (array) $title_prefixes );
1354 1424 }
1355 1425
1356 1426 /**
1357 1427 * Check whether the name title prefix is enabled or not.
@@ -1364,11 +1434,11 @@
1364 1434 * @return bool
1365 1435 */
1366 1436 function give_is_name_title_prefix_enabled( $form_id = 0, $status = '' ) {
1367 1437 if ( empty( $status ) ) {
1368 - $status = array( 'required', 'optional' );
1438 + $status = [ 'required', 'optional' ];
1369 1439 } else {
1370 - $status = array( $status );
1440 + $status = [ $status ];
1371 1441 }
1372 1442
1373 1443 $title_prefix_status = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status );
1374 1444
@@ -1448,13 +1518,13 @@
1448 1518 * @since 2.2.0
1449 1519 */
1450 1520 return apply_filters(
1451 1521 'give_get_default_title_prefixes',
1452 - array(
1522 + [
1453 1523 'Mr.' => __( 'Mr.', 'give' ),
1454 1524 'Mrs.' => __( 'Mrs.', 'give' ),
1455 1525 'Ms.' => __( 'Ms.', 'give' ),
1456 - )
1526 + ]
1457 1527 );
1458 1528 }
1459 1529
1460 1530 /**
@@ -1472,9 +1542,9 @@
1472 1542 if ( ! give_is_name_title_prefix_enabled( $form_id ) ) {
1473 1543 return false;
1474 1544 }
1475 1545
1476 - $status = array( 'optional' );
1546 + $status = [ 'optional' ];
1477 1547 $is_optional = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status );
1478 1548
1479 1549 if ( intval( $form_id ) > 0 ) {
1480 1550 $form_title_prefix = give_get_meta( $form_id, '_give_name_title_prefix', true );
@@ -1517,4 +1587,36 @@
1517 1587 }
1518 1588 }
1519 1589
1520 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 +}