PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.13
GiveWP – Donation Plugin and Fundraising Platform v2.5.13
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 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 7 years ago gateways 6 years ago libraries 7 years ago payments 6 years ago actions.php 6 years ago ajax-functions.php 6 years ago class-give-async-process.php 7 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 7 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 7 years ago class-give-license-handler.php 6 years ago class-give-logging.php 7 years ago class-give-readme-parser.php 7 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 7 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 7 years ago class-give-translation.php 8 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 7 years ago filters.php 7 years ago formatting.php 6 years ago install.php 6 years ago login-register.php 7 years ago misc-functions.php 6 years ago plugin-compatibility.php 6 years ago post-types.php 6 years ago price-functions.php 7 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
class-give-cache.php
793 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, GiveWP
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 GiveWP you must add %1$s to the "Ignored query stems" option in <a href="%2$s">W3 Total Cache settings</a>.', 'give' ), '<code>give</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache#dbcache_reject_sql' ) ) ) ); ?></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( empty( $cache_key ) ) {
205 return new WP_Error( 'give_empty_cache_key', __( 'Do not pass invalid empty cache key', 'give' ) );
206 }elseif ( ! $custom_key ) {
207 return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) );
208 }
209
210 $cache_key = self::get_key( $cache_key, $query_args );
211 }
212
213 $option = get_option( $cache_key );
214
215 // Backward compatibility (<1.8.7).
216 if ( ! is_array( $option ) || empty( $option ) || ! array_key_exists( 'expiration', $option ) ) {
217 return $option;
218 }
219
220 // Get current time.
221 $current_time = current_time( 'timestamp', 1 );
222
223 if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) {
224 $option = $option['data'];
225 } else {
226 $option = false;
227 }
228
229 return $option;
230 }
231
232 /**
233 * Set cache.
234 *
235 * @since 1.8.7
236 *
237 * @param string $cache_key
238 * @param mixed $data
239 * @param int|null $expiration Timestamp should be in GMT format.
240 * @param bool $custom_key
241 * @param mixed $query_args
242 *
243 * @return mixed
244 */
245 public static function set( $cache_key, $data, $expiration = null, $custom_key = false, $query_args = array() ) {
246 if ( ! self::is_valid_cache_key( $cache_key ) ) {
247 if ( ! $custom_key ) {
248 return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) );
249 }
250
251 $cache_key = self::get_key( $cache_key, $query_args );
252 }
253
254 $option_value = array(
255 'data' => $data,
256 'expiration' => ! is_null( $expiration )
257 ? ( $expiration + current_time( 'timestamp', 1 ) )
258 : null,
259 );
260
261 $result = update_option( $cache_key, $option_value, false );
262
263 return $result;
264 }
265
266 /**
267 * Delete cache.
268 *
269 * Note: only for internal use
270 *
271 * @since 1.8.7
272 *
273 * @param string|array $cache_keys
274 *
275 * @return bool|WP_Error
276 */
277 public static function delete( $cache_keys ) {
278 $result = true;
279 $invalid_keys = array();
280
281 if ( ! empty( $cache_keys ) ) {
282 $cache_keys = is_array( $cache_keys ) ? $cache_keys : array( $cache_keys );
283
284 foreach ( $cache_keys as $cache_key ) {
285 if ( ! self::is_valid_cache_key( $cache_key ) ) {
286 $invalid_keys[] = $cache_key;
287 $result = false;
288 }
289
290 delete_option( $cache_key );
291 }
292 }
293
294 if ( ! $result ) {
295 $result = new WP_Error(
296 'give_invalid_cache_key',
297 __( 'Cache key format should be give_cache_*', 'give' ),
298 $invalid_keys
299 );
300 }
301
302 return $result;
303 }
304
305 /**
306 * Delete all logging cache.
307 *
308 * Note: only for internal use
309 *
310 * @since 1.8.7
311 * @access public
312 * @global wpdb $wpdb
313 *
314 * @param bool $force If set to true then all cached values will be delete instead of only expired
315 *
316 * @return bool
317 */
318 public static function delete_all_expired( $force = false ) {
319 global $wpdb;
320 $options = $wpdb->get_results(
321 $wpdb->prepare(
322 "SELECT option_name, option_value
323 FROM {$wpdb->options}
324 Where option_name
325 LIKE '%%%s%%'",
326 'give_cache'
327 ),
328 ARRAY_A
329 );
330
331 // Bailout.
332 if ( empty( $options ) ) {
333 return false;
334 }
335
336 $current_time = current_time( 'timestamp', 1 );
337
338 // Delete log cache.
339 foreach ( $options as $option ) {
340 $option['option_value'] = maybe_unserialize( $option['option_value'] );
341
342 if (
343 (
344 ! self::is_valid_cache_key( $option['option_name'] )
345 || ! is_array( $option['option_value'] ) // Backward compatibility (<1.8.7).
346 || ! array_key_exists( 'expiration', $option['option_value'] ) // Backward compatibility (<1.8.7).
347 || empty( $option['option_value']['expiration'] )
348 || ( $current_time < $option['option_value']['expiration'] )
349 )
350 && ! $force
351 ) {
352 continue;
353 }
354
355 self::delete( $option['option_name'] );
356 }
357 }
358
359
360 /**
361 * Get list of options like.
362 *
363 * Note: only for internal use
364 *
365 * @since 1.8.7
366 * @access public
367 *
368 * @param string $option_name
369 * @param bool $fields
370 *
371 * @return array
372 */
373 public static function get_options_like( $option_name, $fields = false ) {
374 global $wpdb;
375
376 $field_names = $fields ? 'option_name, option_value' : 'option_name';
377
378 if ( $fields ) {
379 $options = $wpdb->get_results(
380 $wpdb->prepare(
381 "SELECT {$field_names }
382 FROM {$wpdb->options}
383 Where option_name
384 LIKE '%%%s%%'",
385 "give_cache_{$option_name}"
386 ),
387 ARRAY_A
388 );
389 } else {
390 $options = $wpdb->get_col(
391 $wpdb->prepare(
392 "SELECT *
393 FROM {$wpdb->options}
394 Where option_name
395 LIKE '%%%s%%'",
396 "give_cache_{$option_name}"
397 ),
398 1
399 );
400 }
401
402 if ( ! empty( $options ) && $fields ) {
403 foreach ( $options as $index => $option ) {
404 $option['option_value'] = maybe_unserialize( $option['option_value'] );
405 $options[ $index ] = $option;
406 }
407 }
408
409 return $options;
410 }
411
412 /**
413 * Check cache key validity.
414 *
415 * @since 1.8.7
416 * @access public
417 *
418 * @param $cache_key
419 *
420 * @return bool
421 */
422 public static function is_valid_cache_key( $cache_key ) {
423 $is_valid = ( false !== strpos( $cache_key, 'give_cache_' ) );
424
425
426 /**
427 * Filter the flag which tell about cache key valid or not
428 *
429 * @since 2.0
430 */
431 return apply_filters( 'give_is_valid_cache_key', $is_valid, $cache_key );
432 }
433
434
435 /**
436 * Get cache from group
437 *
438 * @since 2.0
439 * @access public
440 *
441 * @param int $id
442 * @param string $group
443 *
444 * @return mixed
445 */
446 public static function get_group( $id, $group = '' ) {
447 $cached_data = null;
448
449 // Bailout.
450 if ( self::$instance->is_cache && ! empty( $id ) ) {
451 $group = self::$instance->filter_group_name( $group );
452
453 $cached_data = wp_cache_get( $id, $group );
454 $cached_data = false !== $cached_data ? $cached_data : null;
455 }
456
457 return $cached_data;
458 }
459
460 /**
461 * Cache small chunks inside group
462 *
463 * @since 2.0
464 * @access public
465 *
466 * @param int $id
467 * @param mixed $data
468 * @param string $group
469 * @param int $expire
470 *
471 * @return bool
472 */
473 public static function set_group( $id, $data, $group = '', $expire = 0 ) {
474 $status = false;
475
476 // Bailout.
477 if ( ! self::$instance->is_cache || empty( $id ) ) {
478 return $status;
479 }
480
481 $group = self::$instance->filter_group_name( $group );
482
483 $status = wp_cache_set( $id, $data, $group, $expire );
484
485 return $status;
486 }
487
488 /**
489 * Cache small db query chunks inside group
490 *
491 * @since 2.0
492 * @access public
493 *
494 * @param int $id
495 * @param mixed $data
496 *
497 * @return bool
498 */
499 public static function set_db_query( $id, $data ) {
500 $status = false;
501
502 // Bailout.
503 if ( ! self::$instance->is_cache || empty( $id ) ) {
504 return $status;
505 }
506
507 return self::set_group( $id, $data, 'give-db-queries', 0 );
508 }
509
510 /**
511 * Get cache from group
512 *
513 * @since 2.0
514 * @access public
515 *
516 * @param string $id
517 *
518 * @return mixed
519 */
520 public static function get_db_query( $id ) {
521 return self::get_group( $id, 'give-db-queries' );
522 }
523
524 /**
525 * Delete group cache
526 *
527 * @since 2.0
528 * @access public
529 *
530 * @param int|array $ids
531 * @param string $group
532 * @param int $expire
533 *
534 * @return bool
535 */
536 public static function delete_group( $ids, $group = '', $expire = 0 ) {
537 $status = false;
538
539 // Bailout.
540 if ( ! self::$instance->is_cache || empty( $ids ) ) {
541 return $status;
542 }
543
544 $group_prefix = $group;
545 $group = self::$instance->filter_group_name( $group );
546
547 // Delete single or multiple cache items from cache.
548 if ( ! is_array( $ids ) ) {
549 $status = wp_cache_delete( $ids, $group );
550 self::$instance->get_incrementer( true );
551
552 /**
553 * Fire action when cache deleted for specific id.
554 *
555 * @since 2.0
556 *
557 * @param string $ids
558 * @param string $group
559 * @param int $expire
560 */
561 do_action( "give_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status );
562
563 } else {
564 foreach ( $ids as $id ) {
565 $status = wp_cache_delete( $id, $group );
566 self::$instance->get_incrementer( true );
567
568 /**
569 * Fire action when cache deleted for specific id .
570 *
571 * @since 2.0
572 *
573 * @param string $ids
574 * @param string $group
575 * @param int $expire
576 */
577 do_action( "give_deleted_{$group_prefix}_cache", $id, $group, $expire, $status );
578 }
579 }
580
581 return $status;
582 }
583
584
585 /**
586 * Delete form related cache
587 * Note: only use for internal purpose.
588 *
589 * @since 2.0
590 * @access public
591 *
592 * @param int $form_id
593 */
594 public function delete_form_related_cache( $form_id ) {
595 // If this is just a revision, don't send the email.
596 if ( wp_is_post_revision( $form_id ) ) {
597 return;
598 }
599
600 self::flush_cache(true );
601 }
602
603 /**
604 * Delete payment related cache
605 * Note: only use for internal purpose.
606 *
607 * @since 2.0
608 * @access public
609 *
610 * @param int $donation_id
611 */
612 public function delete_payment_related_cache( $donation_id ) {
613 // If this is just a revision, don't send the email.
614 if ( wp_is_post_revision( $donation_id ) ) {
615 return;
616 }
617
618 if ( $donation_id && ( $donor_id = give_get_payment_donor_id( $donation_id ) ) ) {
619 wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) );
620 }
621
622 wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) );
623
624 self::$instance->get_incrementer( true );
625 }
626
627 /**
628 * Delete donor related cache
629 * Note: only use for internal purpose.
630 *
631 * @since 2.0
632 * @access public
633 *
634 * @param string $id
635 * @param string $group
636 * @param int $expire
637 */
638 public function delete_donor_related_cache( $id, $group, $expire ) {
639 $donation_ids = Give()->donors->get_column( 'payment_ids', $id );
640
641 if ( ! empty( $donation_ids ) ) {
642 $donation_ids = array_map( 'trim', (array) explode( ',', trim( $donation_ids ) ) );
643
644 foreach ( $donation_ids as $donation ) {
645 wp_cache_delete( $donation, $this->filter_group_name( 'give-donations' ) );
646 }
647 }
648
649 self::$instance->get_incrementer( true );
650 }
651
652 /**
653 * Delete donations related cache
654 * Note: only use for internal purpose.
655 *
656 * @since 2.0
657 * @access public
658 *
659 * @param string $id
660 * @param string $group
661 * @param int $expire
662 */
663 public function delete_donations_related_cache( $id, $group, $expire ) {
664 if ( $id && ( $donor_id = give_get_payment_donor_id( $id ) ) ) {
665 wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) );
666 }
667
668 self::$instance->get_incrementer( true );
669 }
670
671
672 /**
673 * Get unique incrementer.
674 *
675 * @see https://core.trac.wordpress.org/ticket/4476
676 * @see https://www.tollmanz.com/invalidation-schemes/
677 *
678 * @since 2.0
679 * @access public
680 *
681 * @param bool $refresh
682 * @param string $incrementer_key
683 *
684 * @return string
685 */
686 public function get_incrementer( $refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries' ) {
687 $incrementer_value = wp_cache_get( $incrementer_key );
688
689 if ( false === $incrementer_value || true === $refresh ) {
690 $incrementer_value = (string) microtime( true );
691 wp_cache_set( $incrementer_key, $incrementer_value );
692 }
693
694 return $incrementer_value;
695 }
696
697
698 /**
699 * Flush cache on cache setting enable/disable
700 * Note: only for internal use
701 *
702 * @since 2.0
703 * @access public
704 *
705 * @param bool $force Delete cache forcefully.
706 *
707 * @return bool
708 */
709 public static function flush_cache( $force = false ) {
710 if (
711 $force
712 || ( Give_Admin_Settings::is_saving_settings() && isset( $_POST['cache'] ) && give_is_setting_enabled( give_clean( $_POST['cache'] ) ) )
713 || ( wp_doing_ajax() && isset( $_GET['action'] ) && 'give_cache_flush' === give_clean( $_GET['action'] ) )
714 ) {
715 self::$instance->get_incrementer( true );
716 self::$instance->get_incrementer( true, 'give-cache-incrementer' );
717
718 /**
719 * Fire the action when all cache deleted.
720 *
721 * @since 2.1.0
722 */
723 do_action( 'give_flushed_cache' );
724
725 return true;
726 }
727
728 return false;
729 }
730
731
732 /**
733 * Filter the group name
734 *
735 * @since 2.0
736 * @access private
737 *
738 * @param $group
739 *
740 * @return mixed
741 */
742 private function filter_group_name( $group ) {
743 /**
744 * Filter the group name
745 *
746 * @since 2.1.0
747 */
748 $filtered_group = apply_filters( 'give_cache_filter_group_name', '', $group );
749
750 if ( empty( $filtered_group ) ) {
751
752 switch ( $group ) {
753 case 'give-db-queries':
754 $incrementer = self::$instance->get_incrementer();
755 break;
756
757 default:
758 $incrementer = self::$instance->get_incrementer( false, 'give-cache-incrementer' );
759
760 }
761
762 $current_blog_id = get_current_blog_id();
763 $filtered_group = "{$group}_{$current_blog_id}_{$incrementer}";
764 }
765
766 return $filtered_group;
767 }
768
769
770 /**
771 * Disable cache.
772 *
773 * @since 2.0
774 * @access public
775 */
776 public static function disable() {
777 self::get_instance()->is_cache = false;
778 }
779
780 /**
781 * Enable cache.
782 *
783 * @since 2.0
784 * @access public
785 */
786 public static function enable() {
787 self::get_instance()->is_cache = true;
788 }
789 }
790
791 // Initialize
792 Give_Cache::get_instance()->setup();
793