| @@ -665,9 +665,9 @@ | ||
| 665 | 665 | 'profile_ids' => $profile_ids, |
| 666 | 666 | ); |
| 667 | 667 | |
| 668 | 668 | // Update the accounts. |
| 669 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 669 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 670 | 670 | |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
| @@ -695,13 +695,48 @@ | ||
| 695 | 695 | $accounts[ $account_id ]['refresh_token'] = $refresh_token; |
| 696 | 696 | $accounts[ $account_id ]['token_expires'] = $token_expires; |
| 697 | 697 | |
| 698 | 698 | // Update the accounts. |
| 699 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 699 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 700 | 700 | |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
| 704 | + * Clears the stored tokens for the account holding the given refresh token. | |
| 705 | + * Keyed on the refresh token, so a token already rotated by another request won't match. | |
| 706 | + * | |
| 707 | + * @since 6.2.5 | |
| 708 | + * | |
| 709 | + * @param string $refresh_token Refresh Token that was rejected. | |
| 710 | + * @return bool Whether an account was cleared. | |
| 711 | + */ | |
| 712 | + public function clear_account_credentials_by_refresh_token( $refresh_token ) { | |
| 713 | + | |
| 714 | + if ( empty( $refresh_token ) ) { | |
| 715 | + return false; | |
| 716 | + } | |
| 717 | + | |
| 718 | + $accounts = $this->get_accounts(); | |
| 719 | + foreach ( $accounts as $account_id => $account ) { | |
| 720 | + if ( $account['refresh_token'] !== $refresh_token ) { | |
| 721 | + continue; | |
| 722 | + } | |
| 723 | + | |
| 724 | + // Clear tokens so the dead token stops being presented and the Reconnect button shows. | |
| 725 | + $accounts[ $account_id ]['access_token'] = ''; | |
| 726 | + $accounts[ $account_id ]['refresh_token'] = ''; | |
| 727 | + $accounts[ $account_id ]['token_expires'] = 0; | |
| 728 | + | |
| 729 | + // Update the accounts. | |
| 730 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 731 | + return true; | |
| 732 | + } | |
| 733 | + | |
| 734 | + return false; | |
| 735 | + | |
| 736 | + } | |
| 737 | + | |
| 738 | + /** | |
| 704 | 739 | * Updates the information for the given account ID. |
| 705 | 740 | * |
| 706 | 741 | * @since 6.0.0 |
| 707 | 742 | * |
| @@ -729,9 +764,9 @@ | ||
| 729 | 764 | $accounts[ $account_id ]['channel_limit'] = $account_channel_limit; |
| 730 | 765 | $accounts[ $account_id ]['profile_ids'] = $profile_ids; |
| 731 | 766 | |
| 732 | 767 | // Update the accounts. |
| 733 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 768 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 734 | 769 | |
| 735 | 770 | } |
| 736 | 771 | |
| 737 | 772 | /** |
| @@ -755,9 +790,9 @@ | ||
| 755 | 790 | // Update the account profile IDs. |
| 756 | 791 | $accounts[ $account_id ]['profile_ids'] = $profile_ids; |
| 757 | 792 | |
| 758 | 793 | // Update the accounts. |
| 759 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 794 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 760 | 795 | |
| 761 | 796 | } |
| 762 | 797 | |
| 763 | 798 | /** |
| @@ -779,9 +814,9 @@ | ||
| 779 | 814 | // Delete the stored profiles for this account. |
| 780 | 815 | delete_option( $this->base->plugin->name . '-profiles-' . $account_id ); |
| 781 | 816 | |
| 782 | 817 | // Update the accounts. |
| 783 | - return update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 818 | + return update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 784 | 819 | |
| 785 | 820 | } |
| 786 | 821 | |
| 787 | 822 | /** |