PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.0
GiveWP – Donation Plugin and Fundraising Platform v2.7.0
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 / includes / actions.php
give / includes Last commit date
admin 6 years ago api 6 years ago database 6 years ago deprecated 6 years ago donors 6 years ago emails 6 years ago forms 6 years ago frontend 6 years ago gateways 6 years ago libraries 6 years ago payments 6 years ago actions.php 6 years ago ajax-functions.php 6 years ago class-give-async-process.php 6 years ago class-give-background-updater.php 6 years ago class-give-cache-setting.php 6 years ago class-give-cache.php 6 years ago class-give-cli-commands.php 6 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 6 years ago class-give-donor-wall-widget.php 6 years ago class-give-donor.php 6 years ago class-give-email-access.php 6 years ago class-give-license-handler.php 6 years ago class-give-logging.php 6 years ago class-give-readme-parser.php 6 years ago class-give-roles.php 6 years ago class-give-scripts.php 6 years ago class-give-session.php 6 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 6 years ago class-notices.php 6 years ago country-functions.php 6 years ago currencies-list.php 6 years ago currency-functions.php 6 years ago error-tracking.php 6 years ago filters.php 6 years ago formatting.php 6 years ago install.php 6 years ago login-register.php 6 years ago misc-functions.php 6 years ago plugin-compatibility.php 6 years ago post-types.php 6 years ago price-functions.php 6 years ago process-donation.php 6 years ago setting-functions.php 6 years ago shortcodes.php 6 years ago template-functions.php 6 years ago user-functions.php 6 years ago
actions.php
376 lines
1 <?php
2 /**
3 * Front-end Actions
4 *
5 * @package Give
6 * @subpackage Functions
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17
18 /**
19 * Look for Give core add-ons update after every third day
20 *
21 * @since 2.5.11
22 */
23 Give_Cron::add_thricely_event( 'give_refresh_licenses' );
24
25 /**
26 * Hooks Give actions, when present in the $_GET superglobal. Every give_action
27 * present in $_GET is called using WordPress's do_action function. These
28 * functions are called on init.
29 *
30 * @since 1.0
31 *
32 * @return void
33 */
34 function give_get_actions() {
35
36 $get_data = give_clean( $_GET ); // WPCS: input var ok, sanitization ok, CSRF ok.
37
38 $_get_action = ! empty( $get_data['give_action'] ) ? $get_data['give_action'] : null;
39
40 // Add backward compatibility to give-action param ( $_GET ).
41 if ( empty( $_get_action ) ) {
42 $_get_action = ! empty( $get_data['give-action'] ) ? $get_data['give-action'] : null;
43 }
44
45 if ( isset( $_get_action ) ) {
46 /**
47 * Fires in WordPress init or admin init, when give_action is present in $_GET.
48 *
49 * @since 1.0
50 *
51 * @param array $_GET Array of HTTP GET variables.
52 */
53 do_action( "give_{$_get_action}", $get_data );
54 }
55
56 }
57
58 add_action( 'init', 'give_get_actions' );
59
60 /**
61 * Hooks Give actions, when present in the $_POST super global. Every give_action
62 * present in $_POST is called using WordPress's do_action function. These
63 * functions are called on init.
64 *
65 * @since 1.0
66 *
67 * @return void
68 */
69 function give_post_actions() {
70
71 $post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.
72
73 $_post_action = ! empty( $post_data['give_action'] ) ? $post_data['give_action'] : null;
74
75 // Add backward compatibility to give-action param ( $_POST ).
76 if ( empty( $_post_action ) ) {
77 $_post_action = ! empty( $post_data['give-action'] ) ? $post_data['give-action'] : null;
78 }
79
80 if ( isset( $_post_action ) ) {
81 /**
82 * Fires in WordPress init or admin init, when give_action is present in $_POST.
83 *
84 * @since 1.0
85 *
86 * @param array $_POST Array of HTTP POST variables.
87 */
88 do_action( "give_{$_post_action}", $post_data );
89 }
90
91 }
92
93 add_action( 'init', 'give_post_actions' );
94
95 /**
96 * Connect WordPress user with Donor.
97 *
98 * @param int $user_id User ID.
99 * @param array $user_data User Data.
100 *
101 * @since 1.7
102 *
103 * @return void
104 */
105 function give_connect_donor_to_wpuser( $user_id, $user_data ) {
106 /* @var Give_Donor $donor */
107 $donor = new Give_Donor( $user_data['user_email'] );
108
109 // Validate donor id and check if do nor is already connect to wp user or not.
110 if ( $donor->id && ! $donor->user_id ) {
111
112 // Update donor user_id.
113 if ( $donor->update( array( 'user_id' => $user_id ) ) ) {
114 $donor_note = sprintf( esc_html__( 'WordPress user #%1$d is connected to #%2$d', 'give' ), $user_id, $donor->id );
115 $donor->add_note( $donor_note );
116
117 // Update user_id meta in payments.
118 // if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) {
119 // foreach ( $donations as $donation ) {
120 // give_update_meta( $donation, '_give_payment_user_id', $user_id );
121 // }
122 // }
123 // Do not need to update user_id in payment because we will get user id from donor id now.
124 }
125 }
126 }
127
128 add_action( 'give_insert_user', 'give_connect_donor_to_wpuser', 10, 2 );
129
130
131 /**
132 * Processing after donor batch export complete
133 *
134 * @since 1.8
135 *
136 * @param $data
137 */
138 function give_donor_batch_export_complete( $data ) {
139 // Remove donor ids cache.
140 if (
141 isset( $data['class'] )
142 && 'Give_Batch_Donors_Export' === $data['class']
143 && ! empty( $data['forms'] )
144 && isset( $data['give_export_option']['query_id'] )
145 ) {
146 Give_Cache::delete( Give_Cache::get_key( $data['give_export_option']['query_id'] ) );
147 }
148 }
149
150 add_action( 'give_file_export_complete', 'give_donor_batch_export_complete' );
151
152
153 /**
154 * Set Donation Amount for Multi Level Donation Forms
155 *
156 * @param int $form_id Donation Form ID.
157 *
158 * @since 1.8.9
159 *
160 * @return void
161 */
162 function give_set_donation_levels_max_min_amount( $form_id ) {
163 if (
164 ( 'set' === $_POST['_give_price_option'] ) ||
165 ( in_array( '_give_donation_levels', $_POST ) && count( $_POST['_give_donation_levels'] ) <= 0 ) ||
166 ! ( $donation_levels_amounts = wp_list_pluck( $_POST['_give_donation_levels'], '_give_amount' ) )
167 ) {
168 // Delete old meta.
169 give_delete_meta( $form_id, '_give_levels_minimum_amount' );
170 give_delete_meta( $form_id, '_give_levels_maximum_amount' );
171
172 return;
173 }
174
175 // Sanitize donation level amounts.
176 $donation_levels_amounts = array_map( 'give_maybe_sanitize_amount', $donation_levels_amounts );
177
178 $min_amount = min( $donation_levels_amounts );
179 $max_amount = max( $donation_levels_amounts );
180
181 // Set Minimum and Maximum amount for Multi Level Donation Forms.
182 give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount_for_db( $min_amount ) : 0 );
183 give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount_for_db( $max_amount ) : 0 );
184 }
185
186 add_action( 'give_pre_process_give_forms_meta', 'give_set_donation_levels_max_min_amount', 30 );
187
188
189 /**
190 * Save donor address when donation complete
191 *
192 * @since 2.0
193 *
194 * @param int $payment_id
195 */
196 function _give_save_donor_billing_address( $payment_id ) {
197 $donor_id = absint( give_get_payment_donor_id( $payment_id ) );
198
199 // Bailout
200 if ( ! $donor_id ) {
201 return;
202 }
203
204 /* @var Give_Donor $donor */
205 $donor = new Give_Donor( $donor_id );
206
207 // Save address.
208 $donor->add_address( 'billing[]', give_get_donation_address( $payment_id ) );
209 }
210
211 add_action( 'give_complete_donation', '_give_save_donor_billing_address', 9999 );
212
213
214 /**
215 * Update form id in payment logs
216 *
217 * @since 2.0
218 *
219 * @param array $args
220 */
221 function give_update_log_form_id( $args ) {
222 $new_form_id = absint( $args[0] );
223 $payment_id = absint( $args[1] );
224 $logs = Give()->logs->get_logs( $payment_id );
225
226 // Bailout.
227 if ( empty( $logs ) ) {
228 return;
229 }
230
231 /* @var object $log */
232 foreach ( $logs as $log ) {
233 Give()->logs->logmeta_db->update_meta( $log->ID, '_give_log_form_id', $new_form_id );
234 }
235
236 // Delete cache.
237 Give()->logs->delete_cache();
238 }
239
240 add_action( 'give_update_log_form_id', 'give_update_log_form_id' );
241
242 /**
243 * Verify addon dependency before addon update
244 *
245 * @since 2.1.4
246 *
247 * @param $error
248 * @param $hook_extra
249 *
250 * @return WP_Error
251 */
252 function __give_verify_addon_dependency_before_update( $error, $hook_extra ) {
253 // Bailout.
254 if (
255 is_wp_error( $error )
256 || ! array_key_exists( 'plugin', $hook_extra )
257 ) {
258 return $error;
259 }
260
261 $plugin_base = strtolower( $hook_extra['plugin'] );
262 $licensed_addon = array_map( 'strtolower', Give_License::get_licensed_addons() );
263
264 // Skip if not a Give addon.
265 if ( ! in_array( $plugin_base, $licensed_addon ) ) {
266 return $error;
267 }
268
269 // Load file.
270 if ( ! class_exists( 'Give_Readme_Parser' ) ) {
271 require_once GIVE_PLUGIN_DIR . 'includes/class-give-readme-parser.php';
272 }
273
274 $plugin_base = strtolower( $plugin_base );
275 $plugin_slug = str_replace( '.php', '', basename( $plugin_base ) );
276
277 $url = give_get_addon_readme_url( $plugin_slug );
278
279 $parser = new Give_Readme_Parser( $url );
280 $give_min_version = $parser->requires_at_least();
281
282 if ( version_compare( GIVE_VERSION, $give_min_version, '<' ) ) {
283 return new WP_Error(
284 'Give_Addon_Update_Error',
285 sprintf(
286 __( 'GiveWP version %s is required to update this add-on.', 'give' ),
287 $give_min_version
288 )
289 );
290 }
291
292 return $error;
293 }
294
295 add_filter( 'upgrader_pre_install', '__give_verify_addon_dependency_before_update', 10, 2 );
296
297 /**
298 * Function to add suppress_filters param if WPML add-on is activated.
299 *
300 * @since 2.1.4
301 *
302 * @param array WP query argument for Total Goal.
303 *
304 * @return array WP query argument for Total Goal.
305 */
306 function __give_wpml_total_goal_shortcode_agrs( $args ) {
307 $args['suppress_filters'] = true;
308
309 return $args;
310 }
311
312 /**
313 * Function to remove WPML post where filter in goal total amount shortcode.
314 *
315 * @since 2.1.4
316 * @global SitePress $sitepress
317 */
318 function __give_remove_wpml_parse_query_filter() {
319 global $sitepress;
320 remove_action( 'parse_query', array( $sitepress, 'parse_query' ) );
321 }
322
323
324 /**
325 * Function to add WPML post where filter in goal total amount shortcode.
326 *
327 * @since 2.1.4
328 * @global SitePress $sitepress
329 */
330 function __give_add_wpml_parse_query_filter() {
331 global $sitepress;
332 add_action( 'parse_query', array( $sitepress, 'parse_query' ) );
333 }
334
335 /**
336 * Action all the hook that add support for WPML.
337 *
338 * @since 2.1.4
339 */
340 function give_add_support_for_wpml() {
341 if ( ! function_exists( 'is_plugin_active' ) ) {
342 include_once ABSPATH . 'wp-admin/includes/plugin.php';
343 }
344
345 if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
346
347 add_filter( 'give_totals_goal_shortcode_query_args', '__give_wpml_total_goal_shortcode_agrs' );
348
349 // @see https://wpml.org/forums/topic/problem-with-query-filter-in-get_posts-function/#post-271309
350 add_action( 'give_totals_goal_shortcode_before_render', '__give_remove_wpml_parse_query_filter', 99 );
351 add_action( 'give_totals_goal_shortcode_after_render', '__give_add_wpml_parse_query_filter', 99 );
352 }
353 }
354
355 add_action( 'give_init', 'give_add_support_for_wpml', 1000 );
356
357 /**
358 * Backward compatibility for email_access property
359 * Note: only for internal purpose
360 *
361 * @todo: Need to decide when to remove this backward compatibility.
362 * We decided to load Give()->email_access on for frontend but some of email tags is still using this. Since we have option to resend email in admin then
363 * this cause of fatal error because that property does not load in backend. This is a temporary solution to prevent fatal error when resend receipt.
364 * ref: https://github.com/impress-org/give/issues/4068
365 *
366 * @since 2.4.5
367 */
368 function give_set_email_access_property() {
369 if ( ! ( Give()->email_access instanceof Give_Email_Access ) ) {
370 require_once GIVE_PLUGIN_DIR . 'includes/class-give-email-access.php';
371 Give()->email_access = new Give_Email_Access();
372 }
373 }
374 add_action( 'give_email_links', 'give_set_email_access_property', -1 );
375 add_action( 'give_donation-receipt_email_notification', 'give_set_email_access_property', -1 );
376