Skip to content

Commit

Permalink
fix: default values for keys
Browse files Browse the repository at this point in the history
Closes #97
  • Loading branch information
adekbadek committed Apr 21, 2020
1 parent 05d761f commit c0d8b23
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions includes/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ public static function api_get_keys() {
$mailchimp_api_key = self::mailchimp_api_key();
$mjml_api_key = get_option( 'newspack_newsletters_mjml_api_key', false );
$mjml_api_secret = get_option( 'newspack_newsletters_mjml_api_secret', false );

$keys = [
'mailchimp_api_key' => $mailchimp_api_key,
'mjml_api_key' => $mjml_api_key,
'mjml_api_secret' => $mjml_api_secret,
'mailchimp_api_key' => $mailchimp_api_key ? $mailchimp_api_key : '',
'mjml_api_key' => $mjml_api_key ? $mjml_api_key : '',
'mjml_api_secret' => $mjml_api_secret ? $mjml_api_secret : '',
'status' => ! empty( $mailchimp_api_key ) && ! empty( $mjml_api_key ) && ! empty( $mjml_api_secret ),
];
return \rest_ensure_response( $keys );
Expand All @@ -342,11 +342,9 @@ public static function api_set_keys( $request ) {
$mjml_api_secret = $request['mjml_api_secret'];
$wp_error = new WP_Error();

$errors = [];

if ( empty( $mailchimp_api_key ) ) {
$wp_error->add(
'newspack_newsletters_invalid_keys_mailchimp',
$wp_error->add(
'newspack_newsletters_invalid_keys_mailchimp',
__( 'Please input a Mailchimp API key.', 'newspack-newsletters' )
);
} else {
Expand All @@ -359,16 +357,16 @@ public static function api_set_keys( $request ) {
if ( $ping ) {
update_option( 'newspack_newsletters_mailchimp_api_key', $mailchimp_api_key );
} else {
$wp_error->add(
'newspack_newsletters_invalid_keys_mailchimp',
$wp_error->add(
'newspack_newsletters_invalid_keys_mailchimp',
__( 'Please input a valid Mailchimp API key.', 'newspack-newsletters' )
);
}
}

if ( empty( $mjml_api_key ) || empty( $mjml_api_secret ) ) {
$wp_error->add(
'newspack_newsletters_invalid_keys_mjml',
$wp_error->add(
'newspack_newsletters_invalid_keys_mjml',
__( 'Please input MJML application ID and secret key.', 'newspack-newsletters' )
);
} else {
Expand All @@ -392,8 +390,8 @@ public static function api_set_keys( $request ) {
update_option( 'newspack_newsletters_mjml_api_key', $mjml_api_key );
update_option( 'newspack_newsletters_mjml_api_secret', $mjml_api_secret );
} else {
$wp_error->add(
'newspack_newsletters_invalid_keys_mjml',
$wp_error->add(
'newspack_newsletters_invalid_keys_mjml',
__( 'Please input valid MJML application ID and secret key.', 'newspack-newsletters' )
);
}
Expand Down

0 comments on commit c0d8b23

Please sign in to comment.