File tree 4 files changed +11
-14
lines changed
4 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ function wpcloud_settings_init(): void {
93
93
);
94
94
95
95
// Only show the API key field if it's not set in the environment.
96
- if ( ! wpcloud_get_api_key () ) {
96
+ if ( ! wpcloud_get_api_key_from_env () ) {
97
97
add_settings_field (
98
98
'wpcloud_field_api_key ' ,
99
99
__ ( 'API Key ' , 'wpcloud ' ),
Original file line number Diff line number Diff line change @@ -712,7 +712,7 @@ public function set( $args ) {
712
712
$ options = get_option ( 'wpcloud_settings ' );
713
713
714
714
// Only allow changing the API key if it's not set in the environment.
715
- if ( ! wpcloud_get_api_key () ) {
715
+ if ( ! wpcloud_get_api_key_from_env () ) {
716
716
if ( 'api_key ' === $ key && isset ( $ options ['wpcloud_api_key ' ] ) ) {
717
717
WP_CLI ::confirm ( 'Are you sure you want to change the API key? ' );
718
718
}
Original file line number Diff line number Diff line change @@ -31,7 +31,12 @@ function wpcloud_get_client_name(): mixed {
31
31
* @return string|null Client API Key on success. WP_Error on error.
32
32
*/
33
33
function wpcloud_get_client_api_key (): mixed {
34
- return wpcloud_get_api_key ();
34
+ $ api_key = wpcloud_get_api_key_from_env ();
35
+ if ( $ api_key ) {
36
+ return $ api_key ;
37
+ }
38
+ $ settings = get_option ( 'wpcloud_settings ' , array () );
39
+ return $ settings ['wpcloud_api_key ' ] ?? null ;
35
40
}
36
41
37
42
/**
Original file line number Diff line number Diff line change @@ -37,24 +37,16 @@ function (): void {
37
37
}
38
38
39
39
/**
40
- * Get the api key.
40
+ * Get the api key from the environment .
41
41
*/
42
- function wpcloud_get_api_key (): string {
43
-
44
- // Try to find the key in the ENV or config.
42
+ function wpcloud_get_api_key_from_env (): string {
45
43
$ api_key = getenv ( 'WP_CLOUD_API_KEY ' );
46
44
if ( defined ( 'WP_CLOUD_API_KEY ' ) ) {
47
45
$ api_key = WP_CLOUD_API_KEY ;
48
46
}
49
47
50
48
$ api_key = apply_filters ( 'wpcloud_api_key ' , $ api_key );
51
-
52
- if ( $ api_key ) {
53
- return $ api_key ;
54
- }
55
- // Else check the local options.
56
- $ settings = get_option ( 'wpcloud_settings ' , array () );
57
- return $ settings ['wpcloud_api_key ' ] ?? '' ;
49
+ return $ api_key ? $ api_key : '' ;
58
50
}
59
51
60
52
/**
You can’t perform that action at this time.
0 commit comments