← All changes
|
jetpack_vendor/automattic/jetpack-connection/src/class-error-handler.php
+42
-5
16.3-a.1
→
16.3
View file →
| @@ -277,8 +277,9 @@ | ||
| 277 | 277 | * (e.g. 'none' to suppress the reconnect CTA); when absent, readers fall back |
| 278 | 278 | * to offering the reconnect CTA. |
| 279 | 279 | * |
| 280 | 280 | * @since 6.13.10 |
| 281 | + * @since 9.8.0 Withholds a non-admin's reconnect CTA while a site connection error is on record. | |
| 281 | 282 | * |
| 282 | 283 | * @return array Array of displayable errors with hierarchical structure. |
| 283 | 284 | * Example: |
| 284 | 285 | * [ |
| @@ -323,8 +324,9 @@ | ||
| 323 | 324 | |
| 324 | 325 | // Viewer-wide, so resolved once rather than per error. |
| 325 | 326 | $viewer_can_connect = current_user_can( 'jetpack_connect' ); |
| 326 | 327 | $viewer_can_connect_user = current_user_can( 'jetpack_connect_user' ); |
| 328 | + $site_connection_broken = ! $viewer_can_connect && $this->has_site_connection_error( $verified_errors, $owner_id ); | |
| 327 | 329 | |
| 328 | 330 | foreach ( $verified_errors as $error_code => $users ) { |
| 329 | 331 | // Only process error codes that are meant to be displayed to users. |
| 330 | 332 | // A raw verified error whose code is marked non-displayable in |
| @@ -428,13 +430,13 @@ | ||
| 428 | 430 | : __( 'The connection owner needs to reconnect their WordPress.com account to restore the connection. If you reconnect instead, you will become the new connection owner and every other user will be disconnected from WordPress.com.', 'jetpack-connection' ); |
| 429 | 431 | } |
| 430 | 432 | } |
| 431 | 433 | |
| 432 | - // Relinking your own account and restoring the site are different actions | |
| 433 | - // with different capabilities, and this notice only offers the second one. | |
| 434 | - // A reporter-declared action is something else, so it is left alone. | |
| 435 | - if ( $viewer_owns_error && ! $viewer_can_connect && empty( $error['error_data']['action'] ) ) { | |
| 436 | - $action = 'none'; | |
| 434 | + // A non-admin relinks over the site connection, so while it is broken the | |
| 435 | + // reconnect CTA cannot work for them. A reporter-declared action is left alone. | |
| 436 | + if ( $viewer_owns_error && $site_connection_broken && empty( $error['error_data']['action'] ) ) { | |
| 437 | + $message = __( 'Your WordPress.com account connection is broken, and the site connection needs attention too. Ask an administrator to restore the site connection, then reconnect your account.', 'jetpack-connection' ); | |
| 438 | + $action = 'none'; | |
| 437 | 439 | } |
| 438 | 440 | |
| 439 | 441 | $error['audience'] = $audience; |
| 440 | 442 | $error['error_message'] = $message; |
| @@ -791,8 +793,43 @@ | ||
| 791 | 793 | return 'owner'; |
| 792 | 794 | } |
| 793 | 795 | |
| 794 | 796 | return 'user'; |
| 797 | + } | |
| 798 | + | |
| 799 | + /** | |
| 800 | + * Whether a displayable site-audience error is on record that would stop a user relinking. | |
| 801 | + * | |
| 802 | + * Codes that survive owner promotion are inbound failures (WordPress.com cannot reach or | |
| 803 | + * verify the site), which leave the outbound, blog-token-signed relink working. | |
| 804 | + * | |
| 805 | + * @since 9.8.0 | |
| 806 | + * | |
| 807 | + * @param array $verified_errors The verified errors, keyed by error code then user ID. | |
| 808 | + * @param int $owner_id The local user ID of the connection owner, or 0 if there is none. | |
| 809 | + * @return bool | |
| 810 | + */ | |
| 811 | + private function has_site_connection_error( $verified_errors, $owner_id ) { | |
| 812 | + foreach ( $verified_errors as $error_code => $users ) { | |
| 813 | + $display_config = $this->get_error_display_config( $error_code ); | |
| 814 | + | |
| 815 | + if ( null === $display_config || ! empty( $display_config['survives_owner_promotion'] ) || ! is_array( $users ) ) { | |
| 816 | + continue; | |
| 817 | + } | |
| 818 | + | |
| 819 | + foreach ( array_keys( $users ) as $user_id ) { | |
| 820 | + // Must precede classification, which would cast 'invalid' to 0 and read it as 'site'. | |
| 821 | + if ( 'invalid' === $user_id ) { | |
| 822 | + continue; | |
| 823 | + } | |
| 824 | + | |
| 825 | + if ( 'site' === $this->classify_error_audience( $user_id, $owner_id ) ) { | |
| 826 | + return true; | |
| 827 | + } | |
| 828 | + } | |
| 829 | + } | |
| 830 | + | |
| 831 | + return false; | |
| 795 | 832 | } |
| 796 | 833 | |
| 797 | 834 | /** |
| 798 | 835 | * Whether an error describes the connection owner's own connection. |