| @@ -178,12 +178,30 @@ | ||
| 178 | 178 | $duplicates = $this->base->get_class( 'validation' )->check_for_duplicates( $settings ); |
| 179 | 179 | if ( is_array( $duplicates ) ) { |
| 180 | 180 | // Fetch Post Type Name, Profile Name and Action Name. |
| 181 | 181 | $post_type_object = get_post_type_object( $type ); |
| 182 | + | |
| 183 | + // Determine the Profile Name for the duplicate. | |
| 182 | 184 | if ( $duplicates['profile_id'] === 'default' ) { |
| 183 | 185 | $profile = __( 'Defaults', 'wp-to-buffer' ); |
| 184 | - } elseif ( isset( $profiles[ $profile_id ] ) ) { | |
| 185 | - $profile = $profiles[ $profile_id ]['formatted_service'] . ': ' . $profiles[ $profile_id ]['formatted_username']; | |
| 186 | + } else { | |
| 187 | + // Fetch connected Profiles, keyed by Profile ID. | |
| 188 | + $profiles = array(); | |
| 189 | + foreach ( $this->get_accounts() as $account_id => $account ) { | |
| 190 | + $this->base->get_class( 'api' )->set_tokens( $account['access_token'], $account['refresh_token'], $account['token_expires'] ); | |
| 191 | + $account_profiles = $this->base->get_class( 'api' )->profiles( false, $account_id ); | |
| 192 | + if ( is_wp_error( $account_profiles ) ) { | |
| 193 | + continue; | |
| 194 | + } | |
| 195 | + foreach ( $account_profiles as $account_profile ) { | |
| 196 | + $profiles[ $account_profile['id'] ] = $account_profile; | |
| 197 | + } | |
| 198 | + } | |
| 199 | + | |
| 200 | + // Use the Profile's formatted name if found, else the Profile ID. | |
| 201 | + $profile = ( isset( $profiles[ $duplicates['profile_id'] ] ) | |
| 202 | + ? $profiles[ $duplicates['profile_id'] ]['formatted_service'] . ': ' . $profiles[ $duplicates['profile_id'] ]['formatted_username'] | |
| 203 | + : $duplicates['profile_id'] ); | |
| 186 | 204 | } |
| 187 | 205 | $post_actions = $this->base->get_class( 'common' )->get_post_actions(); |
| 188 | 206 | $action = $post_actions[ $duplicates['action'] ]; |
| 189 | 207 | |
| @@ -211,9 +229,9 @@ | ||
| 211 | 229 | * |
| 212 | 230 | * @since 4.8.9 |
| 213 | 231 | * |
| 214 | 232 | * @param string|array $value Setting value. |
| 215 | - * @return string Setting value | |
| 233 | + * @return ($value is array ? array : string) Setting value | |
| 216 | 234 | */ |
| 217 | 235 | private function strip_tags_deep( $value ) { |
| 218 | 236 | |
| 219 | 237 | return is_array( $value ) ? array_map( array( $this, 'strip_tags_deep' ), $value ) : wp_strip_all_tags( $value ); |
| @@ -253,9 +271,8 @@ | ||
| 253 | 271 | * |
| 254 | 272 | * @since 3.4.0 |
| 255 | 273 | * |
| 256 | 274 | * @param array $settings Settings. |
| 257 | - * @param string $type Post Type. | |
| 258 | 275 | */ |
| 259 | 276 | $settings = apply_filters( $this->base->plugin->filter_name . '_default_installation_settings', $settings ); |
| 260 | 277 | |
| 261 | 278 | // Return. |
| @@ -525,10 +542,10 @@ | ||
| 525 | 542 | /** |
| 526 | 543 | * Default Publish or Update enabled |
| 527 | 544 | * 1+ Profiles enabled without override |
| 528 | 545 | */ |
| 529 | - $default_publish_action_enabled = $this->get_setting( $post_type, '[default][publish][enabled]', 0 ); | |
| 530 | - $default_update_action_enabled = $this->get_setting( $post_type, '[default][update][enabled]', 0 ); | |
| 546 | + $default_publish_action_enabled = $this->get_setting( $post_type, '[default][publish][enabled]', '0' ); | |
| 547 | + $default_update_action_enabled = $this->get_setting( $post_type, '[default][update][enabled]', '0' ); | |
| 531 | 548 | if ( $default_publish_action_enabled || $default_update_action_enabled ) { |
| 532 | 549 | foreach ( $settings as $profile_id => $profile_settings ) { |
| 533 | 550 | // Skip defaults. |
| 534 | 551 | if ( $profile_id === 'default' ) { |
| @@ -588,32 +605,8 @@ | ||
| 588 | 605 | |
| 589 | 606 | } |
| 590 | 607 | |
| 591 | 608 | /** |
| 592 | - * Runs the given individual status settings through validation. | |
| 593 | - * | |
| 594 | - * @since 3.7.3 | |
| 595 | - * | |
| 596 | - * @param array $status Status Message Settings. | |
| 597 | - * @return array Status Message Settings | |
| 598 | - */ | |
| 599 | - private function validate_status( $status ) { | |
| 600 | - | |
| 601 | - /** | |
| 602 | - * Filters status settings during validation, allowing them to be changed. | |
| 603 | - * | |
| 604 | - * @since 3.7.3 | |
| 605 | - * | |
| 606 | - * @param array $status Status. | |
| 607 | - */ | |
| 608 | - $status = apply_filters( $this->base->plugin->filter_name . '_settings_validate_status', $status ); | |
| 609 | - | |
| 610 | - // Return. | |
| 611 | - return $status; | |
| 612 | - | |
| 613 | - } | |
| 614 | - | |
| 615 | - /** | |
| 616 | 609 | * Returns all accounts and their access token, refresh token and token expiry values. |
| 617 | 610 | * |
| 618 | 611 | * @since 5.4.0 |
| 619 | 612 | * |
| @@ -634,9 +627,9 @@ | ||
| 634 | 627 | */ |
| 635 | 628 | public function account_connected() { |
| 636 | 629 | |
| 637 | 630 | $accounts = $this->get_accounts(); |
| 638 | - return ! empty( $accounts ) && count( $accounts ) > 0; | |
| 631 | + return ! empty( $accounts ); | |
| 639 | 632 | |
| 640 | 633 | } |
| 641 | 634 | |
| 642 | 635 | /** |
| @@ -672,9 +665,9 @@ | ||
| 672 | 665 | 'profile_ids' => $profile_ids, |
| 673 | 666 | ); |
| 674 | 667 | |
| 675 | 668 | // Update the accounts. |
| 676 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 669 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 677 | 670 | |
| 678 | 671 | } |
| 679 | 672 | |
| 680 | 673 | /** |
| @@ -702,13 +695,48 @@ | ||
| 702 | 695 | $accounts[ $account_id ]['refresh_token'] = $refresh_token; |
| 703 | 696 | $accounts[ $account_id ]['token_expires'] = $token_expires; |
| 704 | 697 | |
| 705 | 698 | // Update the accounts. |
| 706 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 699 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 707 | 700 | |
| 708 | 701 | } |
| 709 | 702 | |
| 710 | 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 | + /** | |
| 711 | 739 | * Updates the information for the given account ID. |
| 712 | 740 | * |
| 713 | 741 | * @since 6.0.0 |
| 714 | 742 | * |
| @@ -736,9 +764,9 @@ | ||
| 736 | 764 | $accounts[ $account_id ]['channel_limit'] = $account_channel_limit; |
| 737 | 765 | $accounts[ $account_id ]['profile_ids'] = $profile_ids; |
| 738 | 766 | |
| 739 | 767 | // Update the accounts. |
| 740 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 768 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 741 | 769 | |
| 742 | 770 | } |
| 743 | 771 | |
| 744 | 772 | /** |
| @@ -762,9 +790,9 @@ | ||
| 762 | 790 | // Update the account profile IDs. |
| 763 | 791 | $accounts[ $account_id ]['profile_ids'] = $profile_ids; |
| 764 | 792 | |
| 765 | 793 | // Update the accounts. |
| 766 | - update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 794 | + update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 767 | 795 | |
| 768 | 796 | } |
| 769 | 797 | |
| 770 | 798 | /** |
| @@ -786,9 +814,9 @@ | ||
| 786 | 814 | // Delete the stored profiles for this account. |
| 787 | 815 | delete_option( $this->base->plugin->name . '-profiles-' . $account_id ); |
| 788 | 816 | |
| 789 | 817 | // Update the accounts. |
| 790 | - return update_option( $this->base->plugin->settingsName . '-accounts', $accounts ); | |
| 818 | + return update_option( $this->base->plugin->settingsName . '-accounts', $accounts, false ); | |
| 791 | 819 | |
| 792 | 820 | } |
| 793 | 821 | |
| 794 | 822 | /** |
| @@ -913,11 +941,11 @@ | ||
| 913 | 941 | * Helper method to store a value to the options table |
| 914 | 942 | * |
| 915 | 943 | * @since 3.0.0 |
| 916 | 944 | * |
| 917 | - * @param string $key Key. | |
| 918 | - * @param string $value Value. | |
| 919 | - * @return bool Success | |
| 945 | + * @param string $key Key. | |
| 946 | + * @param string|array $value Value. | |
| 947 | + * @return bool Success | |
| 920 | 948 | */ |
| 921 | 949 | public function update_option( $key, $value ) { |
| 922 | 950 | |
| 923 | 951 | // Depending on the key, perform some validation before saving. |
| @@ -927,9 +955,9 @@ | ||
| 927 | 955 | * - Remove duplicate keys. |
| 928 | 956 | */ |
| 929 | 957 | case 'custom_tags': |
| 930 | 958 | // Skip validation if there are no custom field key/values to validate. |
| 931 | - if ( count( $value ) === 0 ) { | |
| 959 | + if ( ! is_array( $value ) || count( $value ) === 0 ) { | |
| 932 | 960 | break; |
| 933 | 961 | } |
| 934 | 962 | |
| 935 | 963 | foreach ( $value as $post_type => $custom_tags ) { |