PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.2
GiveWP – Donation Plugin and Fundraising Platform v2.1.2
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 / class-give-cache.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-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
class-give-cache.php
808 lines
1 <?php
2 /**
3 * Class for managing cache
4 * Note: only use for internal purpose.
5 *
6 * @package Give
7 * @subpackage Classes/Give_Cache
8 * @copyright Copyright (c) 2017, WordImpress
9 * @license https://opensource.org/licenses/gpl-license GNU Public License
10 * @since 1.8.7
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 class Give_Cache {
19 /**
20 * Instance.
21 *
22 * @since 1.8.7
23 * @access private
24 * @var Give_Cache
25 */
26 static private $instance;
27
28 /**
29 * Flag to check if caching enabled or not.
30 *
31 * @since 2.0
32 * @access private
33 * @var
34 */
35 private $is_cache;
36
37 /**
38 * Singleton pattern.
39 *
40 * @since 1.8.7
41 * @access private
42 * Give_Cache constructor.
43 */
44 private function __construct() {
45 }
46
47
48 /**
49 * Get instance.
50 *
51 * @since 1.8.7
52 * @access public
53 * @return static
54 */
55 public static function get_instance() {
56 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Give_Cache ) ) {
57 self::$instance = new Give_Cache();
58 }
59
60 return self::$instance;
61 }
62
63 /**
64 * Setup hooks.
65 *
66 * @since 1.8.7
67 * @access public
68 */
69 public function setup() {
70 // Currently enable cache only for backend.
71 self::$instance->is_cache = ( defined( 'GIVE_CACHE' ) ? GIVE_CACHE : give_is_setting_enabled( give_get_option( 'cache', 'enabled' ) ) ) && is_admin();
72
73 // weekly delete all expired cache.
74 Give_Cron::add_weekly_event( array( $this, 'delete_all_expired' ) );
75
76 add_action( 'save_post_give_forms', array( $this, 'delete_form_related_cache' ) );
77 add_action( 'save_post_give_payment', array( $this, 'delete_payment_related_cache' ) );
78 add_action( 'give_deleted_give-donors_cache', array( $this, 'delete_donor_related_cache' ), 10, 3 );
79 add_action( 'give_deleted_give-donations_cache', array( $this, 'delete_donations_related_cache' ), 10, 3 );
80
81 add_action( 'give_save_settings_give_settings', array( __CLASS__, 'flush_cache' ) );
82
83 add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
84 add_action( 'admin_notices', array( $this, '__notices' ) );
85 }
86
87 /**
88 * Prevent caching on certain pages
89 *
90 * @since 2.0.5
91 * @access public
92 * @credit WooCommerce
93 */
94 public static function prevent_caching() {
95 if ( ! is_blog_installed() ) {
96 return;
97 }
98
99 $page_ids = array_filter( array(
100 give_get_option( 'success_page' ),
101 give_get_option( 'failure_page' ),
102 give_get_option( 'history_page' ),
103 ) );
104
105 if (
106 is_page( $page_ids )
107 || is_singular( 'give_forms' )
108 ) {
109 self::set_nocache_constants();
110 nocache_headers();
111 }
112 }
113
114 /**
115 * Set constants to prevent caching by some plugins.
116 *
117 * @since 2.0.5
118 * @access public
119 * @credit WooCommerce
120 *
121 * @param mixed $return Value to return. Previously hooked into a filter.
122 *
123 * @return mixed
124 */
125 public static function set_nocache_constants( $return = true ) {
126 give_maybe_define_constant( 'DONOTCACHEPAGE', true );
127 give_maybe_define_constant( 'DONOTCACHEOBJECT', true );
128 give_maybe_define_constant( 'DONOTCACHEDB', true );
129
130 return $return;
131 }
132
133 /**
134 * Notices function.
135 *
136 * @since 2.0.5
137 * @access public
138 * @credit WooCommerce
139 */
140 public function __notices() {
141 if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
142 return;
143 }
144
145 $config = w3_instance( 'W3_Config' );
146 $enabled = $config->get_integer( 'dbcache.enabled' );
147 $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
148
149 if ( $enabled && ! in_array( 'give', $settings, true ) ) {
150 ?>
151 <div class="error">
152 <p><?php echo wp_kses_post( sprintf( __( 'In order for <strong>database caching</strong> to work with Give you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'give' ), '<code>give</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache' ) ) ) ); ?></p>
153 </div>
154 <?php
155 }
156 }
157
158 /**
159 * Get cache key.
160 *
161 * @since 1.8.7
162 *
163 * @param string $action Cache key prefix.
164 * @param array $query_args (optional) Query array.
165 * @param bool $is_prefix
166 *
167 * @return string
168 */
169 public static function get_key( $action, $query_args = null, $is_prefix = true ) {
170 // Bailout.
171 if ( empty( $action ) ) {
172 return new WP_Error( 'give_invalid_cache_key_action', __( 'Do not pass empty action to generate cache key.', 'give' ) );
173 }
174
175 // Set cache key.
176 $cache_key = $is_prefix ? "give_cache_{$action}" : $action;
177
178 // Bailout.
179 if ( ! empty( $query_args ) ) {
180 $cache_key = "{$cache_key}_" . substr( md5( serialize( $query_args ) ), 0, 15 );
181 }
182
183 /**
184 * Filter the cache key name.
185 *
186 * @since 2.0
187 */
188 return apply_filters( 'give_get_cache_key', $cache_key, $action, $query_args );
189 }
190
191 /**
192 * Get cache.
193 *
194 * @since 1.8.7
195 *
196 * @param string $cache_key
197 * @param bool $custom_key
198 * @param mixed $query_args
199 *
200 * @return mixed
201 */
202 public static function get( $cache_key, $custom_key = false, $query_args = array() ) {
203 if ( ! self::is_valid_cache_key( $cache_key ) ) {
204 if ( ! $custom_key ) {
205 return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) );
206 }
207
208 $cache_key = self::get_key( $cache_key, $query_args );
209 }
210
211 $option = get_option( $cache_key );
212
213 // Backward compatibility (<1.8.7).
214 if ( ! is_array( $option ) || empty( $option ) || ! array_key_exists( 'expiration', $option ) ) {
215 return $option;
216 }
217
218 // Get current time.
219 $current_time = current_time( 'timestamp', 1 );
220
221 if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) {
222 $option = $option['data'];
223 } else {
224 $option = false;
225 }
226
227 return $option;
228 }
229
230 /**
231 * Set cache.
232 *
233 * @since 1.8.7
234 *
235 * @param string $cache_key
236 * @param mixed $data
237 * @param int|null $expiration Timestamp should be in GMT format.
238 * @param bool $custom_key
239 * @param mixed $query_args
240 *
241 * @return mixed
242 */
243 public static function set( $cache_key, $data, $expiration = null, $custom_key = false, $query_args = array() ) {
244 if ( ! self::is_valid_cache_key( $cache_key ) ) {
245 if ( ! $custom_key ) {
246 return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) );
247 }
248
249 $cache_key = self::get_key( $cache_key, $query_args );
250 }
251
252 $option_value = array(
253 'data' => $data,
254 'expiration' => ! is_null( $expiration )
255 ? ( $expiration + current_time( 'timestamp', 1 ) )
256 : null,
257 );
258
259 $result = update_option( $cache_key, $option_value, 'no' );
260
261 return $result;
262 }
263
264 /**
265 * Delete cache.
266 *
267 * Note: only for internal use
268 *
269 * @since 1.8.7
270 *
271 * @param string|array $cache_keys
272 *
273 * @return bool|WP_Error
274 */
275 public static function delete( $cache_keys ) {
276 $result = true;
277 $invalid_keys = array();
278
279 if ( ! empty( $cache_keys ) ) {
280 $cache_keys = is_array( $cache_keys ) ? $cache_keys : array( $cache_keys );
281
282 foreach ( $cache_keys as $cache_key ) {
283 if ( ! self::is_valid_cache_key( $cache_key ) ) {
284 $invalid_keys[] = $cache_key;
285 $result = false;
286 }
287
288 delete_option( $cache_key );
289 }
290 }
291
292 if ( ! $result ) {
293 $result = new WP_Error(
294 'give_invalid_cache_key',
295 __( 'Cache key format should be give_cache_*', 'give' ),
296 $invalid_keys
297 );
298 }
299
300 return $result;
301 }
302
303 /**
304 * Delete all logging cache.
305 *
306 * Note: only for internal use
307 *
308 * @since 1.8.7
309 * @access public
310 * @global wpdb $wpdb
311 *
312 * @param bool $force If set to true then all cached values will be delete instead of only expired
313 *
314 * @return bool
315 */
316 public static function delete_all_expired( $force = false ) {
317 global $wpdb;
318 $options = $wpdb->get_results(
319 $wpdb->prepare(
320 "SELECT option_name, option_value
321 FROM {$wpdb->options}
322 Where option_name
323 LIKE '%%%s%%'",
324 'give_cache'
325 ),
326 ARRAY_A
327 );
328
329 // Bailout.
330 if ( empty( $options ) ) {
331 return false;
332 }
333
334 $current_time = current_time( 'timestamp', 1 );
335
336 // Delete log cache.
337 foreach ( $options as $option ) {
338 $option['option_value'] = maybe_unserialize( $option['option_value'] );
339
340 if (
341 (
342 ! self::is_valid_cache_key( $option['option_name'] )
343 || ! is_array( $option['option_value'] ) // Backward compatibility (<1.8.7).
344 || ! array_key_exists( 'expiration', $option['option_value'] ) // Backward compatibility (<1.8.7).
345 || empty( $option['option_value']['expiration'] )
346 || ( $current_time < $option['option_value']['expiration'] )
347 )
348 && ! $force
349 ) {
350 continue;
351 }
352
353 self::delete( $option['option_name'] );
354 }
355 }
356
357
358 /**
359 * Get list of options like.
360 *
361 * Note: only for internal use
362 *
363 * @since 1.8.7
364 * @access public
365 *
366 * @param string $option_name
367 * @param bool $fields
368 *
369 * @return array
370 */
371 public static function get_options_like( $option_name, $fields = false ) {
372 global $wpdb;
373
374 $field_names = $fields ? 'option_name, option_value' : 'option_name';
375
376 if ( $fields ) {
377 $options = $wpdb->get_results(
378 $wpdb->prepare(
379 "SELECT {$field_names }
380 FROM {$wpdb->options}
381 Where option_name
382 LIKE '%%%s%%'",
383 "give_cache_{$option_name}"
384 ),
385 ARRAY_A
386 );
387 } else {
388 $options = $wpdb->get_col(
389 $wpdb->prepare(
390 "SELECT *
391 FROM {$wpdb->options}
392 Where option_name
393 LIKE '%%%s%%'",
394 "give_cache_{$option_name}"
395 ),
396 1
397 );
398 }
399
400 if ( ! empty( $options ) && $fields ) {
401 foreach ( $options as $index => $option ) {
402 $option['option_value'] = maybe_unserialize( $option['option_value'] );
403 $options[ $index ] = $option;
404 }
405 }
406
407 return $options;
408 }
409
410 /**
411 * Check cache key validity.
412 *
413 * @since 1.8.7
414 * @access public
415 *
416 * @param $cache_key
417 *
418 * @return bool
419 */
420 public static function is_valid_cache_key( $cache_key ) {
421 $is_valid = ( false !== strpos( $cache_key, 'give_cache_' ) );
422
423
424 /**
425 * Filter the flag which tell about cache key valid or not
426 *
427 * @since 2.0
428 */
429 return apply_filters( 'give_is_valid_cache_key', $is_valid, $cache_key );
430 }
431
432
433 /**
434 * Get cache from group
435 *
436 * @since 2.0
437 * @access public
438 *
439 * @param int $id
440 * @param string $group
441 *
442 * @return mixed
443 */
444 public static function get_group( $id, $group = '' ) {
445 $cached_data = null;
446
447 // Bailout.
448 if ( self::$instance->is_cache && ! empty( $id ) ) {
449 $group = self::$instance->filter_group_name( $group );
450
451 $cached_data = wp_cache_get( $id, $group );
452 $cached_data = false !== $cached_data ? $cached_data : null;
453 }
454
455 return $cached_data;
456 }
457
458 /**
459 * Cache small chunks inside group
460 *
461 * @since 2.0
462 * @access public
463 *
464 * @param int $id
465 * @param mixed $data
466 * @param string $group
467 * @param int $expire
468 *
469 * @return bool
470 */
471 public static function set_group( $id, $data, $group = '', $expire = 0 ) {
472 $status = false;
473
474 // Bailout.
475 if ( ! self::$instance->is_cache || empty( $id ) ) {
476 return $status;
477 }
478
479 $group = self::$instance->filter_group_name( $group );
480
481 $status = wp_cache_set( $id, $data, $group, $expire );
482
483 return $status;
484 }
485
486 /**
487 * Cache small db query chunks inside group
488 *
489 * @since 2.0
490 * @access public
491 *
492 * @param int $id
493 * @param mixed $data
494 *
495 * @return bool
496 */
497 public static function set_db_query( $id, $data ) {
498 $status = false;
499
500 // Bailout.
501 if ( ! self::$instance->is_cache || empty( $id ) ) {
502 return $status;
503 }
504
505 return self::set_group( $id, $data, 'give-db-queries', 0 );
506 }
507
508 /**
509 * Get cache from group
510 *
511 * @since 2.0
512 * @access public
513 *
514 * @param string $id
515 *
516 * @return mixed
517 */
518 public static function get_db_query( $id ) {
519 return self::get_group( $id, 'give-db-queries' );
520 }
521
522 /**
523 * Delete group cache
524 *
525 * @since 2.0
526 * @access public
527 *
528 * @param int|array $ids
529 * @param string $group
530 * @param int $expire
531 *
532 * @return bool
533 */
534 public static function delete_group( $ids, $group = '', $expire = 0 ) {
535 $status = false;
536
537 // Bailout.
538 if ( ! self::$instance->is_cache || empty( $ids ) ) {
539 return $status;
540 }
541
542 $group_prefix = $group;
543 $group = self::$instance->filter_group_name( $group );
544
545 // Delete single or multiple cache items from cache.
546 if ( ! is_array( $ids ) ) {
547 $status = wp_cache_delete( $ids, $group );
548 self::$instance->get_incrementer( true );
549
550 /**
551 * Fire action when cache deleted for specific id.
552 *
553 * @since 2.0
554 *
555 * @param string $ids
556 * @param string $group
557 * @param int $expire
558 */
559 do_action( "give_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status );
560
561 } else {
562 foreach ( $ids as $id ) {
563 $status = wp_cache_delete( $id, $group );
564 self::$instance->get_incrementer( true );
565
566 /**
567 * Fire action when cache deleted for specific id .
568 *
569 * @since 2.0
570 *
571 * @param string $ids
572 * @param string $group
573 * @param int $expire
574 */
575 do_action( "give_deleted_{$group_prefix}_cache", $id, $group, $expire, $status );
576 }
577 }
578
579 return $status;
580 }
581
582
583 /**
584 * Delete form related cache
585 * Note: only use for internal purpose.
586 *
587 * @since 2.0
588 * @access public
589 *
590 * @param int $form_id
591 */
592 public function delete_form_related_cache( $form_id ) {
593 // If this is just a revision, don't send the email.
594 if ( wp_is_post_revision( $form_id ) ) {
595 return;
596 }
597
598 $donation_query = new Give_Payments_Query(
599 array(
600 'number' => - 1,
601 'give_forms' => $form_id,
602 'output' => '',
603 'fields' => 'ids',
604 )
605 );
606
607 $donations = $donation_query->get_payments();
608
609 if ( ! empty( $donations ) ) {
610 /* @var Give_Payment $donation */
611 foreach ( $donations as $donation_id ) {
612 wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) );
613 wp_cache_delete( give_get_payment_donor_id( $donation_id ), $this->filter_group_name( 'give-donors' ) );
614 }
615 }
616
617 self::$instance->get_incrementer( true );
618 }
619
620 /**
621 * Delete payment related cache
622 * Note: only use for internal purpose.
623 *
624 * @since 2.0
625 * @access public
626 *
627 * @param int $donation_id
628 */
629 public function delete_payment_related_cache( $donation_id ) {
630 // If this is just a revision, don't send the email.
631 if ( wp_is_post_revision( $donation_id ) ) {
632 return;
633 }
634
635 if ( $donation_id && ( $donor_id = give_get_payment_donor_id( $donation_id ) ) ) {
636 wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) );
637 }
638
639 wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) );
640
641 self::$instance->get_incrementer( true );
642 }
643
644 /**
645 * Delete donor related cache
646 * Note: only use for internal purpose.
647 *
648 * @since 2.0
649 * @access public
650 *
651 * @param string $id
652 * @param string $group
653 * @param int $expire
654 */
655 public function delete_donor_related_cache( $id, $group, $expire ) {
656 $donation_ids = Give()->donors->get_column( 'payment_ids', $id );
657
658 if ( ! empty( $donation_ids ) ) {
659 $donation_ids = array_map( 'trim', (array) explode( ',', trim( $donation_ids ) ) );
660
661 foreach ( $donation_ids as $donation ) {
662 wp_cache_delete( $donation, $this->filter_group_name( 'give-donations' ) );
663 }
664 }
665
666 self::$instance->get_incrementer( true );
667 }
668
669 /**
670 * Delete donations related cache
671 * Note: only use for internal purpose.
672 *
673 * @since 2.0
674 * @access public
675 *
676 * @param string $id
677 * @param string $group
678 * @param int $expire
679 */
680 public function delete_donations_related_cache( $id, $group, $expire ) {
681 if ( $id && ( $donor_id = give_get_payment_donor_id( $id ) ) ) {
682 wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) );
683 }
684
685 self::$instance->get_incrementer( true );
686 }
687
688
689 /**
690 * Get unique incrementer.
691 *
692 * @see https://core.trac.wordpress.org/ticket/4476
693 * @see https://www.tollmanz.com/invalidation-schemes/
694 *
695 * @since 2.0
696 * @access public
697 *
698 * @param bool $refresh
699 * @param string $incrementer_key
700 *
701 * @return string
702 */
703 public function get_incrementer( $refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries' ) {
704 $incrementer_value = wp_cache_get( $incrementer_key );
705
706 if ( false === $incrementer_value || true === $refresh ) {
707 $incrementer_value = microtime( true );
708 wp_cache_set( $incrementer_key, $incrementer_value );
709 }
710
711 return $incrementer_value;
712 }
713
714
715 /**
716 * Flush cache on cache setting enable/disable
717 * Note: only for internal use
718 *
719 * @since 2.0
720 * @access public
721 */
722 public static function flush_cache() {
723 if (
724 ( Give_Admin_Settings::is_saving_settings()
725 && isset( $_POST['cache'] )
726 && give_is_setting_enabled( give_clean( $_POST['cache'] ) )
727 )
728 || ( wp_doing_ajax() && 'give_cache_flush' === give_clean( $_GET['action'] ) )
729 ) {
730 self::$instance->get_incrementer( true );
731 self::$instance->get_incrementer( true, 'give-cache-incrementer' );
732
733 /**
734 * Fire the action when all cache deleted.
735 *
736 * @since 2.1.0
737 */
738 do_action( 'give_fluched_cache' );
739
740 return true;
741 }
742
743 return false;
744 }
745
746
747 /**
748 * Filter the group name
749 *
750 * @since 2.0
751 * @access private
752 *
753 * @param $group
754 *
755 * @return mixed
756 */
757 private function filter_group_name( $group ) {
758 /**
759 * Filter the group name
760 *
761 * @since 2.1.0
762 */
763 $filtered_group = apply_filters( 'give_cache_filter_group_name', '', $group );
764
765 if ( empty( $filtered_group ) ) {
766
767 switch ( $group ) {
768 case 'give-db-queries':
769 $incrementer = self::$instance->get_incrementer();
770 break;
771
772 default:
773 $incrementer = self::$instance->get_incrementer( false, 'give-cache-incrementer' );
774
775 }
776
777 $currenct_blog_id = get_current_blog_id();
778 $filtered_group = "{$group}_{$currenct_blog_id}_{$incrementer}";
779 }
780
781 return $filtered_group;
782 }
783
784
785 /**
786 * Disable cache.
787 *
788 * @since 2.0
789 * @access public
790 */
791 public static function disable() {
792 self::get_instance()->is_cache = false;
793 }
794
795 /**
796 * Enable cache.
797 *
798 * @since 2.0
799 * @access public
800 */
801 public static function enable() {
802 self::get_instance()->is_cache = true;
803 }
804 }
805
806 // Initialize
807 Give_Cache::get_instance()->setup();
808