Test Failed
Push — master ( 9a7225...07651e )
by Ravinder
05:42
created
includes/class-give-cache.php 1 patch
Spacing   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return static
54 54
 	 */
55 55
 	public static function get_instance() {
56
-		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Give_Cache ) ) {
56
+		if ( ! isset(self::$instance) && ! (self::$instance instanceof Give_Cache)) {
57 57
 			self::$instance = new Give_Cache();
58 58
 		}
59 59
 
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
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 : give_is_setting_enabled(give_get_option('cache', 'enabled'))) && is_admin();
72 72
 
73 73
 		// weekly delete all expired cache.
74
-		Give_Cron::add_weekly_event( array( $this, 'delete_all_expired' ) );
74
+		Give_Cron::add_weekly_event(array($this, 'delete_all_expired'));
75 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 );
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 80
 
81
-		add_action( 'give_save_settings_give_settings', array( __CLASS__, 'flush_cache' ) );
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
 	/**
@@ -92,19 +92,19 @@  discard block
 block discarded – undo
92 92
 	 * @credit WooCommerce
93 93
 	 */
94 94
 	public static function prevent_caching() {
95
-		if ( ! is_blog_installed() ) {
95
+		if ( ! is_blog_installed()) {
96 96
 			return;
97 97
 		}
98 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
-		) );
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 104
 
105 105
 		if (
106
-			is_page( $page_ids )
107
-			|| is_singular( 'give_forms' )
106
+			is_page($page_ids)
107
+			|| is_singular('give_forms')
108 108
 		) {
109 109
 			self::set_nocache_constants();
110 110
 			nocache_headers();
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @return mixed
124 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 );
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 129
 
130 130
 		return $return;
131 131
 	}
@@ -138,18 +138,18 @@  discard block
 block discarded – undo
138 138
 	 * @credit WooCommerce
139 139
 	 */
140 140
 	public function __notices() {
141
-		if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
141
+		if ( ! function_exists('w3tc_pgcache_flush') || ! function_exists('w3_instance')) {
142 142
 			return;
143 143
 		}
144 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' ) );
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 148
 
149
-		if ( $enabled && ! in_array( 'give', $settings, true ) ) {
149
+		if ($enabled && ! in_array('give', $settings, true)) {
150 150
 			?>
151 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 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>
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>
153 153
 			</div>
154 154
 			<?php
155 155
 		}
@@ -166,18 +166,18 @@  discard block
 block discarded – undo
166 166
 	 *
167 167
 	 * @return string
168 168
 	 */
169
-	public static function get_key( $action, $query_args = null, $is_prefix = true ) {
169
+	public static function get_key($action, $query_args = null, $is_prefix = true) {
170 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' ) );
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 173
 		}
174 174
 
175 175
 		// Set cache key.
176 176
 		$cache_key = $is_prefix ? "give_cache_{$action}" : $action;
177 177
 
178 178
 		// Bailout.
179
-		if ( ! empty( $query_args ) ) {
180
-			$cache_key = "{$cache_key}_" . substr( md5( serialize( $query_args ) ), 0, 15 );
179
+		if ( ! empty($query_args)) {
180
+			$cache_key = "{$cache_key}_".substr(md5(serialize($query_args)), 0, 15);
181 181
 		}
182 182
 
183 183
 		/**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		 *
186 186
 		 * @since 2.0
187 187
 		 */
188
-		return apply_filters( 'give_get_cache_key', $cache_key, $action, $query_args );
188
+		return apply_filters('give_get_cache_key', $cache_key, $action, $query_args);
189 189
 	}
190 190
 
191 191
 	/**
@@ -199,28 +199,28 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return mixed
201 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' ) );
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 208
 			}
209 209
 
210
-			$cache_key = self::get_key( $cache_key, $query_args );
210
+			$cache_key = self::get_key($cache_key, $query_args);
211 211
 		}
212 212
 
213
-		$option = get_option( $cache_key );
213
+		$option = get_option($cache_key);
214 214
 
215 215
 		// Backward compatibility (<1.8.7).
216
-		if ( ! is_array( $option ) || empty( $option ) || ! array_key_exists( 'expiration', $option ) ) {
216
+		if ( ! is_array($option) || empty($option) || ! array_key_exists('expiration', $option)) {
217 217
 			return $option;
218 218
 		}
219 219
 
220 220
 		// Get current time.
221
-		$current_time = current_time( 'timestamp', 1 );
221
+		$current_time = current_time('timestamp', 1);
222 222
 
223
-		if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) {
223
+		if (empty($option['expiration']) || ($current_time < $option['expiration'])) {
224 224
 			$option = $option['data'];
225 225
 		} else {
226 226
 			$option = false;
@@ -242,23 +242,23 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @return mixed
244 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' ) );
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 249
 			}
250 250
 
251
-			$cache_key = self::get_key( $cache_key, $query_args );
251
+			$cache_key = self::get_key($cache_key, $query_args);
252 252
 		}
253 253
 
254 254
 		$option_value = array(
255 255
 			'data'       => $data,
256
-			'expiration' => ! is_null( $expiration )
257
-				? ( $expiration + current_time( 'timestamp', 1 ) )
256
+			'expiration' => ! is_null($expiration)
257
+				? ($expiration + current_time('timestamp', 1))
258 258
 				: null,
259 259
 		);
260 260
 
261
-		$result = update_option( $cache_key, $option_value, false );
261
+		$result = update_option($cache_key, $option_value, false);
262 262
 
263 263
 		return $result;
264 264
 	}
@@ -274,27 +274,27 @@  discard block
 block discarded – undo
274 274
 	 *
275 275
 	 * @return bool|WP_Error
276 276
 	 */
277
-	public static function delete( $cache_keys ) {
277
+	public static function delete($cache_keys) {
278 278
 		$result       = true;
279 279
 		$invalid_keys = array();
280 280
 
281
-		if ( ! empty( $cache_keys ) ) {
282
-			$cache_keys = is_array( $cache_keys ) ? $cache_keys : array( $cache_keys );
281
+		if ( ! empty($cache_keys)) {
282
+			$cache_keys = is_array($cache_keys) ? $cache_keys : array($cache_keys);
283 283
 
284
-			foreach ( $cache_keys as $cache_key ) {
285
-				if ( ! self::is_valid_cache_key( $cache_key ) ) {
284
+			foreach ($cache_keys as $cache_key) {
285
+				if ( ! self::is_valid_cache_key($cache_key)) {
286 286
 					$invalid_keys[] = $cache_key;
287 287
 					$result         = false;
288 288
 				}
289 289
 
290
-				delete_option( $cache_key );
290
+				delete_option($cache_key);
291 291
 			}
292 292
 		}
293 293
 
294
-		if ( ! $result ) {
294
+		if ( ! $result) {
295 295
 			$result = new WP_Error(
296 296
 				'give_invalid_cache_key',
297
-				__( 'Cache key format should be give_cache_*', 'give' ),
297
+				__('Cache key format should be give_cache_*', 'give'),
298 298
 				$invalid_keys
299 299
 			);
300 300
 		}
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 *
316 316
 	 * @return bool
317 317
 	 */
318
-	public static function delete_all_expired( $force = false ) {
318
+	public static function delete_all_expired($force = false) {
319 319
 		global $wpdb;
320 320
 		$options = $wpdb->get_results(
321 321
 			$wpdb->prepare(
@@ -329,30 +329,30 @@  discard block
 block discarded – undo
329 329
 		);
330 330
 
331 331
 		// Bailout.
332
-		if ( empty( $options ) ) {
332
+		if (empty($options)) {
333 333
 			return false;
334 334
 		}
335 335
 
336
-		$current_time = current_time( 'timestamp', 1 );
336
+		$current_time = current_time('timestamp', 1);
337 337
 
338 338
 		// Delete log cache.
339
-		foreach ( $options as $option ) {
340
-			$option['option_value'] = maybe_unserialize( $option['option_value'] );
339
+		foreach ($options as $option) {
340
+			$option['option_value'] = maybe_unserialize($option['option_value']);
341 341
 
342 342
 			if (
343 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'] )
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 349
 				)
350 350
 				&& ! $force
351 351
 			) {
352 352
 				continue;
353 353
 			}
354 354
 
355
-			self::delete( $option['option_name'] );
355
+			self::delete($option['option_name']);
356 356
 		}
357 357
 	}
358 358
 
@@ -370,12 +370,12 @@  discard block
 block discarded – undo
370 370
 	 *
371 371
 	 * @return array
372 372
 	 */
373
-	public static function get_options_like( $option_name, $fields = false ) {
373
+	public static function get_options_like($option_name, $fields = false) {
374 374
 		global $wpdb;
375 375
 
376 376
 		$field_names = $fields ? 'option_name, option_value' : 'option_name';
377 377
 
378
-		if ( $fields ) {
378
+		if ($fields) {
379 379
 			$options = $wpdb->get_results(
380 380
 				$wpdb->prepare(
381 381
 					"SELECT {$field_names }
@@ -399,10 +399,10 @@  discard block
 block discarded – undo
399 399
 			);
400 400
 		}
401 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;
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 406
 			}
407 407
 		}
408 408
 
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 	 *
420 420
 	 * @return bool
421 421
 	 */
422
-	public static function is_valid_cache_key( $cache_key ) {
423
-		$is_valid = ( false !== strpos( $cache_key, 'give_cache_' ) );
422
+	public static function is_valid_cache_key($cache_key) {
423
+		$is_valid = (false !== strpos($cache_key, 'give_cache_'));
424 424
 
425 425
 
426 426
 		/**
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		 *
429 429
 		 * @since 2.0
430 430
 		 */
431
-		return apply_filters( 'give_is_valid_cache_key', $is_valid, $cache_key );
431
+		return apply_filters('give_is_valid_cache_key', $is_valid, $cache_key);
432 432
 	}
433 433
 
434 434
 
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
 	 *
444 444
 	 * @return mixed
445 445
 	 */
446
-	public static function get_group( $id, $group = '' ) {
446
+	public static function get_group($id, $group = '') {
447 447
 		$cached_data = null;
448 448
 
449 449
 		// Bailout.
450
-		if ( self::$instance->is_cache && ! empty( $id ) ) {
451
-			$group = self::$instance->filter_group_name( $group );
450
+		if (self::$instance->is_cache && ! empty($id)) {
451
+			$group = self::$instance->filter_group_name($group);
452 452
 
453
-			$cached_data = wp_cache_get( $id, $group );
453
+			$cached_data = wp_cache_get($id, $group);
454 454
 			$cached_data = false !== $cached_data ? $cached_data : null;
455 455
 		}
456 456
 
@@ -470,17 +470,17 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @return bool
472 472
 	 */
473
-	public static function set_group( $id, $data, $group = '', $expire = 0 ) {
473
+	public static function set_group($id, $data, $group = '', $expire = 0) {
474 474
 		$status = false;
475 475
 
476 476
 		// Bailout.
477
-		if ( ! self::$instance->is_cache || empty( $id ) ) {
477
+		if ( ! self::$instance->is_cache || empty($id)) {
478 478
 			return $status;
479 479
 		}
480 480
 
481
-		$group = self::$instance->filter_group_name( $group );
481
+		$group = self::$instance->filter_group_name($group);
482 482
 
483
-		$status = wp_cache_set( $id, $data, $group, $expire );
483
+		$status = wp_cache_set($id, $data, $group, $expire);
484 484
 
485 485
 		return $status;
486 486
 	}
@@ -496,15 +496,15 @@  discard block
 block discarded – undo
496 496
 	 *
497 497
 	 * @return bool
498 498
 	 */
499
-	public static function set_db_query( $id, $data ) {
499
+	public static function set_db_query($id, $data) {
500 500
 		$status = false;
501 501
 
502 502
 		// Bailout.
503
-		if ( ! self::$instance->is_cache || empty( $id ) ) {
503
+		if ( ! self::$instance->is_cache || empty($id)) {
504 504
 			return $status;
505 505
 		}
506 506
 
507
-		return self::set_group( $id, $data, 'give-db-queries', 0 );
507
+		return self::set_group($id, $data, 'give-db-queries', 0);
508 508
 	}
509 509
 
510 510
 	/**
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 	 *
518 518
 	 * @return mixed
519 519
 	 */
520
-	public static function get_db_query( $id ) {
521
-		return self::get_group( $id, 'give-db-queries' );
520
+	public static function get_db_query($id) {
521
+		return self::get_group($id, 'give-db-queries');
522 522
 	}
523 523
 
524 524
 	/**
@@ -533,21 +533,21 @@  discard block
 block discarded – undo
533 533
 	 *
534 534
 	 * @return bool
535 535
 	 */
536
-	public static function delete_group( $ids, $group = '', $expire = 0 ) {
536
+	public static function delete_group($ids, $group = '', $expire = 0) {
537 537
 		$status = false;
538 538
 
539 539
 		// Bailout.
540
-		if ( ! self::$instance->is_cache || empty( $ids ) ) {
540
+		if ( ! self::$instance->is_cache || empty($ids)) {
541 541
 			return $status;
542 542
 		}
543 543
 
544 544
 		$group_prefix = $group;
545
-		$group = self::$instance->filter_group_name( $group );
545
+		$group = self::$instance->filter_group_name($group);
546 546
 
547 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 );
548
+		if ( ! is_array($ids)) {
549
+			$status = wp_cache_delete($ids, $group);
550
+			self::$instance->get_incrementer(true);
551 551
 
552 552
 			/**
553 553
 			 * Fire action when cache deleted for specific id.
@@ -558,12 +558,12 @@  discard block
 block discarded – undo
558 558
 			 * @param string $group
559 559
 			 * @param int    $expire
560 560
 			 */
561
-			do_action( "give_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status );
561
+			do_action("give_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status);
562 562
 
563 563
 		} else {
564
-			foreach ( $ids as $id ) {
565
-				$status = wp_cache_delete( $id, $group );
566
-				self::$instance->get_incrementer( true );
564
+			foreach ($ids as $id) {
565
+				$status = wp_cache_delete($id, $group);
566
+				self::$instance->get_incrementer(true);
567 567
 
568 568
 				/**
569 569
 				 * Fire action when cache deleted for specific id .
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 				 * @param string $group
575 575
 				 * @param int    $expire
576 576
 				 */
577
-				do_action( "give_deleted_{$group_prefix}_cache", $id, $group, $expire, $status );
577
+				do_action("give_deleted_{$group_prefix}_cache", $id, $group, $expire, $status);
578 578
 			}
579 579
 		}
580 580
 
@@ -591,15 +591,15 @@  discard block
 block discarded – undo
591 591
 	 *
592 592
 	 * @param int $form_id
593 593
 	 */
594
-	public function delete_form_related_cache( $form_id ) {
594
+	public function delete_form_related_cache($form_id) {
595 595
 		// If this is just a revision, don't send the email.
596
-		if ( wp_is_post_revision( $form_id ) ) {
596
+		if (wp_is_post_revision($form_id)) {
597 597
 			return;
598 598
 		}
599 599
 
600 600
 		$donation_query = new Give_Payments_Query(
601 601
 			array(
602
-				'number'     => - 1,
602
+				'number'     => -1,
603 603
 				'give_forms' => $form_id,
604 604
 				'output'     => '',
605 605
 				'fields'     => 'ids',
@@ -608,15 +608,15 @@  discard block
 block discarded – undo
608 608
 
609 609
 		$donations = $donation_query->get_payments();
610 610
 
611
-		if ( ! empty( $donations ) ) {
611
+		if ( ! empty($donations)) {
612 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' ) );
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 616
 			}
617 617
 		}
618 618
 
619
-		self::$instance->get_incrementer( true );
619
+		self::$instance->get_incrementer(true);
620 620
 	}
621 621
 
622 622
 	/**
@@ -628,19 +628,19 @@  discard block
 block discarded – undo
628 628
 	 *
629 629
 	 * @param int $donation_id
630 630
 	 */
631
-	public function delete_payment_related_cache( $donation_id ) {
631
+	public function delete_payment_related_cache($donation_id) {
632 632
 		// If this is just a revision, don't send the email.
633
-		if ( wp_is_post_revision( $donation_id ) ) {
633
+		if (wp_is_post_revision($donation_id)) {
634 634
 			return;
635 635
 		}
636 636
 
637
-		if ( $donation_id && ( $donor_id = give_get_payment_donor_id( $donation_id ) ) ) {
638
-			wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) );
637
+		if ($donation_id && ($donor_id = give_get_payment_donor_id($donation_id))) {
638
+			wp_cache_delete($donor_id, $this->filter_group_name('give-donors'));
639 639
 		}
640 640
 
641
-		wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) );
641
+		wp_cache_delete($donation_id, $this->filter_group_name('give-donations'));
642 642
 
643
-		self::$instance->get_incrementer( true );
643
+		self::$instance->get_incrementer(true);
644 644
 	}
645 645
 
646 646
 	/**
@@ -654,18 +654,18 @@  discard block
 block discarded – undo
654 654
 	 * @param string $group
655 655
 	 * @param int    $expire
656 656
 	 */
657
-	public function delete_donor_related_cache( $id, $group, $expire ) {
658
-		$donation_ids = Give()->donors->get_column( 'payment_ids', $id );
657
+	public function delete_donor_related_cache($id, $group, $expire) {
658
+		$donation_ids = Give()->donors->get_column('payment_ids', $id);
659 659
 
660
-		if ( ! empty( $donation_ids ) ) {
661
-			$donation_ids = array_map( 'trim', (array) explode( ',', trim( $donation_ids  ) ) );
660
+		if ( ! empty($donation_ids)) {
661
+			$donation_ids = array_map('trim', (array) explode(',', trim($donation_ids)));
662 662
 
663
-			foreach ( $donation_ids as $donation ) {
664
-				wp_cache_delete( $donation, $this->filter_group_name( 'give-donations' ) );
663
+			foreach ($donation_ids as $donation) {
664
+				wp_cache_delete($donation, $this->filter_group_name('give-donations'));
665 665
 			}
666 666
 		}
667 667
 
668
-		self::$instance->get_incrementer( true );
668
+		self::$instance->get_incrementer(true);
669 669
 	}
670 670
 
671 671
 	/**
@@ -679,12 +679,12 @@  discard block
 block discarded – undo
679 679
 	 * @param string $group
680 680
 	 * @param int    $expire
681 681
 	 */
682
-	public function delete_donations_related_cache( $id, $group, $expire ) {
683
-		if ( $id && ( $donor_id = give_get_payment_donor_id( $id ) ) ) {
684
-			wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) );
682
+	public function delete_donations_related_cache($id, $group, $expire) {
683
+		if ($id && ($donor_id = give_get_payment_donor_id($id))) {
684
+			wp_cache_delete($donor_id, $this->filter_group_name('give-donors'));
685 685
 		}
686 686
 
687
-		self::$instance->get_incrementer( true );
687
+		self::$instance->get_incrementer(true);
688 688
 	}
689 689
 
690 690
 
@@ -702,12 +702,12 @@  discard block
 block discarded – undo
702 702
 	 *
703 703
 	 * @return string
704 704
 	 */
705
-	public function get_incrementer( $refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries' ) {
706
-		$incrementer_value = wp_cache_get( $incrementer_key );
705
+	public function get_incrementer($refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries') {
706
+		$incrementer_value = wp_cache_get($incrementer_key);
707 707
 
708
-		if ( false === $incrementer_value || true === $refresh ) {
709
-			$incrementer_value = microtime( true );
710
-			wp_cache_set( $incrementer_key, $incrementer_value );
708
+		if (false === $incrementer_value || true === $refresh) {
709
+			$incrementer_value = microtime(true);
710
+			wp_cache_set($incrementer_key, $incrementer_value);
711 711
 		}
712 712
 
713 713
 		return $incrementer_value;
@@ -725,21 +725,21 @@  discard block
 block discarded – undo
725 725
 	 *
726 726
 	 * @return bool
727 727
 	 */
728
-	public static function flush_cache( $force = false ) {
728
+	public static function flush_cache($force = false) {
729 729
 		if (
730 730
 			$force
731
-			|| ( 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'] ) )
731
+			|| (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']))
733 733
 		) {
734
-			self::$instance->get_incrementer( true );
735
-			self::$instance->get_incrementer( true, 'give-cache-incrementer' );
734
+			self::$instance->get_incrementer(true);
735
+			self::$instance->get_incrementer(true, 'give-cache-incrementer');
736 736
 
737 737
 			/**
738 738
 			 * Fire the action when all cache deleted.
739 739
 			 *
740 740
 			 * @since 2.1.0
741 741
 			 */
742
-			do_action( 'give_fluched_cache' );
742
+			do_action('give_fluched_cache');
743 743
 
744 744
 			return true;
745 745
 		}
@@ -758,23 +758,23 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @return mixed
760 760
 	 */
761
-	private function filter_group_name( $group ) {
761
+	private function filter_group_name($group) {
762 762
 		/**
763 763
 		 * Filter the group name
764 764
 		 *
765 765
 		 * @since 2.1.0
766 766
 		 */
767
-		$filtered_group = apply_filters( 'give_cache_filter_group_name', '', $group );
767
+		$filtered_group = apply_filters('give_cache_filter_group_name', '', $group);
768 768
 
769
-		if ( empty( $filtered_group ) ) {
769
+		if (empty($filtered_group)) {
770 770
 
771
-			switch ( $group ) {
771
+			switch ($group) {
772 772
 				case 'give-db-queries':
773 773
 					$incrementer = self::$instance->get_incrementer();
774 774
 					break;
775 775
 
776 776
 				default:
777
-					$incrementer = self::$instance->get_incrementer( false, 'give-cache-incrementer' );
777
+					$incrementer = self::$instance->get_incrementer(false, 'give-cache-incrementer');
778 778
 
779 779
 			}
780 780
 
Please login to merge, or discard this patch.