diff --git a/includes/class-newspack-newsletters.php b/includes/class-newspack-newsletters.php index b7cbbcc25..3e00e6ba3 100644 --- a/includes/class-newspack-newsletters.php +++ b/includes/class-newspack-newsletters.php @@ -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 ); @@ -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 { @@ -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 { @@ -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' ) ); }