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 a5164dc
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 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 Expand Up @@ -754,8 +752,6 @@ public static function sync_with_mailchimp( $post ) {
],
];

$mc_campaign_id = null;

$mc_campaign_id = get_post_meta( $post->ID, 'mc_campaign_id', true );
if ( $mc_campaign_id ) {
$campaign_result = $mc->patch( "campaigns/$mc_campaign_id", $payload );
Expand Down

0 comments on commit a5164dc

Please sign in to comment.