PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.5
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.5
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 +15 -6 3.1.103.4.5 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,10 +39,10 @@
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 47 return $this->url;
48 48 }
@@ -137,8 +137,9 @@
137 137 if ( empty( $query ) ) {
138 138 $query = $this->query;
139 139 }
140 140
141 + $is_live_api = null;
141 142 $headers = [
142 143 'Content-Type' => 'application/json',
143 144 'x-templately-ip' => Helper::get_ip(),
144 145 'x-templately-url' => home_url( '/' ),
@@ -149,8 +150,13 @@
149 150 $headers = wp_parse_args( $args['headers'], $headers );
150 151 unset( $args['headers'] );
151 152 }
152 153
154 + if ( ! empty( $args['is_live_api'] ) ) {
155 + $is_live_api = $args['is_live_api'];
156 + unset( $args['is_live_api'] );
157 + }
158 +
153 159 if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
154 160 Helper::log( 'URL: ' . $this->url() );
155 161 Helper::log( 'QUERY: ' . $query );
156 162 }
@@ -166,9 +172,9 @@
166 172 $retryCount = 0;
167 173 $maxRetries = defined('TEMPLATELY_HTTP_RETRY') ? TEMPLATELY_HTTP_RETRY : 3;
168 174 $args = wp_parse_args( $args, $_default_args );
169 175 do {
170 - $response = wp_remote_post( $this->url(), $args );
176 + $response = wp_remote_post( $this->url($is_live_api), $args );
171 177 $retryCount++;
172 178 } while ( is_wp_error( $response ) && $retryCount < $maxRetries );
173 179
174 180 if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
@@ -181,9 +187,9 @@
181 187 return $this->maybeErrors( $response, $args );
182 188 }
183 189
184 190 /**
185 - * Formating the self::post() response
191 + * Formatting the self::post() response
186 192 *
187 193 * @param mixed $response
188 194 * @param array $args
189 195 * @return mixed
@@ -192,13 +198,16 @@
192 198 if ( $response instanceof WP_Error ) {
193 199 return $response; // Return WP_Error, if it is an error.
194 200 }
195 201
202 + // Check for verification header before processing response body
203 + Helper::check_verification_header( $response );
204 +
196 205 $response_code = wp_remote_retrieve_response_code( $response );
197 206 $response_message = wp_remote_retrieve_response_message( $response );
198 207
199 208 /**
200 - * Retrive Data from Response Body.
209 + * Retrieve Data from Response Body.
201 210 */
202 211 $response = json_decode( wp_remote_retrieve_body( $response ), true );
203 212 /**
204 213 * If the graphql hit with any error.