PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.4
GiveWP – Donation Plugin and Fundraising Platform v2.1.4
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 8 years ago api 8 years ago deprecated 8 years ago donors 8 years ago emails 8 years ago forms 8 years ago gateways 8 years ago libraries 8 years ago payments 8 years ago actions.php 8 years ago ajax-functions.php 8 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 8 years ago class-give-cache.php 8 years ago class-give-cli-commands.php 8 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 8 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 8 years ago class-give-db-meta.php 8 years ago class-give-db-payment-meta.php 8 years ago class-give-db-sequential-ordering.php 8 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor.php 8 years ago class-give-email-access.php 8 years ago class-give-gravatars.php 8 years ago class-give-html-elements.php 8 years ago class-give-license-handler.php 8 years ago class-give-logging.php 8 years ago class-give-readme-parser.php 8 years ago class-give-roles.php 8 years ago class-give-scripts.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 8 years ago country-functions.php 8 years ago currency-functions.php 8 years ago error-tracking.php 8 years ago filters.php 8 years ago formatting.php 8 years ago import-functions.php 8 years ago install.php 8 years ago login-register.php 8 years ago misc-functions.php 8 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 8 years ago process-donation.php 8 years ago shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
actions.php
453 lines
1 <?php
2 /**
3 * Front-end Actions
4 *
5 * @package Give
6 * @subpackage Functions
7 * @copyright Copyright (c) 2016, WordImpress
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 * Hooks Give actions, when present in the $_GET superglobal. Every give_action
19 * present in $_GET is called using WordPress's do_action function. These
20 * functions are called on init.
21 *
22 * @since 1.0
23 *
24 * @return void
25 */
26 function give_get_actions() {
27
28 $_get_action = ! empty( $_GET['give_action'] ) ? $_GET['give_action'] : null;
29
30 // Add backward compatibility to give-action param ( $_GET )
31 if ( empty( $_get_action ) ) {
32 $_get_action = ! empty( $_GET['give-action'] ) ? $_GET['give-action'] : null;
33 }
34
35 if ( isset( $_get_action ) ) {
36 /**
37 * Fires in WordPress init or admin init, when give_action is present in $_GET.
38 *
39 * @since 1.0
40 *
41 * @param array $_GET Array of HTTP GET variables.
42 */
43 do_action( "give_{$_get_action}", $_GET );
44 }
45
46 }
47
48 add_action( 'init', 'give_get_actions' );
49
50 /**
51 * Hooks Give actions, when present in the $_POST super global. Every give_action
52 * present in $_POST is called using WordPress's do_action function. These
53 * functions are called on init.
54 *
55 * @since 1.0
56 *
57 * @return void
58 */
59 function give_post_actions() {
60
61 $_post_action = ! empty( $_POST['give_action'] ) ? $_POST['give_action'] : null;
62
63 // Add backward compatibility to give-action param ( $_POST ).
64 if ( empty( $_post_action ) ) {
65 $_post_action = ! empty( $_POST['give-action'] ) ? $_POST['give-action'] : null;
66 }
67
68 if ( isset( $_post_action ) ) {
69 /**
70 * Fires in WordPress init or admin init, when give_action is present in $_POST.
71 *
72 * @since 1.0
73 *
74 * @param array $_POST Array of HTTP POST variables.
75 */
76 do_action( "give_{$_post_action}", $_POST );
77 }
78
79 }
80
81 add_action( 'init', 'give_post_actions' );
82
83 /**
84 * Connect WordPress user with Donor.
85 *
86 * @param int $user_id User ID.
87 * @param array $user_data User Data.
88 *
89 * @since 1.7
90 *
91 * @return void
92 */
93 function give_connect_donor_to_wpuser( $user_id, $user_data ) {
94 /* @var Give_Donor $donor */
95 $donor = new Give_Donor( $user_data['user_email'] );
96
97 // Validate donor id and check if do nor is already connect to wp user or not.
98 if ( $donor->id && ! $donor->user_id ) {
99
100 // Update donor user_id.
101 if ( $donor->update( array( 'user_id' => $user_id ) ) ) {
102 $donor_note = sprintf( esc_html__( 'WordPress user #%d is connected to #%d', 'give' ), $user_id, $donor->id );
103 $donor->add_note( $donor_note );
104
105 // Update user_id meta in payments.
106 // if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) {
107 // foreach ( $donations as $donation ) {
108 // give_update_meta( $donation, '_give_payment_user_id', $user_id );
109 // }
110 // }
111 // Do not need to update user_id in payment because we will get user id from donor id now.
112 }
113 }
114 }
115
116 add_action( 'give_insert_user', 'give_connect_donor_to_wpuser', 10, 2 );
117
118
119 /**
120 * Setup site home url check
121 *
122 * Note: if location of site changes then run cron to validate licenses
123 *
124 * @since 1.7
125 * @updated 1.8.15 - Resolved issue with endless looping because of URL mismatches.
126 * @return void
127 */
128 function give_validate_license_when_site_migrated() {
129 // Store current site address if not already stored.
130 $home_url_parts = parse_url( home_url() );
131 $home_url = isset( $home_url_parts['host'] ) ? $home_url_parts['host'] : false;
132 $home_url .= isset( $home_url_parts['path'] ) ? $home_url_parts['path'] : '';
133 $site_address_before_migrate = get_option( 'give_site_address_before_migrate' );
134
135 // Need $home_url to proceed.
136 if ( ! $home_url ) {
137 return;
138 }
139
140 // Save site address.
141 if ( ! $site_address_before_migrate ) {
142 // Update site address.
143 update_option( 'give_site_address_before_migrate', $home_url );
144
145 return;
146 }
147
148 // Backwards compat. for before when we were storing URL scheme.
149 if ( strpos( $site_address_before_migrate, 'http' ) ) {
150 $site_address_before_migrate = parse_url( $site_address_before_migrate );
151 $site_address_before_migrate = isset( $site_address_before_migrate['host'] ) ? $site_address_before_migrate['host'] : false;
152
153 // Add path for multisite installs.
154 $site_address_before_migrate .= isset( $site_address_before_migrate['path'] ) ? $site_address_before_migrate['path'] : '';
155 }
156
157 // If the two URLs don't match run CRON.
158 if ( $home_url !== $site_address_before_migrate ) {
159 // Immediately run cron.
160 wp_schedule_single_event( time(), 'give_validate_license_when_site_migrated' );
161
162 // Update site address.
163 update_option( 'give_site_address_before_migrate', $home_url );
164 }
165
166 }
167
168 add_action( 'admin_init', 'give_validate_license_when_site_migrated' );
169
170
171 /**
172 * Processing after donor batch export complete
173 *
174 * @since 1.8
175 *
176 * @param $data
177 */
178 function give_donor_batch_export_complete( $data ) {
179 // Remove donor ids cache.
180 if (
181 isset( $data['class'] )
182 && 'Give_Batch_Donors_Export' === $data['class']
183 && ! empty( $data['forms'] )
184 && isset( $data['give_export_option']['query_id'] )
185 ) {
186 Give_Cache::delete( Give_Cache::get_key( $data['give_export_option']['query_id'] ) );
187 }
188 }
189
190 add_action( 'give_file_export_complete', 'give_donor_batch_export_complete' );
191
192 /**
193 * Print css for wordpress setting pages.
194 *
195 * @since 1.8.7
196 */
197 function give_admin_quick_css() {
198 /* @var WP_Screen $screen */
199 $screen = get_current_screen();
200
201 if ( ! ( $screen instanceof WP_Screen ) ) {
202 return false;
203 }
204
205 switch ( true ) {
206 case ( 'plugins' === $screen->base || 'plugins-network' === $screen->base ):
207 ?>
208 <style>
209 tr.active.update + tr.give-addon-notice-tr td {
210 box-shadow: none;
211 -webkit-box-shadow: none;
212 }
213
214 tr.active + tr.give-addon-notice-tr td {
215 position: relative;
216 top: -1px;
217 }
218
219 tr.active + tr.give-addon-notice-tr .notice {
220 margin: 5px 20px 15px 40px;
221 }
222
223 tr.give-addon-notice-tr .dashicons {
224 color: #f56e28;
225 }
226
227 tr.give-addon-notice-tr td {
228 border-left: 4px solid #00a0d2;
229 }
230
231 tr.give-addon-notice-tr td {
232 padding: 0 !important;
233 }
234
235 tr.active.update + tr.give-addon-notice-tr .notice {
236 margin: 5px 20px 5px 40px;
237 }
238 </style>
239 <?php
240 }
241 }
242
243 add_action( 'admin_head', 'give_admin_quick_css' );
244
245
246 /**
247 * Set Donation Amount for Multi Level Donation Forms
248 *
249 * @param int $form_id Donation Form ID.
250 *
251 * @since 1.8.9
252 *
253 * @return void
254 */
255 function give_set_donation_levels_max_min_amount( $form_id ) {
256 if (
257 ( 'set' === $_POST['_give_price_option'] ) ||
258 ( in_array( '_give_donation_levels', $_POST ) && count( $_POST['_give_donation_levels'] ) <= 0 ) ||
259 ! ( $donation_levels_amounts = wp_list_pluck( $_POST['_give_donation_levels'], '_give_amount' ) )
260 ) {
261 // Delete old meta.
262 give_delete_meta( $form_id, '_give_levels_minimum_amount' );
263 give_delete_meta( $form_id, '_give_levels_maximum_amount' );
264
265 return;
266 }
267
268 // Sanitize donation level amounts.
269 $donation_levels_amounts = array_map( 'give_maybe_sanitize_amount', $donation_levels_amounts );
270
271 $min_amount = min( $donation_levels_amounts );
272 $max_amount = max( $donation_levels_amounts );
273
274 // Set Minimum and Maximum amount for Multi Level Donation Forms.
275 give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount_for_db( $min_amount ) : 0 );
276 give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount_for_db( $max_amount ) : 0 );
277 }
278
279 add_action( 'give_pre_process_give_forms_meta', 'give_set_donation_levels_max_min_amount', 30 );
280
281
282 /**
283 * Save donor address when donation complete
284 *
285 * @since 2.0
286 *
287 * @param int $payment_id
288 */
289 function _give_save_donor_billing_address( $payment_id ) {
290 $donor_id = absint( give_get_payment_donor_id( $payment_id ));
291
292 // Bailout
293 if ( ! $donor_id ) {
294 return;
295 }
296
297
298 /* @var Give_Donor $donor */
299 $donor = new Give_Donor( $donor_id );
300
301 // Save address.
302 $donor->add_address( 'billing[]', give_get_donation_address( $payment_id ) );
303 }
304
305 add_action( 'give_complete_donation', '_give_save_donor_billing_address', 9999 );
306
307
308 /**
309 * Update form id in payment logs
310 *
311 * @since 2.0
312 *
313 * @param array $args
314 */
315 function give_update_log_form_id( $args ) {
316 $new_form_id = absint( $args[0] );
317 $payment_id = absint( $args[1] );
318 $logs = Give()->logs->get_logs( $payment_id );
319
320 // Bailout.
321 if ( empty( $logs ) ) {
322 return;
323 }
324
325 /* @var object $log */
326 foreach ( $logs as $log ) {
327 Give()->logs->logmeta_db->update_meta( $log->ID, '_give_log_form_id', $new_form_id );
328 }
329
330 // Delete cache.
331 Give()->logs->delete_cache();
332 }
333
334 add_action( 'give_update_log_form_id', 'give_update_log_form_id' );
335
336 /**
337 * Verify addon dependency before addon update
338 *
339 * @since 2.1.4
340 *
341 * @param $error
342 * @param $hook_extra
343 *
344 * @return WP_Error
345 */
346 function __give_verify_addon_dependency_before_update( $error, $hook_extra ) {
347 // Bailout.
348 if ( is_wp_error( $error ) ) {
349 return $error;
350 }
351
352 $plugin_base = strtolower( $hook_extra['plugin'] );
353 $licensed_addon = array_map( 'strtolower', Give_License::get_licensed_addons() );
354
355 // Skip if not a Give addon.
356 if ( ! in_array( $plugin_base, $licensed_addon ) ) {
357 return $error;
358 }
359
360 $plugin_base = strtolower( $plugin_base );
361 $plugin_slug = str_replace( '.php', '', basename( $plugin_base ) );
362
363 /**
364 * Filter the addon readme.txt url
365 *
366 * @since 2.1.4
367 */
368 $url = apply_filters(
369 'give_addon_readme_file_url',
370 "https://givewp.com/downloads/plugins/{$plugin_slug}/readme.txt",
371 $plugin_slug
372 );
373
374 $parser = new Give_Readme_Parser( $url );
375 $give_min_version = $parser->requires_at_least();
376
377
378 if ( version_compare( GIVE_VERSION, $give_min_version, '<' ) ) {
379 return new WP_Error(
380 'Give_Addon_Update_Error',
381 sprintf(
382 __( 'Give version %s is required to update this add-on.', 'give' ),
383 $give_min_version
384 )
385 );
386 }
387
388 return $error;
389 }
390
391 add_filter( 'upgrader_pre_install', '__give_verify_addon_dependency_before_update', 10, 2 );
392
393 /**
394 * Function to add suppress_filters param if WPML add-on is activated.
395 *
396 * @since 2.1.4
397 *
398 * @param array WP query argument for Total Goal.
399 *
400 * @return array WP query argument for Total Goal.
401 */
402 function __give_wpml_total_goal_shortcode_agrs( $args ) {
403 $args['suppress_filters'] = true;
404
405 return $args;
406 }
407
408 /**
409 * Function to remove WPML post where filter in goal total amount shortcode.
410 *
411 * @since 2.1.4
412 * @global SitePress $sitepress
413 */
414 function __give_remove_wpml_parse_query_filter() {
415 global $sitepress;
416 remove_action('parse_query', array($sitepress, 'parse_query'));
417 }
418
419
420 /**
421 * Function to add WPML post where filter in goal total amount shortcode.
422 *
423 * @since 2.1.4
424 * @global SitePress $sitepress
425 */
426 function __give_add_wpml_parse_query_filter() {
427 global $sitepress;
428 add_action('parse_query', array($sitepress, 'parse_query'));
429 }
430
431 /**
432 * Action all the hook that add support for WPML.
433 *
434 * @since 2.1.4
435 */
436 function give_add_support_for_wpml() {
437 if ( ! function_exists( 'is_plugin_active' ) ) {
438 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
439 }
440
441
442 if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
443
444 add_filter( 'give_totals_goal_shortcode_query_args', '__give_wpml_total_goal_shortcode_agrs' );
445
446 // @see https://wpml.org/forums/topic/problem-with-query-filter-in-get_posts-function/#post-271309
447 add_action( 'give_totals_goal_shortcode_before_render', '__give_remove_wpml_parse_query_filter', 99 );
448 add_action( 'give_totals_goal_shortcode_after_render', '__give_add_wpml_parse_query_filter', 99 );
449 }
450 }
451
452 add_action( 'give_init', 'give_add_support_for_wpml', 1000 );
453