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 +25 -1 6.0.76.2.5 View file →
@@ -41,5 +41,29 @@
41 41
42 42 }
43 43
44 44 // Update Access Token when refreshed by the API class.
45 -add_action( 'wp_to_buffer_pro_api_refresh_token', 'wp_to_buffer_update_credentials', 10, 3 );
45 +add_action( 'wp_to_buffer_api_refresh_token', 'wp_to_buffer_update_credentials', 10, 3 );
46 +
47 +/**
48 + * Clears stored credentials when a refresh returns invalid_grant, which is terminal.
49 + *
50 + * @since 6.2.5
51 + *
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.
56 + */
57 +function wp_to_buffer_revoke_credentials( $result, $client_id, $existing_access_token, $existing_refresh_token ) {
58 +
59 + // Don't revoke credentials if the error is not invalid_grant.
60 + if ( $result->get_error_code() !== 'invalid_grant' ) {
61 + return;
62 + }
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 +
68 +}
69 +add_action( 'wp_to_buffer_api_refresh_token_error', 'wp_to_buffer_revoke_credentials', 10, 4 );