@@ -32,19 +32,27 @@ class API_Rewrite {
32
32
*/
33
33
private $ disable_ssl ;
34
34
35
+ /**
36
+ * API Key.
37
+ *
38
+ * @var string
39
+ */
40
+ private $ api_key ;
41
+
35
42
/**
36
43
* The Constructor.
37
44
*
38
45
* @param string $redirected_host The host to redirect to.
39
46
* @param boolean $disable_ssl Disable SSL.
40
47
*/
41
- public function __construct ( $ redirected_host , $ disable_ssl ) {
48
+ public function __construct ( $ redirected_host , $ disable_ssl, $ api_key ) {
42
49
if ( 'debug ' === $ redirected_host ) {
43
50
$ this ->redirected_host = $ this ->default_host ;
44
51
} else {
45
52
$ this ->redirected_host = strtolower ( $ redirected_host );
46
53
}
47
54
$ this ->disable_ssl = $ disable_ssl ;
55
+ $ this ->api_key = $ api_key ;
48
56
add_filter ( 'pre_http_request ' , [ $ this , 'pre_http_request ' ], 10 , 3 );
49
57
}
50
58
@@ -65,17 +73,30 @@ public function pre_http_request( $response, $parsed_args, $url ) {
65
73
( '' !== $ this ->redirected_host )
66
74
) {
67
75
if ( false !== strpos ( $ url , $ this ->default_host ) ) {
68
- Debug::log_string ( 'Default API Found: ' . $ url );
69
- Debug::log_request ( $ parsed_args );
76
+ Debug::log_string ( __ ( 'Default API Found: ' , 'aspireupdate ' ) . $ url );
70
77
71
78
if ( $ this ->default_host !== $ this ->redirected_host ) {
72
79
if ( $ this ->disable_ssl ) {
73
- Debug::log_string ( 'SSL Verification Disabled ' );
80
+ Debug::log_string ( __ ( 'SSL Verification Disabled ' , ' aspireupdate ' ) );
74
81
$ parsed_args ['sslverify ' ] = false ;
75
82
}
76
83
84
+ if ( '' !== $ this ->api_key ) {
85
+ Debug::log_string ( __ ( 'API Key Authorization header added. ' , 'aspireupdate ' ) );
86
+ $ parsed_args ['headers ' ]['Authorization ' ] = 'Bearer ' . $ this ->api_key ;
87
+ }
88
+
77
89
$ updated_url = str_replace ( $ this ->default_host , $ this ->redirected_host , $ url );
78
- Debug::log_string ( 'API Rerouted to: ' . $ updated_url );
90
+
91
+ /**
92
+ * Adding cache buster parameter for AC beta test. Will remove this after Beta.
93
+ */
94
+ Debug::log_string ( __ ( 'Cache Buster Added to URL ' , 'aspireupdate ' ) );
95
+ $ updated_url = add_query_arg ( 'cache_buster ' , time (), $ updated_url );
96
+
97
+ Debug::log_string ( __ ( 'API Rerouted to: ' , 'aspireupdate ' ) . $ updated_url );
98
+
99
+ Debug::log_request ( $ parsed_args );
79
100
80
101
/**
81
102
* Temporarily Unhook Filter to prevent recursion.
0 commit comments