Skip to content

Commit

Permalink
Subscriptions: inform a clear error for pending confirmations (#14326)
Browse files Browse the repository at this point in the history
* [not verified] Rebase from the master branch and resolve conflict after #14275 is merged

* Fix the space issue (again)

* Add rel attribute

Co-Authored-By: Jeremy Herve <jeremy@jeremy.hu>

* Fix PHPCS error for switch statement

* Update wording.

Co-authored-by: Jeremy Herve <jeremy@tagada.hu>
Co-authored-by: Brandon Kraft <public@brandonkraft.com>
  • Loading branch information
3 people committed Jan 27, 2020
1 parent 6ac061c commit 67ca6cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
38 changes: 22 additions & 16 deletions modules/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ function get_settings() {
* not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email.
* disabled : Site owner has disabled subscriptions.
* active : Already subscribed.
* pending : Tried to subscribe before but the confirmation link is never clicked. No confirmation email is sent.
* unknown : strange error. Jetpack servers at WordPress.com returned something malformed.
* unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand.
*/
Expand Down Expand Up @@ -577,21 +578,24 @@ function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array()
}

switch ( $response[0]['status'] ) {
case 'error' :
$r[] = new Jetpack_Error( 'not_subscribed' );
continue 2;
case 'disabled' :
$r[] = new Jetpack_Error( 'disabled' );
continue 2;
case 'active' :
$r[] = new Jetpack_Error( 'active' );
continue 2;
case 'pending' :
$r[] = true;
continue 2;
default :
$r[] = new Jetpack_Error( 'unknown_status', (string) $response[0]['status'] );
continue 2;
case 'error':
$r[] = new Jetpack_Error( 'not_subscribed' );
continue 2;
case 'disabled':
$r[] = new Jetpack_Error( 'disabled' );
continue 2;
case 'active':
$r[] = new Jetpack_Error( 'active' );
continue 2;
case 'confirming':
$r[] = true;
continue 2;
case 'pending':
$r[] = new Jetpack_Error( 'pending' );
continue 2;
default:
$r[] = new Jetpack_Error( 'unknown_status', (string) $response[0]['status'] );
continue 2;
}
}

Expand Down Expand Up @@ -655,12 +659,14 @@ function widget_submit() {
$result = 'opted_out';
break;
case 'active':
case 'pending':
$result = 'already';
break;
case 'flooded_email':
$result = 'many_pending_subs';
break;
case 'pending':
$result = 'pending';
break;
default:
$result = 'error';
break;
Expand Down
17 changes: 17 additions & 0 deletions modules/subscriptions/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ static function render_widget_status_messages( $instance ) {
?>
</p>
<?php break;
case 'pending':
?>
<p class="error">
<?php
printf(
wp_kses(
/* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
__( 'You subscribed this site before but you have not clicked the confirmation link yet. Please check your inbox. <br /> Otherwise, you can manage your preferences at <a href="%1$s" title="%2$s" target="_blank" rel="noopener noreferrer">subscribe.wordpress.com</a>.', 'jetpack' ),
self::$allowed_html_tags_for_message
),
'https://subscribe.wordpress.com/',
esc_attr__( 'Manage your email preferences.', 'jetpack' )
);
?>
</p>
<?php
break;
case 'success' : ?>
<div class="success"><?php echo wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total['value'] ), $success_message ) ); ?></div>
<?php break;
Expand Down

0 comments on commit 67ca6cf

Please sign in to comment.