Skip to content

Commit

Permalink
Subscriptions Block: Remove logged in view for wpcom (#18550)
Browse files Browse the repository at this point in the history
* Remove logged in view for wpcom and match terminology to editor.

* Fix linting errors.

* Ignore escape error because this pre existed and we need autop.

* remove unused variable

* Remove unused function

See https://github.com/Automattic/jetpack/pull/18550/files?diff=unified&w=1#r566354742

Co-authored-by: Jeremy Herve <[email protected]>
  • Loading branch information
apeatling and jeherve authored Feb 11, 2021
1 parent 24e7506 commit 32919e1
Showing 1 changed file with 59 additions and 120 deletions.
179 changes: 59 additions & 120 deletions projects/plugins/jetpack/modules/subscriptions/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ function widget( $args, $instance ) {

self::render_widget_status_messages( $instance );

if ( self::is_current_user_subscribed() ) {
self::render_widget_already_subscribed( $instance );
} else {
self::render_widget_subscription_form( $args, $instance, $subscribe_email );
}
self::render_widget_subscription_form( $args, $instance, $subscribe_email );

echo "\n" . $after_widget;
}
Expand Down Expand Up @@ -254,33 +250,6 @@ static function render_widget_status_messages( $instance ) {
}
}

/**
* Renders a message to folks who are already subscribed.
*
* @param array $instance The settings for the particular instance of the widget.
*
* @return void
*/
static function render_widget_already_subscribed( $instance ) {
if ( self::is_wpcom() ) {
$subscribers_total = self::fetch_subscriber_count();
$edit_subs_url = 'https://wordpress.com/following/edit/';
if ( function_exists( 'localized_wpcom_url' ) ) {
$edit_subs_url = localized_wpcom_url( http() . '://wordpress.com/following/edit/', get_user_locale() );
}
$show_subscribers_total = (bool) $instance['show_subscribers_total'];
if ( $show_subscribers_total && $subscribers_total > 1 ) :
$subscribers_not_me = $subscribers_total - 1;
/* translators: %s: number of folks following the blog */
?>
<p><?php printf( _n( 'You are following this blog, along with %s other amazing person (<a href="%s">manage</a>).', 'You are following this blog, along with %s other amazing people (<a href="%s">manage</a>).', $subscribers_not_me ), number_format_i18n( $subscribers_not_me ), $edit_subs_url ) ?></p><?php
else :
?>
<p><?php printf( __( 'You are following this blog (<a href="%s">manage</a>).' ), $edit_subs_url ) ?></p><?php
endif;
}
}

/**
* Renders a form allowing folks to subscribe to the blog.
*
Expand All @@ -290,7 +259,6 @@ static function render_widget_already_subscribed( $instance ) {
*/
static function render_widget_subscription_form( $args, $instance, $subscribe_email ) {
$show_only_email_and_button = $instance['show_only_email_and_button'];
$subscribe_logged_in = isset( $instance['subscribe_logged_in'] ) ? stripslashes( $instance['subscribe_logged_in'] ) : '';
$show_subscribers_total = (bool) $instance['show_subscribers_total'];
$subscribe_text = empty( $instance['show_only_email_and_button'] ) ?
stripslashes( $instance['subscribe_text'] ) :
Expand Down Expand Up @@ -320,81 +288,62 @@ static function render_widget_subscription_form( $args, $instance, $subscribe_em
accept-charset="utf-8"
id="<?php echo esc_attr( $form_id ); ?>"
>
<?php if ( is_user_logged_in() ) : ?>
<?php
if ( ! $show_only_email_and_button ) {
echo wpautop( $subscribe_logged_in );
}
if ( $show_subscribers_total && $subscribers_total ) {
?>
<div class="jetpack-subscribe-count">
<p>
<?php
/* translators: %s: number of folks following the blog */
echo esc_html( sprintf( _n( 'Join %s other follower', 'Join %s other followers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
?>
</p>
</div>
<?php
}
?>
<?php else : ?>
<?php
if ( ! $show_only_email_and_button ) {
echo wpautop( $subscribe_text );
}
if ( $show_subscribers_total && $subscribers_total ) {
?>
<div class="jetpack-subscribe-count">
<p>
<?php
/* translators: %s: number of folks following the blog */
echo esc_html( sprintf( _n( 'Join %s other follower', 'Join %s other followers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
?>
</p>
</div>
<?php
}
$email_field_id = 'subscribe-field';
$email_field_id .= self::$instance_count > 1
? '-' . self::$instance_count
: '';
$label_field_id = $email_field_id . '-label';
<?php
if ( ! $show_only_email_and_button ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo wpautop( $subscribe_text );
}
if ( $show_subscribers_total && $subscribers_total ) {
?>
<p id="subscribe-email">
<label
id="<?php echo esc_attr( $label_field_id ); ?>"
for="<?php echo esc_attr( $email_field_id ); ?>"
class="screen-reader-text"
>
<?php echo esc_html__( 'Email Address:', 'jetpack' ); ?>
</label>

<div class="jetpack-subscribe-count">
<p>
<?php
printf(
'<input
type="text"
name="email"
%1$s
style="%2$s"
placeholder="%3$s"
value=""
id="%4$s"
/>',
( ! empty( $email_field_classes )
? 'class="' . esc_attr( $email_field_classes ) . '"'
: ''
),
( ! empty( $email_field_styles )
? esc_attr( $email_field_styles )
: 'width: 95%; padding: 1px 10px'
),
esc_attr__( 'Enter your email address' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- This is only used on WordPress.com.
esc_attr( $email_field_id )
);
/* translators: %s: number of folks following the blog */
echo esc_html( sprintf( _n( 'Join %s other follower', 'Join %s other followers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
?>
</p>
<?php endif; ?>
</p>
</div>
<?php
}
$email_field_id = 'subscribe-field';
$email_field_id .= self::$instance_count > 1
? '-' . self::$instance_count
: '';
$label_field_id = $email_field_id . '-label';
?>
<p id="subscribe-email">
<label
id="<?php echo esc_attr( $label_field_id ); ?>"
for="<?php echo esc_attr( $email_field_id ); ?>"
class="screen-reader-text"
>
<?php echo esc_html__( 'Email Address:', 'jetpack' ); ?>
</label>

<?php
printf(
'<input
type="text"
name="email"
%1$s
style="%2$s"
placeholder="%3$s"
value=""
id="%4$s"
/>',
( ! empty( $email_field_classes )
? 'class="' . esc_attr( $email_field_classes ) . '"'
: ''
),
( ! empty( $email_field_styles )
? esc_attr( $email_field_styles )
: 'width: 95%; padding: 1px 10px'
),
esc_attr__( 'Enter your email address', 'jetpack' ),
esc_attr( $email_field_id )
);
?>
</p>

<p id="subscribe-submit">
<input type="hidden" name="action" value="subscribe"/>
Expand Down Expand Up @@ -643,21 +592,11 @@ static function defaults() {
'show_only_email_and_button' => false
);

if ( self::is_jetpack() ) {
$defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
$defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
$defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
$defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
$defaults['success_message'] = esc_html__( "Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm Follow' to start subscribing.", 'jetpack' );
}

if ( self::is_wpcom() ) {
$defaults['title'] = __( 'Follow Blog via Email' );
$defaults['title_following'] = __( 'You are following this blog' );
$defaults['subscribe_text'] = __( 'Enter your email address to follow this blog and receive notifications of new posts by email.' );
$defaults['subscribe_button'] = __( 'Follow' );
$defaults['subscribe_logged_in'] = __( 'Click to follow this blog and receive notifications of new posts by email.' );
}
$defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
$defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
$defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
$defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
$defaults['success_message'] = esc_html__( "Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm Follow' to start subscribing.", 'jetpack' );

return $defaults;
}
Expand Down

0 comments on commit 32919e1

Please sign in to comment.