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/actions.php +70 -115 2.3.04.16.9 View file →
@@ -3,9 +3,9 @@
3 3 * Front-end Actions
4 4 *
5 5 * @package Give
6 6 * @subpackage Functions
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.0
10 10 */
11 11
@@ -13,9 +13,17 @@
13 13 if ( ! defined( 'ABSPATH' ) ) {
14 14 exit;
15 15 }
16 16
17 +
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 +/**
18 26 * Hooks Give actions, when present in the $_GET superglobal. Every give_action
19 27 * present in $_GET is called using WordPress's do_action function. These
20 28 * functions are called on init.
21 29 *
@@ -89,13 +97,18 @@
89 97 *
90 98 * @param int $user_id User ID.
91 99 * @param array $user_data User Data.
92 100 *
101 + * @since 4.16.6 Only auto-link when registered via the donation-checkout flow.
93 102 * @since 1.7
94 103 *
95 104 * @return void
96 105 */
97 106 function give_connect_donor_to_wpuser( $user_id, $user_data ) {
107 + if ( empty( $user_data['give_donation_checkout_registration'] ) ) {
108 + return;
109 + }
110 +
98 111 /* @var Give_Donor $donor */
99 112 $donor = new Give_Donor( $user_data['user_email'] );
100 113
101 114 // Validate donor id and check if do nor is already connect to wp user or not.
@@ -101,18 +114,18 @@
101 114 // Validate donor id and check if do nor is already connect to wp user or not.
102 115 if ( $donor->id && ! $donor->user_id ) {
103 116
104 117 // Update donor user_id.
105 - if ( $donor->update( array( 'user_id' => $user_id ) ) ) {
106 - $donor_note = sprintf( esc_html__( 'WordPress user #%d is connected to #%d', 'give' ), $user_id, $donor->id );
118 + if ( $donor->update( [ 'user_id' => $user_id ] ) ) {
119 + $donor_note = sprintf( esc_html__( 'WordPress user #%1$d is connected to #%2$d', 'give' ), $user_id, $donor->id );
107 120 $donor->add_note( $donor_note );
108 121
109 122 // Update user_id meta in payments.
110 123 // if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) {
111 - // foreach ( $donations as $donation ) {
112 - // give_update_meta( $donation, '_give_payment_user_id', $user_id );
113 - // }
124 + // foreach ( $donations as $donation ) {
125 + // give_update_meta( $donation, '_give_payment_user_id', $user_id );
114 126 // }
127 + // }
115 128 // Do not need to update user_id in payment because we will get user id from donor id now.
116 129 }
117 130 }
118 131 }
@@ -140,62 +153,9 @@
140 153 }
141 154
142 155 add_action( 'give_file_export_complete', 'give_donor_batch_export_complete' );
143 156
144 -/**
145 - * Print css for wordpress setting pages.
146 - *
147 - * @since 1.8.7
148 - */
149 -function give_admin_quick_css() {
150 - /* @var WP_Screen $screen */
151 - $screen = get_current_screen();
152 157
153 - if ( ! ( $screen instanceof WP_Screen ) ) {
154 - return false;
155 - }
156 -
157 - switch ( true ) {
158 - case ( 'plugins' === $screen->base || 'plugins-network' === $screen->base ):
159 - ?>
160 - <style>
161 - tr.active.update + tr.give-addon-notice-tr td {
162 - box-shadow: none;
163 - -webkit-box-shadow: none;
164 - }
165 -
166 - tr.active + tr.give-addon-notice-tr td {
167 - position: relative;
168 - top: -1px;
169 - }
170 -
171 - tr.active + tr.give-addon-notice-tr .notice {
172 - margin: 5px 20px 15px 40px;
173 - }
174 -
175 - tr.give-addon-notice-tr .dashicons {
176 - color: #f56e28;
177 - }
178 -
179 - tr.give-addon-notice-tr td {
180 - border-left: 4px solid #00a0d2;
181 - }
182 -
183 - tr.give-addon-notice-tr td {
184 - padding: 0 !important;
185 - }
186 -
187 - tr.active.update + tr.give-addon-notice-tr .notice {
188 - margin: 5px 20px 5px 40px;
189 - }
190 - </style>
191 - <?php
192 - }
193 -}
194 -
195 -add_action( 'admin_head', 'give_admin_quick_css' );
196 -
197 -
198 158 /**
199 159 * Set Donation Amount for Multi Level Donation Forms
200 160 *
201 161 * @param int $form_id Donation Form ID.
@@ -238,9 +198,9 @@
238 198 *
239 199 * @param int $payment_id
240 200 */
241 201 function _give_save_donor_billing_address( $payment_id ) {
242 - $donor_id = absint( give_get_payment_donor_id( $payment_id ));
202 + $donor_id = absint( give_get_payment_donor_id( $payment_id ) );
243 203
244 204 // Bailout
245 205 if ( ! $donor_id ) {
246 206 return;
@@ -245,9 +205,8 @@
245 205 if ( ! $donor_id ) {
246 206 return;
247 207 }
248 208
249 -
250 209 /* @var Give_Donor $donor */
251 210 $donor = new Give_Donor( $donor_id );
252 211
253 212 // Save address.
@@ -255,40 +214,13 @@
255 214 }
256 215
257 216 add_action( 'give_complete_donation', '_give_save_donor_billing_address', 9999 );
258 217
259 -
260 218 /**
261 - * Update form id in payment logs
262 - *
263 - * @since 2.0
264 - *
265 - * @param array $args
266 - */
267 -function give_update_log_form_id( $args ) {
268 - $new_form_id = absint( $args[0] );
269 - $payment_id = absint( $args[1] );
270 - $logs = Give()->logs->get_logs( $payment_id );
271 -
272 - // Bailout.
273 - if ( empty( $logs ) ) {
274 - return;
275 - }
276 -
277 - /* @var object $log */
278 - foreach ( $logs as $log ) {
279 - Give()->logs->logmeta_db->update_meta( $log->ID, '_give_log_form_id', $new_form_id );
280 - }
281 -
282 - // Delete cache.
283 - Give()->logs->delete_cache();
284 -}
285 -
286 -add_action( 'give_update_log_form_id', 'give_update_log_form_id' );
287 -
288 -/**
289 219 * Verify addon dependency before addon update
290 220 *
221 + * @since 4.9.0 rename function - PHP 8 compatibility
222 + * @since 4.1.0 add bailout for GiveWP to protect it from licensing issues
291 223 * @since 2.1.4
292 224 *
293 225 * @param $error
294 226 * @param $hook_extra
@@ -294,9 +226,9 @@
294 226 * @param $hook_extra
295 227 *
296 228 * @return WP_Error
297 229 */
298 -function __give_verify_addon_dependency_before_update( $error, $hook_extra ) {
230 +function give_verify_addon_dependency_before_update( $error, $hook_extra ) {
299 231 // Bailout.
300 232 if (
301 233 is_wp_error( $error )
302 234 || ! array_key_exists( 'plugin', $hook_extra )
@@ -303,9 +235,15 @@
303 235 ) {
304 236 return $error;
305 237 }
306 238
307 - $plugin_base = strtolower( $hook_extra['plugin'] );
239 + // If the plugin is GiveWP then bypass the License check altogether. If there's a problem with licensing it's
240 + // important that we can always upgrade GiveWP.
241 + $plugin_base = strtolower( $hook_extra['plugin'] );
242 + if ( GIVE_PLUGIN_BASENAME === $plugin_base ) {
243 + return $error;
244 + }
245 +
308 246 $licensed_addon = array_map( 'strtolower', Give_License::get_licensed_addons() );
309 247
310 248 // Skip if not a Give addon.
311 249 if ( ! in_array( $plugin_base, $licensed_addon ) ) {
@@ -311,31 +249,26 @@
311 249 if ( ! in_array( $plugin_base, $licensed_addon ) ) {
312 250 return $error;
313 251 }
314 252
253 + // Load file.
254 + if ( ! class_exists( 'Give_Readme_Parser' ) ) {
255 + require_once GIVE_PLUGIN_DIR . 'includes/class-give-readme-parser.php';
256 + }
257 +
315 258 $plugin_base = strtolower( $plugin_base );
316 259 $plugin_slug = str_replace( '.php', '', basename( $plugin_base ) );
317 260
318 - /**
319 - * Filter the addon readme.txt url
320 - *
321 - * @since 2.1.4
322 - */
323 - $url = apply_filters(
324 - 'give_addon_readme_file_url',
325 - "https://givewp.com/downloads/plugins/{$plugin_slug}/readme.txt",
326 - $plugin_slug
327 - );
261 + $url = give_get_addon_readme_url( $plugin_slug );
328 262
329 263 $parser = new Give_Readme_Parser( $url );
330 264 $give_min_version = $parser->requires_at_least();
331 265
332 -
333 266 if ( version_compare( GIVE_VERSION, $give_min_version, '<' ) ) {
334 267 return new WP_Error(
335 268 'Give_Addon_Update_Error',
336 269 sprintf(
337 - __( 'Give version %s is required to update this add-on.', 'give' ),
270 + __( 'GiveWP version %s is required to update this add-on.', 'give' ),
338 271 $give_min_version
339 272 )
340 273 );
341 274 }
@@ -342,13 +275,14 @@
342 275
343 276 return $error;
344 277 }
345 278
346 -add_filter( 'upgrader_pre_install', '__give_verify_addon_dependency_before_update', 10, 2 );
279 +add_filter( 'upgrader_pre_install', 'give_verify_addon_dependency_before_update', 10, 2 );
347 280
348 281 /**
349 282 * Function to add suppress_filters param if WPML add-on is activated.
350 283 *
284 + * @since 4.9.0 rename function - PHP 8 compatibility
351 285 * @since 2.1.4
352 286 *
353 287 * @param array WP query argument for Total Goal.
354 288 *
@@ -353,9 +287,9 @@
353 287 * @param array WP query argument for Total Goal.
354 288 *
355 289 * @return array WP query argument for Total Goal.
356 290 */
357 -function __give_wpml_total_goal_shortcode_agrs( $args ) {
291 +function give_wpml_total_goal_shortcode_agrs( $args ) {
358 292 $args['suppress_filters'] = true;
359 293
360 294 return $args;
361 295 }
@@ -362,14 +296,15 @@
362 296
363 297 /**
364 298 * Function to remove WPML post where filter in goal total amount shortcode.
365 299 *
300 + * @since 4.9.0 rename function - PHP 8 compatibility
366 301 * @since 2.1.4
367 302 * @global SitePress $sitepress
368 303 */
369 -function __give_remove_wpml_parse_query_filter() {
304 +function give_remove_wpml_parse_query_filter() {
370 305 global $sitepress;
371 - remove_action('parse_query', array($sitepress, 'parse_query'));
306 + remove_action( 'parse_query', [ $sitepress, 'parse_query' ] );
372 307 }
373 308
374 309
375 310 /**
@@ -374,14 +309,15 @@
374 309
375 310 /**
376 311 * Function to add WPML post where filter in goal total amount shortcode.
377 312 *
313 + * @since 4.9.0 rename function - PHP 8 compatibility
378 314 * @since 2.1.4
379 315 * @global SitePress $sitepress
380 316 */
381 -function __give_add_wpml_parse_query_filter() {
317 +function give_add_wpml_parse_query_filter() {
382 318 global $sitepress;
383 - add_action('parse_query', array($sitepress, 'parse_query'));
319 + add_action( 'parse_query', [ $sitepress, 'parse_query' ] );
384 320 }
385 321
386 322 /**
387 323 * Action all the hook that add support for WPML.
@@ -389,19 +325,38 @@
389 325 * @since 2.1.4
390 326 */
391 327 function give_add_support_for_wpml() {
392 328 if ( ! function_exists( 'is_plugin_active' ) ) {
393 - include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
329 + include_once ABSPATH . 'wp-admin/includes/plugin.php';
394 330 }
395 331
396 -
397 332 if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
398 333
399 - add_filter( 'give_totals_goal_shortcode_query_args', '__give_wpml_total_goal_shortcode_agrs' );
334 + add_filter( 'give_totals_goal_shortcode_query_args', 'give_wpml_total_goal_shortcode_agrs');
400 335
401 336 // @see https://wpml.org/forums/topic/problem-with-query-filter-in-get_posts-function/#post-271309
402 - add_action( 'give_totals_goal_shortcode_before_render', '__give_remove_wpml_parse_query_filter', 99 );
403 - add_action( 'give_totals_goal_shortcode_after_render', '__give_add_wpml_parse_query_filter', 99 );
337 + add_action( 'give_totals_goal_shortcode_before_render', 'give_remove_wpml_parse_query_filter', 99 );
338 + add_action( 'give_totals_goal_shortcode_after_render', 'give_add_wpml_parse_query_filter', 99 );
404 339 }
405 340 }
406 341
407 342 add_action( 'give_init', 'give_add_support_for_wpml', 1000 );
343 +
344 +/**
345 + * Backward compatibility for email_access property
346 + * Note: only for internal purpose
347 + *
348 + * @todo: Need to decide when to remove this backward compatibility.
349 + * 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
350 + * 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.
351 + * ref: https://github.com/impress-org/give/issues/4068
352 + *
353 + * @since 2.4.5
354 + */
355 +function give_set_email_access_property() {
356 + if ( ! ( Give()->email_access instanceof Give_Email_Access ) ) {
357 + require_once GIVE_PLUGIN_DIR . 'includes/class-give-email-access.php';
358 + Give()->email_access = new Give_Email_Access();
359 + }
360 +}
361 +add_action( 'give_email_links', 'give_set_email_access_property', -1 );
362 +add_action( 'give_donation-receipt_email_notification', 'give_set_email_access_property', -1 );