| @@ -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,12 +137,14 @@ | ||
| 137 | 137 | if ( empty( $query ) ) { |
| 138 | 138 | $query = $this->query; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | + $is_live_api = null; | |
| 141 | 142 | $headers = [ |
| 142 | - 'Content-Type' => 'application/json', | |
| 143 | - 'x-templately-ip' => Helper::get_ip(), | |
| 144 | - 'x-templately-url' => home_url( '/' ) | |
| 143 | + 'Content-Type' => 'application/json', | |
| 144 | + 'x-templately-ip' => Helper::get_ip(), | |
| 145 | + 'x-templately-url' => home_url( '/' ), | |
| 146 | + 'x-templately-version' => TEMPLATELY_VERSION, | |
| 145 | 147 | ]; |
| 146 | 148 | |
| 147 | 149 | if ( ! empty( $args['headers'] ) ) { |
| 148 | 150 | $headers = wp_parse_args( $args['headers'], $headers ); |
| @@ -148,8 +150,13 @@ | ||
| 148 | 150 | $headers = wp_parse_args( $args['headers'], $headers ); |
| 149 | 151 | unset( $args['headers'] ); |
| 150 | 152 | } |
| 151 | 153 | |
| 154 | + if ( ! empty( $args['is_live_api'] ) ) { | |
| 155 | + $is_live_api = $args['is_live_api']; | |
| 156 | + unset( $args['is_live_api'] ); | |
| 157 | + } | |
| 158 | + | |
| 152 | 159 | if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) { |
| 153 | 160 | Helper::log( 'URL: ' . $this->url() ); |
| 154 | 161 | Helper::log( 'QUERY: ' . $query ); |
| 155 | 162 | } |
| @@ -165,9 +172,9 @@ | ||
| 165 | 172 | $retryCount = 0; |
| 166 | 173 | $maxRetries = defined('TEMPLATELY_HTTP_RETRY') ? TEMPLATELY_HTTP_RETRY : 3; |
| 167 | 174 | $args = wp_parse_args( $args, $_default_args ); |
| 168 | 175 | do { |
| 169 | - $response = wp_remote_post( $this->url(), $args ); | |
| 176 | + $response = wp_remote_post( $this->url($is_live_api), $args ); | |
| 170 | 177 | $retryCount++; |
| 171 | 178 | } while ( is_wp_error( $response ) && $retryCount < $maxRetries ); |
| 172 | 179 | |
| 173 | 180 | if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) { |