PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 2.9.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v2.9.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 5 years ago WP_Async_Request.php 5 years ago
WP_Async_Request.php
171 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 return array(
108 'action' => $this->identifier,
109 'nonce' => wp_create_nonce( $this->identifier ),
110 );
111 }
112
113 /**
114 * Get query URL
115 *
116 * @return string
117 */
118 protected function get_query_url() {
119 if ( property_exists( $this, 'query_url' ) ) {
120 return $this->query_url;
121 }
122
123 return admin_url( 'admin-ajax.php' );
124 }
125
126 /**
127 * Get post args
128 *
129 * @return array
130 */
131 protected function get_post_args() {
132 if ( property_exists( $this, 'post_args' ) ) {
133 return $this->post_args;
134 }
135
136 return array(
137 'timeout' => 0.01,
138 'blocking' => false,
139 'body' => $this->data,
140 'cookies' => $_COOKIE,
141 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
142 );
143 }
144
145 /**
146 * Maybe handle
147 *
148 * Check for correct nonce and pass to handler.
149 */
150 public function maybe_handle() {
151 // Don't lock up other requests while processing
152 session_write_close();
153
154 check_ajax_referer( $this->identifier, 'nonce' );
155
156 $this->handle();
157
158 wp_die();
159 }
160
161 /**
162 * Handle
163 *
164 * Override this method to perform any actions required
165 * during the async request.
166 */
167 abstract protected function handle();
168
169 }
170 }
171