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/class-give-cache.php +52 -55 2.3.14.16.9 View file →
@@ -22,9 +22,9 @@
22 22 * @since 1.8.7
23 23 * @access private
24 24 * @var Give_Cache
25 25 */
26 - static private $instance;
26 + private static $instance;
27 27
28 28 /**
29 29 * Flag to check if caching enabled or not.
30 30 *
@@ -67,9 +67,9 @@
67 67 * @access public
68 68 */
69 69 public function setup() {
70 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();
71 + self::$instance->is_cache = defined( 'GIVE_CACHE' ) ? GIVE_CACHE : $this->is_cache_enabled();
72 72
73 73 // weekly delete all expired cache.
74 74 Give_Cron::add_weekly_event( array( $this, 'delete_all_expired' ) );
75 75
@@ -79,13 +79,23 @@
79 79 add_action( 'give_deleted_give-donations_cache', array( $this, 'delete_donations_related_cache' ), 10, 3 );
80 80
81 81 add_action( 'give_save_settings_give_settings', array( __CLASS__, 'flush_cache' ) );
82 82
83 - add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
84 - add_action( 'admin_notices', array( $this, '__notices' ) );
83 + add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
84 + add_action( 'admin_notices', array($this, 'notices') );
85 85 }
86 86
87 87 /**
88 + * Get result if cache enabled or not.
89 + *
90 + * @return bool
91 + * @since 2.6.1
92 + */
93 + private function is_cache_enabled() {
94 + return give_is_setting_enabled( give_get_option( 'cache', 'enabled' ) ) && ( is_admin() || false !== strpos( $_SERVER['REQUEST_URI'], rest_get_url_prefix() . '/give-api/' ) );
95 + }
96 +
97 + /**
88 98 * Prevent caching on certain pages
89 99 *
90 100 * @since 2.0.5
91 101 * @access public
@@ -95,18 +105,24 @@
95 105 if ( ! is_blog_installed() ) {
96 106 return;
97 107 }
98 108
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 - ) );
109 + $page_ids = array_filter(
110 + array(
111 + give_get_option( 'success_page' ),
112 + give_get_option( 'failure_page' ),
113 + give_get_option( 'history_page' ),
114 + )
115 + );
104 116
105 - if (
106 - is_page( $page_ids )
107 - || is_singular( 'give_forms' )
108 - ) {
117 + /**
118 + * Use this filter to prevent
119 + *
120 + * @since 2.6.3
121 + */
122 + $canCache = apply_filters( 'give_can_cache_page', is_page( $page_ids ) );
123 +
124 + if ( $canCache ) {
109 125 self::set_nocache_constants();
110 126 nocache_headers();
111 127 }
112 128 }
@@ -132,13 +148,14 @@
132 148
133 149 /**
134 150 * Notices function.
135 151 *
152 + * @since 4.9.0 rename function - PHP 8 compatibility
136 153 * @since 2.0.5
137 154 * @access public
138 155 * @credit WooCommerce
139 156 */
140 - public function __notices() {
157 + public function notices() {
141 158 if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
142 159 return;
143 160 }
144 161
@@ -148,9 +165,9 @@
148 165
149 166 if ( $enabled && ! in_array( 'give', $settings, true ) ) {
150 167 ?>
151 168 <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 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>
169 + <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 170 </div>
154 171 <?php
155 172 }
156 173 }
@@ -200,11 +217,11 @@
200 217 * @return mixed
201 218 */
202 219 public static function get( $cache_key, $custom_key = false, $query_args = array() ) {
203 220 if ( ! self::is_valid_cache_key( $cache_key ) ) {
204 - if( empty( $cache_key ) ) {
221 + if ( empty( $cache_key ) ) {
205 222 return new WP_Error( 'give_empty_cache_key', __( 'Do not pass invalid empty cache key', 'give' ) );
206 - }elseif ( ! $custom_key ) {
223 + } elseif ( ! $custom_key ) {
207 224 return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) );
208 225 }
209 226
210 227 $cache_key = self::get_key( $cache_key, $query_args );
@@ -217,9 +234,9 @@
217 234 return $option;
218 235 }
219 236
220 237 // Get current time.
221 - $current_time = current_time( 'timestamp', 1 );
238 + $current_time = time();
222 239
223 240 if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) {
224 241 $option = $option['data'];
225 242 } else {
@@ -253,9 +270,9 @@
253 270
254 271 $option_value = array(
255 272 'data' => $data,
256 273 'expiration' => ! is_null( $expiration )
257 - ? ( $expiration + current_time( 'timestamp', 1 ) )
274 + ? ( $expiration + time() )
258 275 : null,
259 276 );
260 277
261 278 $result = update_option( $cache_key, $option_value, false );
@@ -310,9 +327,9 @@
310 327 * @since 1.8.7
311 328 * @access public
312 329 * @global wpdb $wpdb
313 330 *
314 - * @param bool $force If set to true then all cached values will be delete instead of only expired
331 + * @param bool $force If set to true then all cached values will be delete instead of only expired
315 332 *
316 333 * @return bool
317 334 */
318 335 public static function delete_all_expired( $force = false ) {
@@ -321,10 +338,10 @@
321 338 $wpdb->prepare(
322 339 "SELECT option_name, option_value
323 340 FROM {$wpdb->options}
324 341 Where option_name
325 - LIKE '%%%s%%'",
326 - 'give_cache'
342 + LIKE '%s'",
343 + '%give_cache%'
327 344 ),
328 345 ARRAY_A
329 346 );
330 347
@@ -332,9 +349,9 @@
332 349 if ( empty( $options ) ) {
333 350 return false;
334 351 }
335 352
336 - $current_time = current_time( 'timestamp', 1 );
353 + $current_time = time();
337 354
338 355 // Delete log cache.
339 356 foreach ( $options as $option ) {
340 357 $option['option_value'] = maybe_unserialize( $option['option_value'] );
@@ -380,10 +397,10 @@
380 397 $wpdb->prepare(
381 398 "SELECT {$field_names }
382 399 FROM {$wpdb->options}
383 400 Where option_name
384 - LIKE '%%%s%%'",
385 - "give_cache_{$option_name}"
401 + LIKE '%s'",
402 + "%give_cache_{$option_name}%"
386 403 ),
387 404 ARRAY_A
388 405 );
389 406 } else {
@@ -391,10 +408,10 @@
391 408 $wpdb->prepare(
392 409 "SELECT *
393 410 FROM {$wpdb->options}
394 411 Where option_name
395 - LIKE '%%%s%%'",
396 - "give_cache_{$option_name}"
412 + LIKE '%s'",
413 + "%give_cache_{$option_name}%"
397 414 ),
398 415 1
399 416 );
400 417 }
@@ -421,9 +438,8 @@
421 438 */
422 439 public static function is_valid_cache_key( $cache_key ) {
423 440 $is_valid = ( false !== strpos( $cache_key, 'give_cache_' ) );
424 441
425 -
426 442 /**
427 443 * Filter the flag which tell about cache key valid or not
428 444 *
429 445 * @since 2.0
@@ -541,9 +557,9 @@
541 557 return $status;
542 558 }
543 559
544 560 $group_prefix = $group;
545 - $group = self::$instance->filter_group_name( $group );
561 + $group = self::$instance->filter_group_name( $group );
546 562
547 563 // Delete single or multiple cache items from cache.
548 564 if ( ! is_array( $ids ) ) {
549 565 $status = wp_cache_delete( $ids, $group );
@@ -596,28 +612,9 @@
596 612 if ( wp_is_post_revision( $form_id ) ) {
597 613 return;
598 614 }
599 615
600 - $donation_query = new Give_Payments_Query(
601 - array(
602 - 'number' => - 1,
603 - 'give_forms' => $form_id,
604 - 'output' => '',
605 - 'fields' => 'ids',
606 - )
607 - );
608 -
609 - $donations = $donation_query->get_payments();
610 -
611 - if ( ! empty( $donations ) ) {
612 - /* @var Give_Payment $donation */
613 - foreach ( $donations as $donation_id ) {
614 - wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) );
615 - wp_cache_delete( give_get_payment_donor_id( $donation_id ), $this->filter_group_name( 'give-donors' ) );
616 - }
617 - }
618 -
619 - self::$instance->get_incrementer( true );
616 + self::flush_cache( true );
620 617 }
621 618
622 619 /**
623 620 * Delete payment related cache
@@ -657,9 +654,9 @@
657 654 public function delete_donor_related_cache( $id, $group, $expire ) {
658 655 $donation_ids = Give()->donors->get_column( 'payment_ids', $id );
659 656
660 657 if ( ! empty( $donation_ids ) ) {
661 - $donation_ids = array_map( 'trim', (array) explode( ',', trim( $donation_ids ) ) );
658 + $donation_ids = array_map( 'trim', (array) explode( ',', trim( $donation_ids ) ) );
662 659
663 660 foreach ( $donation_ids as $donation ) {
664 661 wp_cache_delete( $donation, $this->filter_group_name( 'give-donations' ) );
665 662 }
@@ -705,9 +702,9 @@
705 702 public function get_incrementer( $refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries' ) {
706 703 $incrementer_value = wp_cache_get( $incrementer_key );
707 704
708 705 if ( false === $incrementer_value || true === $refresh ) {
709 - $incrementer_value = microtime( true );
706 + $incrementer_value = (string) microtime( true );
710 707 wp_cache_set( $incrementer_key, $incrementer_value );
711 708 }
712 709
713 710 return $incrementer_value;
@@ -720,9 +717,9 @@
720 717 *
721 718 * @since 2.0
722 719 * @access public
723 720 *
724 - * @param bool $force Delte cache forcefully.
721 + * @param bool $force Delete cache forcefully.
725 722 *
726 723 * @return bool
727 724 */
728 725 public static function flush_cache( $force = false ) {
@@ -728,9 +725,9 @@
728 725 public static function flush_cache( $force = false ) {
729 726 if (
730 727 $force
731 728 || ( Give_Admin_Settings::is_saving_settings() && isset( $_POST['cache'] ) && give_is_setting_enabled( give_clean( $_POST['cache'] ) ) )
732 - || ( wp_doing_ajax() && isset( $_GET['action'] ) && 'give_cache_flush' === give_clean( $_GET['action'] ) )
729 + || ( wp_doing_ajax() && isset( $_GET['action'] ) && 'give_cache_flush' === give_clean( $_GET['action'] ) )
733 730 ) {
734 731 self::$instance->get_incrementer( true );
735 732 self::$instance->get_incrementer( true, 'give-cache-incrementer' );
736 733
@@ -777,10 +774,10 @@
777 774 $incrementer = self::$instance->get_incrementer( false, 'give-cache-incrementer' );
778 775
779 776 }
780 777
781 - $currenct_blog_id = get_current_blog_id();
782 - $filtered_group = "{$group}_{$currenct_blog_id}_{$incrementer}";
778 + $current_blog_id = get_current_blog_id();
779 + $filtered_group = "{$group}_{$current_blog_id}_{$incrementer}";
783 780 }
784 781
785 782 return $filtered_group;
786 783 }