PluginProbe
Social Media Auto Poster – Schedule & Publish to Buffer / 6.2.5
Social Media Auto Poster – Schedule & Publish to Buffer v6.2.5
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.2 6.1.1 6.1.0 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 All 126 releases
← All changes | includes/functions.php +16 -9 6.2.06.2.5 View file →
@@ -44,19 +44,26 @@
44 44 // Update Access Token when refreshed by the API class.
45 45 add_action( 'wp_to_buffer_api_refresh_token', 'wp_to_buffer_update_credentials', 10, 3 );
46 46
47 47 /**
48 - * Schedules the WordPress Cron event to refresh the access token before it expires.
48 + * Clears stored credentials when a refresh returns invalid_grant, which is terminal.
49 49 *
50 - * Runs whenever an access token is refreshed, so that each token schedules the
51 - * refresh of its successor.
50 + * @since 6.2.5
52 51 *
53 - * @since 6.2.0
52 + * @param \WP_Error $result Error from API.
53 + * @param string $client_id OAuth Client ID.
54 + * @param string $existing_access_token Existing Access Token.
55 + * @param string $existing_refresh_token Existing Refresh Token.
54 56 */
55 -function wp_to_buffer_schedule_refresh_token_event() {
57 +function wp_to_buffer_revoke_credentials( $result, $client_id, $existing_access_token, $existing_refresh_token ) {
56 58
57 - WP_To_Buffer::get_instance()->get_class( 'cron' )->reschedule_refresh_token_event();
59 + // Don't revoke credentials if the error is not invalid_grant.
60 + if ( $result->get_error_code() !== 'invalid_grant' ) {
61 + return;
62 + }
58 63
64 + // Revoke credentials by removing them from the account.
65 + $wp_to_buffer = WP_To_Buffer::get_instance();
66 + $wp_to_buffer->get_class( 'settings' )->clear_account_credentials_by_refresh_token( $existing_refresh_token );
67 +
59 68 }
60 -
61 -// Schedule the next token refresh whenever a token is refreshed.
62 -add_action( 'wp_to_buffer_api_refresh_token', 'wp_to_buffer_schedule_refresh_token_event', 20 );
69 +add_action( 'wp_to_buffer_api_refresh_token_error', 'wp_to_buffer_revoke_credentials', 10, 4 );