PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / vendor / woocommerce / action-scheduler / lib / WP_Async_Request.php
jetformbuilder / vendor / woocommerce / action-scheduler / lib Last commit date
cron-expression 1 year ago WP_Async_Request.php 1 year ago
WP_Async_Request.php
189 lines
1 <?php
2 /**
3 * WP Async Request
4 *
5 * @package WP-Background-Processing
6 */
7
8 /*
9 Library URI: https://github.com/deliciousbrains/wp-background-processing/blob/fbbc56f2480910d7959972ec9ec0819a13c6150a/classes/wp-async-request.php
10 Author: Delicious Brains Inc.
11 Author URI: https://deliciousbrains.com/
12 License: GNU General Public License v2.0
13 License URI: https://github.com/deliciousbrains/wp-background-processing/commit/126d7945dd3d39f39cb6488ca08fe1fb66cb351a
14 */
15
16 if ( ! class_exists( 'WP_Async_Request' ) ) {
17
18 /**
19 * Abstract WP_Async_Request class.
20 *
21 * @abstract
22 */
23 abstract class WP_Async_Request {
24
25 /**
26 * Prefix
27 *
28 * (default value: 'wp')
29 *
30 * @var string
31 */
32 protected $prefix = 'wp';
33
34 /**
35 * Action
36 *
37 * (default value: 'async_request')
38 *
39 * @var string
40 */
41 protected $action = 'async_request';
42
43 /**
44 * Identifier
45 *
46 * @var mixed
47 */
48 protected $identifier;
49
50 /**
51 * Data
52 *
53 * (default value: array())
54 *
55 * @var array
56 */
57 protected $data = array();
58
59 /**
60 * Initiate new async request
61 */
62 public function __construct() {
63 $this->identifier = $this->prefix . '_' . $this->action;
64
65 add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
66 add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
67 }
68
69 /**
70 * Set data used during the request
71 *
72 * @param array $data Data.
73 *
74 * @return $this
75 */
76 public function data( $data ) {
77 $this->data = $data;
78
79 return $this;
80 }
81
82 /**
83 * Dispatch the async request
84 *
85 * @return array|WP_Error
86 */
87 public function dispatch() {
88 $url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
89 $args = $this->get_post_args();
90
91 return wp_remote_post( esc_url_raw( $url ), $args );
92 }
93
94 /**
95 * Get query args
96 *
97 * @return array
98 */
99 protected function get_query_args() {
100 if ( property_exists( $this, 'query_args' ) ) {
101 return $this->query_args;
102 }
103
104 $args = array(
105 'action' => $this->identifier,
106 'nonce' => wp_create_nonce( $this->identifier ),
107 );
108
109 /**
110 * Filters the post arguments used during an async request.
111 *
112 * @param array $url
113 */
114 return apply_filters( $this->identifier . '_query_args', $args );
115 }
116
117 /**
118 * Get query URL
119 *
120 * @return string
121 */
122 protected function get_query_url() {
123 if ( property_exists( $this, 'query_url' ) ) {
124 return $this->query_url;
125 }
126
127 $url = admin_url( 'admin-ajax.php' );
128
129 /**
130 * Filters the post arguments used during an async request.
131 *
132 * @param string $url
133 */
134 return apply_filters( $this->identifier . '_query_url', $url );
135 }
136
137 /**
138 * Get post args
139 *
140 * @return array
141 */
142 protected function get_post_args() {
143 if ( property_exists( $this, 'post_args' ) ) {
144 return $this->post_args;
145 }
146
147 $args = array(
148 'timeout' => 0.01,
149 'blocking' => false,
150 'body' => $this->data,
151 'cookies' => $_COOKIE,
152 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
153 );
154
155 /**
156 * Filters the post arguments used during an async request.
157 *
158 * @param array $args
159 */
160 return apply_filters( $this->identifier . '_post_args', $args );
161 }
162
163 /**
164 * Maybe handle
165 *
166 * Check for correct nonce and pass to handler.
167 */
168 public function maybe_handle() {
169 // Don't lock up other requests while processing.
170 session_write_close();
171
172 check_ajax_referer( $this->identifier, 'nonce' );
173
174 $this->handle();
175
176 wp_die();
177 }
178
179 /**
180 * Handle
181 *
182 * Override this method to perform any actions required
183 * during the async request.
184 */
185 abstract protected function handle();
186
187 }
188 }
189