Skip to content

Commit 9d995d0

Browse files
committed
Only hide key option if not in the env
1 parent 5cb0799 commit 9d995d0

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

plugin/admin/init.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function wpcloud_settings_init(): void {
9393
);
9494

9595
// 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() ) {
9797
add_settings_field(
9898
'wpcloud_field_api_key',
9999
__( 'API Key', 'wpcloud' ),

plugin/includes/class-wpcloud-cli.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ public function set( $args ) {
712712
$options = get_option( 'wpcloud_settings' );
713713

714714
// 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() ) {
716716
if ( 'api_key' === $key && isset( $options['wpcloud_api_key'] ) ) {
717717
WP_CLI::confirm( 'Are you sure you want to change the API key?' );
718718
}

plugin/includes/wpcloud-client.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ function wpcloud_get_client_name(): mixed {
3131
* @return string|null Client API Key on success. WP_Error on error.
3232
*/
3333
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;
3540
}
3641

3742
/**

plugin/init.php

+3-11
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,16 @@ function (): void {
3737
}
3838

3939
/**
40-
* Get the api key.
40+
* Get the api key from the environment.
4141
*/
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 {
4543
$api_key = getenv( 'WP_CLOUD_API_KEY' );
4644
if ( defined( 'WP_CLOUD_API_KEY' ) ) {
4745
$api_key = WP_CLOUD_API_KEY;
4846
}
4947

5048
$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 : '';
5850
}
5951

6052
/**

0 commit comments

Comments
 (0)