PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.9
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.9
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 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.1 3.1.10 All 111 releases
← All changes | includes/Utils/Http.php +32 -10 3.1.103.4.9 View file →
@@ -31,9 +31,9 @@
31 31 /**
32 32 * Setting the development mode.
33 33 */
34 34 public function __construct() {
35 - $this->dev_mode = defined( 'TEMPLATELY_DEV' ) && TEMPLATELY_DEV;
35 + $this->dev_mode = Helper::is_dev_api();
36 36 }
37 37
38 38 /**
39 39 * Determining the endpoint URL based on the mode.
@@ -39,12 +39,21 @@
39 39 * Determining the endpoint URL based on the mode.
40 40 *
41 41 * @return string
42 42 */
43 - public function url() {
44 - if ( $this->dev_mode ) {
43 + public function url($is_live_api = false) {
44 + if ( !$is_live_api && Helper::is_dev_api() ) {
45 45 $this->url = 'https://app.templately.dev/api/plugin';
46 46 }
47 +
48 + /**
49 + * Filter the API endpoint URL
50 + *
51 + * @since 3.5.0
52 + * @param string $url The endpoint URL
53 + */
54 + $this->url = apply_filters('templately_dev_api_endpoint_url', $this->url);
55 +
47 56 return $this->url;
48 57 }
49 58
50 59 /**
@@ -137,8 +146,9 @@
137 146 if ( empty( $query ) ) {
138 147 $query = $this->query;
139 148 }
140 149
150 + $is_live_api = null;
141 151 $headers = [
142 152 'Content-Type' => 'application/json',
143 153 'x-templately-ip' => Helper::get_ip(),
144 154 'x-templately-url' => home_url( '/' ),
@@ -149,8 +159,13 @@
149 159 $headers = wp_parse_args( $args['headers'], $headers );
150 160 unset( $args['headers'] );
151 161 }
152 162
163 + if ( ! empty( $args['is_live_api'] ) ) {
164 + $is_live_api = $args['is_live_api'];
165 + unset( $args['is_live_api'] );
166 + }
167 +
153 168 if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
154 169 Helper::log( 'URL: ' . $this->url() );
155 170 Helper::log( 'QUERY: ' . $query );
156 171 }
@@ -166,17 +181,17 @@
166 181 $retryCount = 0;
167 182 $maxRetries = defined('TEMPLATELY_HTTP_RETRY') ? TEMPLATELY_HTTP_RETRY : 3;
168 183 $args = wp_parse_args( $args, $_default_args );
169 184 do {
170 - $response = wp_remote_post( $this->url(), $args );
185 + $response = wp_remote_post( $this->url($is_live_api), $args );
171 186 $retryCount++;
172 187 } while ( is_wp_error( $response ) && $retryCount < $maxRetries );
173 188
174 189 if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
175 190 Helper::log( 'Retry Count: ' . $retryCount );
176 - Helper::log( 'RAW RESPONSE: ' );
177 - Helper::log( $response );
178 - Helper::log( 'END RAW RESPONSE' );
191 + // Helper::log( 'RAW RESPONSE: ' );
192 + // Helper::log( $response );
193 + // Helper::log( 'END RAW RESPONSE' );
179 194 }
180 195
181 196 return $this->maybeErrors( $response, $args );
182 197 }
@@ -181,9 +196,9 @@
181 196 return $this->maybeErrors( $response, $args );
182 197 }
183 198
184 199 /**
185 - * Formating the self::post() response
200 + * Formatting the self::post() response
186 201 *
187 202 * @param mixed $response
188 203 * @param array $args
189 204 * @return mixed
@@ -192,13 +207,16 @@
192 207 if ( $response instanceof WP_Error ) {
193 208 return $response; // Return WP_Error, if it is an error.
194 209 }
195 210
211 + // Check for verification header before processing response body
212 + Helper::check_verification_header( $response );
213 +
196 214 $response_code = wp_remote_retrieve_response_code( $response );
197 215 $response_message = wp_remote_retrieve_response_message( $response );
198 216
199 217 /**
200 - * Retrive Data from Response Body.
218 + * Retrieve Data from Response Body.
201 219 */
202 220 $response = json_decode( wp_remote_retrieve_body( $response ), true );
203 221 /**
204 222 * If the graphql hit with any error.
@@ -221,12 +239,16 @@
221 239 } );
222 240 }
223 241 } );
224 242 } else {
243 + $error_data = [];
244 + if(!empty($error["extensions"]["statusText"])) {
245 + $error_data["statusText"] = $error["extensions"]["statusText"];
246 + }
225 247 if ( isset( $error['debugMessage'] ) ) {
226 248 $wp_error->add( 'templately_graphql_error', $error['debugMessage'] );
227 249 } else {
228 - $wp_error->add( 'templately_graphql_error', $error['message'] );
250 + $wp_error->add( 'templately_graphql_error', $error['message'], $error_data );
229 251 }
230 252 }
231 253 }
232 254 } );