| @@ -36,9 +36,9 @@ | ||
| 36 | 36 | |
| 37 | 37 | // Refresh the token. |
| 38 | 38 | $result = $api->refresh_token(); |
| 39 | 39 | |
| 40 | - // If an error occurred, don't save the new tokens. | |
| 40 | + // If an error occured, don't save the new tokens. | |
| 41 | 41 | // Logging is handled by the ConvertKit_API_V4 class. |
| 42 | 42 | if ( is_wp_error( $result ) ) { |
| 43 | 43 | return; |
| 44 | 44 | } |
| @@ -67,17 +67,8 @@ | ||
| 67 | 67 | // Get Settings and Log classes. |
| 68 | 68 | $settings = new ConvertKit_Settings(); |
| 69 | 69 | $log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH ); |
| 70 | 70 | |
| 71 | - // Bail if no access and refresh token exists. | |
| 72 | - if ( ! $settings->has_access_and_refresh_token() ) { | |
| 73 | - if ( $settings->debug_enabled() ) { | |
| 74 | - $log->add( 'CRON: convertkit_resource_refresh_posts(): No access and refresh token exists.' ); | |
| 75 | - } | |
| 76 | - | |
| 77 | - return; | |
| 78 | - } | |
| 79 | - | |
| 80 | 71 | // If debug logging is enabled, write to it now. |
| 81 | 72 | if ( $settings->debug_enabled() ) { |
| 82 | 73 | $log->add( 'CRON: convertkit_resource_refresh_posts(): Started' ); |
| 83 | 74 | } |
| @@ -85,20 +76,18 @@ | ||
| 85 | 76 | // Refresh Posts Resource. |
| 86 | 77 | $posts = new ConvertKit_Resource_Posts( 'cron' ); |
| 87 | 78 | $result = $posts->refresh(); |
| 88 | 79 | |
| 89 | - // Bail if an error occurred. | |
| 90 | - if ( is_wp_error( $result ) ) { | |
| 91 | - // Delete credentials if the error is a 401. | |
| 92 | - convertkit_maybe_delete_credentials( $result, CONVERTKIT_OAUTH_CLIENT_ID ); | |
| 93 | - | |
| 94 | - $log->add( 'CRON: convertkit_resource_refresh_posts(): Error: ' . $result->get_error_message() ); | |
| 95 | - return; | |
| 96 | - } | |
| 97 | - | |
| 98 | 80 | // If debug logging is enabled, write to it now. |
| 99 | 81 | if ( $settings->debug_enabled() ) { |
| 100 | - $log->add( 'CRON: convertkit_resource_refresh_posts(): Success: ' . count( $result ) . ' broadcasts fetched from API and cached.' ); | |
| 82 | + // If an error occured, log it. | |
| 83 | + if ( is_wp_error( $result ) ) { | |
| 84 | + $log->add( 'CRON: convertkit_resource_refresh_posts(): Error: ' . $result->get_error_message() ); | |
| 85 | + } | |
| 86 | + if ( is_array( $result ) ) { | |
| 87 | + $log->add( 'CRON: convertkit_resource_refresh_posts(): Success: ' . count( $result ) . ' broadcasts fetched from API and cached.' ); | |
| 88 | + } | |
| 89 | + | |
| 101 | 90 | $log->add( 'CRON: convertkit_resource_refresh_posts(): Finished' ); |
| 102 | 91 | } |
| 103 | 92 | |
| 104 | 93 | } |