Test Failed
Pull Request — master (#2668)
by Devin
07:48
created

Give_Async_Process   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 4 1
A handle() 0 21 4
1
<?php
2
/**
3
 * Background Process
4
 *
5
 * Uses https://github.com/A5hleyRich/wp-background-processing to handle DB
6
 * updates in the background.
7
 *
8
 * @class    Give_Async_Request
9
 * @version  2.0.0
10
 * @package  Give/Classes
11
 * @category Class
12
 * @author   WordImpress
13
 */
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
/**
19
 * Give_Background_Updater Class.
20
 */
21
class Give_Async_Process extends WP_Async_Request {
22
	/**
23
	 * Prefix
24
	 *
25
	 *
26
	 * @var string
27
	 * @access protected
28
	 */
29
	protected $prefix = 'give';
30
31
	/**
32
	 * Dispatch updater.
33
	 *
34
	 * Updater will still run via cron job if this fails for any reason.
35
	 */
36
	public function dispatch() {
37
		/* @var WP_Async_Request $dispatched */
38
		parent::dispatch();
39
	}
40
41
	/**
42
	 * Handle
43
	 *
44
	 * Override this method to perform any actions required
45
	 * during the async request.
46
	 */
47
	protected function handle() {
48
		/*
49
		 * $data = array(
50
		 *  'hook'     => '', // required
51
		 *  'data' => {mixed} // required
52
		 * )
53
		 */
54
55
		$_post = give_clean( $_POST );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
56
57
		if ( empty( $_post ) || empty( $_post['data'] ) || empty( $_post['hook'] ) ) {
58
			exit();
59
		}
60
61
		/**
62
		 * Fire the hook.
63
		 */
64
		do_action( $_post['hook'], $_post['data'] );
65
66
		exit();
67
	}
68
}
69