PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.11.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.11.0
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / lib / WP_Async_Request.php
wp-mail-smtp / vendor / woocommerce / action-scheduler / lib Last commit date
cron-expression 2 years ago WP_Async_Request.php 2 years ago
WP_Async_Request.php
192 lines
1 <?php
2 /**
3 * WP Async Request
4 *
5 * @package WP-Background-Processing
6 */
7 /*
8 Library URI: https://github.com/deliciousbrains/wp-background-processing/blob/fbbc56f2480910d7959972ec9ec0819a13c6150a/classes/wp-async-request.php
9 Author: Delicious Brains Inc.
10 Author URI: https://deliciousbrains.com/
11 License: GNU General Public License v2.0
12 License URI: https://github.com/deliciousbrains/wp-background-processing/commit/126d7945dd3d39f39cb6488ca08fe1fb66cb351a
13 */
14
15 if ( ! class_exists( 'WP_Async_Request' ) ) {
16
17 /**
18 * Abstract WP_Async_Request class.
19 *
20 * @abstract
21 */
22 abstract class WP_Async_Request {
23
24 /**
25 * Prefix
26 *
27 * (default value: 'wp')
28 *
29 * @var string
30 * @access protected
31 */
32 protected $prefix = 'wp';
33
34 /**
35 * Action
36 *
37 * (default value: 'async_request')
38 *
39 * @var string
40 * @access protected
41 */
42 protected $action = 'async_request';
43
44 /**
45 * Identifier
46 *
47 * @var mixed
48 * @access protected
49 */
50 protected $identifier;
51
52 /**
53 * Data
54 *
55 * (default value: array())
56 *
57 * @var array
58 * @access protected
59 */
60 protected $data = array();
61
62 /**
63 * Initiate new async request
64 */
65 public function __construct() {
66 $this->identifier = $this->prefix . '_' . $this->action;
67
68 add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
69 add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
70 }
71
72 /**
73 * Set data used during the request
74 *
75 * @param array $data Data.
76 *
77 * @return $this
78 */
79 public function data( $data ) {
80 $this->data = $data;
81
82 return $this;
83 }
84
85 /**
86 * Dispatch the async request
87 *
88 * @return array|WP_Error
89 */
90 public function dispatch() {
91 $url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
92 $args = $this->get_post_args();
93
94 return wp_remote_post( esc_url_raw( $url ), $args );
95 }
96
97 /**
98 * Get query args
99 *
100 * @return array
101 */
102 protected function get_query_args() {
103 if ( property_exists( $this, 'query_args' ) ) {
104 return $this->query_args;
105 }
106
107 $args = array(
108 'action' => $this->identifier,
109 'nonce' => wp_create_nonce( $this->identifier ),
110 );
111
112 /**
113 * Filters the post arguments used during an async request.
114 *
115 * @param array $url
116 */
117 return apply_filters( $this->identifier . '_query_args', $args );
118 }
119
120 /**
121 * Get query URL
122 *
123 * @return string
124 */
125 protected function get_query_url() {
126 if ( property_exists( $this, 'query_url' ) ) {
127 return $this->query_url;
128 }
129
130 $url = admin_url( 'admin-ajax.php' );
131
132 /**
133 * Filters the post arguments used during an async request.
134 *
135 * @param string $url
136 */
137 return apply_filters( $this->identifier . '_query_url', $url );
138 }
139
140 /**
141 * Get post args
142 *
143 * @return array
144 */
145 protected function get_post_args() {
146 if ( property_exists( $this, 'post_args' ) ) {
147 return $this->post_args;
148 }
149
150 $args = array(
151 'timeout' => 0.01,
152 'blocking' => false,
153 'body' => $this->data,
154 'cookies' => $_COOKIE,
155 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
156 );
157
158 /**
159 * Filters the post arguments used during an async request.
160 *
161 * @param array $args
162 */
163 return apply_filters( $this->identifier . '_post_args', $args );
164 }
165
166 /**
167 * Maybe handle
168 *
169 * Check for correct nonce and pass to handler.
170 */
171 public function maybe_handle() {
172 // Don't lock up other requests while processing
173 session_write_close();
174
175 check_ajax_referer( $this->identifier, 'nonce' );
176
177 $this->handle();
178
179 wp_die();
180 }
181
182 /**
183 * Handle
184 *
185 * Override this method to perform any actions required
186 * during the async request.
187 */
188 abstract protected function handle();
189
190 }
191 }
192