PluginProbe
Siteimprove / 2.1.2
Siteimprove v2.1.2
2.1.4 trunk 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3
siteimprove / includes / class-siteimproveutils.php

class-siteimproveutils.php in Siteimprove 2.1.2, at includes/class-siteimproveutils.php

40 lines 950 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Global Utilities used by the plugin
4 *
5 * @package Siteimprove
6 * @subpackage Siteimprove/includes
7 */
8
9 /**
10 * Global Utilities Class used throughout the plugin
11 *
12 * @package Siteimprove
13 * @subpackage Siteimprove/includes
14 */
15 class SiteimproveUtils {
16
17 const TOKEN_REQUEST_URL = 'https://my2.siteimprove.com/auth/token';
18
19 /**
20 * Return Siteimprove token.
21 */
22 public static function request_token() {
23 // Request new token.
24 $response = wp_remote_get( self::TOKEN_REQUEST_URL . '?cms=wordpress_' . get_bloginfo( 'version' ), array( 'headers' => array( 'Accept' => 'application/json' ) ) );
25
26 // Check the response code.
27 $response_code = wp_remote_retrieve_response_code( $response );
28 $data = wp_remote_retrieve_body( $response );
29 if ( 200 === $response_code && ! empty( $data ) ) {
30 $json = json_decode( $data );
31 if ( ! empty( $json->token ) ) {
32 return $json->token;
33 }
34 }
35
36 return false;
37 }
38
39 }
40