| @@ -23,10 +23,10 @@ | ||
| 23 | 23 | */ |
| 24 | 24 | public function __construct( $core ) { |
| 25 | 25 | parent::__construct( $core ); |
| 26 | 26 | $this->blog_id = get_current_blog_id(); |
| 27 | - add_action( 'patchstack_update_license_status', array( $this, 'update_license_status' ) ); | |
| 28 | - add_action( 'patchstack_send_ping', array( $this, 'ping' ) ); | |
| 27 | + add_action( 'patchstack_update_license_status', [ $this, 'update_license_status' ] ); | |
| 28 | + add_action( 'patchstack_send_ping', [ $this, 'ping' ] ); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Get the API token. |
| @@ -50,12 +50,12 @@ | ||
| 50 | 50 | if ( $response && $response->result == 'success' ) { |
| 51 | 51 | $this->update_blog_option( |
| 52 | 52 | $this->blog_id, |
| 53 | 53 | 'patchstack_api_token', |
| 54 | - array( | |
| 54 | + [ | |
| 55 | 55 | 'token' => $response->message, |
| 56 | 56 | 'expiresin' => $response->expiresin, |
| 57 | - ) | |
| 57 | + ] | |
| 58 | 58 | ); |
| 59 | 59 | return $response->message; |
| 60 | 60 | } |
| 61 | 61 | |
| @@ -68,17 +68,17 @@ | ||
| 68 | 68 | * Fetch the API Token from API Server. |
| 69 | 69 | * |
| 70 | 70 | * @param string $clientid The API client ID. |
| 71 | 71 | * @param string $secretkey The API secret key. |
| 72 | - * @return string|array|object | |
| 72 | + * @return string|array | |
| 73 | 73 | */ |
| 74 | 74 | public function fetch_access_token( $clientid = '', $secretkey = '' ) { |
| 75 | 75 | // Skeleton for the response data. |
| 76 | - $response_data = (object) array( | |
| 76 | + $response_data = (object) [ | |
| 77 | 77 | 'result' => '', |
| 78 | 78 | 'message' => '', |
| 79 | 79 | 'expiresin' => '', |
| 80 | - ); | |
| 80 | + ]; | |
| 81 | 81 | |
| 82 | 82 | // Determine if the license id/key is set. |
| 83 | 83 | $client_id = $this->get_blog_option( $this->blog_id, 'patchstack_clientid', $clientid ); |
| 84 | 84 | |
| @@ -98,22 +98,22 @@ | ||
| 98 | 98 | |
| 99 | 99 | // Send a request to our server to obtain the access token. |
| 100 | 100 | $response = wp_remote_post( |
| 101 | 101 | $this->plugin->auth_url . '/oauth/token', |
| 102 | - array( | |
| 102 | + [ | |
| 103 | 103 | 'method' => 'POST', |
| 104 | 104 | 'timeout' => 60, |
| 105 | 105 | 'redirection' => 5, |
| 106 | 106 | 'httpversion' => '1.0', |
| 107 | 107 | 'blocking' => true, |
| 108 | - 'headers' => array(), | |
| 109 | - 'body' => array( | |
| 108 | + 'headers' => [], | |
| 109 | + 'body' => [ | |
| 110 | 110 | 'client_id' => $client_id, |
| 111 | 111 | 'client_secret' => $client_secret, |
| 112 | 112 | 'grant_type' => 'client_credentials', |
| 113 | - ), | |
| 114 | - 'cookies' => array(), | |
| 115 | - ) | |
| 113 | + ], | |
| 114 | + 'cookies' => [], | |
| 115 | + ] | |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | 118 | // Stop if we received an error from the API. |
| 119 | 119 | if ( is_wp_error( $response ) ) { |
| @@ -184,8 +184,22 @@ | ||
| 184 | 184 | if ( isset( $response['active'] ) && $response['active'] == true ) { |
| 185 | 185 | $this->update_blog_option( $this->blog_id, 'patchstack_license_activated', true ); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | + if ( isset( $response['class'] ) ) { | |
| 189 | + $this->update_blog_option( $this->blog_id, 'patchstack_subscription_class', $response['class'] ); | |
| 190 | + $this->update_blog_option( $this->blog_id, 'patchstack_last_license_check', time() ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + if ( isset( $response['managed'], $response['managed_string'] ) ) { | |
| 194 | + $this->update_blog_option( $this->blog_id, 'patchstack_managed', $response['managed'] ); | |
| 195 | + $this->update_blog_option( $this->blog_id, 'patchstack_managed_text', $response['managed_string'] ); | |
| 196 | + } | |
| 197 | + | |
| 198 | + if ( isset( $response['site_id'] ) ) { | |
| 199 | + $this->update_blog_option( $this->blog_id, 'patchstack_site_id', $response['site_id'] ); | |
| 200 | + } | |
| 201 | + | |
| 188 | 202 | return $response; |
| 189 | 203 | } |
| 190 | 204 | |
| 191 | 205 | /** |
| @@ -195,9 +209,9 @@ | ||
| 195 | 209 | * @param string $request |
| 196 | 210 | * @param array $data |
| 197 | 211 | * @return void|array If successful array, otherwise void. |
| 198 | 212 | */ |
| 199 | - public function send_request( $url, $request, $data = array() ) { | |
| 213 | + public function send_request( $url, $request, $data = [] ) { | |
| 200 | 214 | // Attempt to get the access token. |
| 201 | 215 | $token = $this->get_access_token(); |
| 202 | 216 | if ( empty( $token ) ) { |
| 203 | 217 | return; |
| @@ -205,22 +219,22 @@ | ||
| 205 | 219 | |
| 206 | 220 | // Send the remote request using the WordPress built-in method. |
| 207 | 221 | $response = wp_remote_request( |
| 208 | 222 | $this->plugin->api_url . $url, |
| 209 | - array( | |
| 223 | + [ | |
| 210 | 224 | 'method' => $request, |
| 211 | 225 | 'timeout' => 60, |
| 212 | 226 | 'redirection' => 5, |
| 213 | 227 | 'httpversion' => '1.0', |
| 214 | 228 | 'blocking' => true, |
| 215 | - 'headers' => array( | |
| 229 | + 'headers' => [ | |
| 216 | 230 | 'Authorization' => 'Bearer ' . $token, |
| 217 | 231 | 'LicenseID' => $this->get_blog_option( $this->blog_id, 'patchstack_clientid', 0 ), |
| 218 | 232 | 'Source-Host' => get_site_url(), |
| 219 | - ), | |
| 233 | + ], | |
| 220 | 234 | 'body' => $data, |
| 221 | - 'cookies' => array(), | |
| 222 | - ) | |
| 235 | + 'cookies' => [], | |
| 236 | + ] | |
| 223 | 237 | ); |
| 224 | 238 | |
| 225 | 239 | // Check error or status code. |
| 226 | 240 | if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { |
| @@ -246,23 +260,23 @@ | ||
| 246 | 260 | |
| 247 | 261 | // Tell our API. |
| 248 | 262 | wp_remote_request( |
| 249 | 263 | $this->plugin->api_url . '/api/header', |
| 250 | - array( | |
| 264 | + [ | |
| 251 | 265 | 'method' => 'POST', |
| 252 | 266 | 'timeout' => 60, |
| 253 | 267 | 'redirection' => 5, |
| 254 | 268 | 'httpversion' => '1.0', |
| 255 | 269 | 'blocking' => true, |
| 256 | - 'headers' => array( | |
| 270 | + 'headers' => [ | |
| 257 | 271 | 'Source-Host' => get_site_url(), |
| 258 | - ), | |
| 259 | - 'body' => array( | |
| 272 | + ], | |
| 273 | + 'body' => [ | |
| 260 | 274 | 'token' => $ott, |
| 261 | 275 | 'url' => get_site_url() |
| 262 | - ), | |
| 263 | - 'cookies' => array(), | |
| 264 | - ) | |
| 276 | + ], | |
| 277 | + 'cookies' => [], | |
| 278 | + ] | |
| 265 | 279 | ); |
| 266 | 280 | } |
| 267 | 281 | } |
| 268 | 282 | |
| @@ -271,14 +285,9 @@ | ||
| 271 | 285 | * |
| 272 | 286 | * @return array The firewall rules. |
| 273 | 287 | */ |
| 274 | 288 | public function post_firewall_rule_json() { |
| 275 | - // If the request is coming from the API, fetch fresh rules. | |
| 276 | - if ( isset( $_POST['webarx_refresh_rules'] ) ) { | |
| 277 | - return $this->send_request( '/api/get-rules/2?bypass=cache', 'POST' ); | |
| 278 | - } | |
| 279 | - | |
| 280 | - return $this->send_request( '/api/get-rules/2', 'POST' ); | |
| 289 | + return $this->send_request( '/api/get-rules/3', 'POST' ); | |
| 281 | 290 | } |
| 282 | 291 | |
| 283 | 292 | /** |
| 284 | 293 | * Get the .htaccess rules. |
| @@ -368,7 +377,7 @@ | ||
| 368 | 377 | * |
| 369 | 378 | * @return void |
| 370 | 379 | */ |
| 371 | 380 | public function ping() { |
| 372 | - $this->send_request( '/api/ping', 'POST', array( 'firewall' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ? 1 : 0 ) ); | |
| 381 | + $this->send_request( '/api/ping', 'POST', [ 'firewall' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ? 1 : 0 ] ); | |
| 373 | 382 | } |
| 374 | 383 | } |