PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.1.5
Jetpack – WP Security, Backup, Speed, & Growth v13.1.5
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / subscriptions / views.php
jetpack / modules / subscriptions Last commit date
subscribe-modal 2 years ago jetpack-user-content-link-redirection.php 2 years ago readme.md 7 years ago subscriptions.css 7 years ago views.php 2 years ago
views.php
1039 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4
5 /**
6 * Jetpack_Subscriptions_Widget main view class.
7 */
8 class Jetpack_Subscriptions_Widget extends WP_Widget {
9
10 const ID_BASE = 'blog_subscription';
11
12 /**
13 * Track number of rendered Subscription widgets. The count is used for class names and widget IDs.
14 *
15 * @var int
16 */
17 public static $instance_count = 0;
18
19 /**
20 * When printing the submit button, what tags are allowed.
21 *
22 * @var array
23 */
24 public static $allowed_html_tags_for_submit_button = array(
25 'br' => array(),
26 's' => array(),
27 'strong' => array(),
28 'em' => array(),
29 );
30
31 /**
32 * Use this variable when printing the message after submitting an email in subscription widgets
33 *
34 * @var array what tags are allowed
35 */
36 public static $allowed_html_tags_for_message = array(
37 'a' => array(
38 'href' => array(),
39 'title' => array(),
40 'rel' => array(),
41 'target' => array(),
42 ),
43 'br' => array(),
44 );
45
46 /**
47 * Jetpack_Subscriptions_Widget constructor.
48 */
49 public function __construct() {
50 $widget_ops = array(
51 'classname' => 'widget_blog_subscription jetpack_subscription_widget',
52 'description' => __( 'Add an email signup form to allow people to subscribe to your blog.', 'jetpack' ),
53 'customize_selective_refresh' => true,
54 'show_instance_in_rest' => true,
55 );
56
57 $name = self::is_jetpack() ?
58 /** This filter is documented in modules/widgets/facebook-likebox.php */
59 apply_filters( 'jetpack_widget_name', __( 'Blog Subscriptions', 'jetpack' ) ) :
60 __( 'Follow Blog', 'jetpack' );
61
62 parent::__construct(
63 'blog_subscription',
64 $name,
65 $widget_ops
66 );
67
68 if ( self::is_jetpack() &&
69 (
70 is_active_widget( false, false, $this->id_base ) ||
71 is_active_widget( false, false, 'monster' ) ||
72 is_customize_preview()
73 )
74 ) {
75 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
76 }
77
78 add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
79 }
80
81 /**
82 * Remove the "Blog Subscription" widget from the Legacy Widget block
83 *
84 * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block.
85 * @return array $widget_types New list of widgets that will be removed.
86 */
87 public function hide_widget_in_block_editor( $widget_types ) {
88 $widget_types[] = self::ID_BASE;
89 return $widget_types;
90 }
91
92 /**
93 * Enqueue the form's CSS.
94 *
95 * @since 4.5.0
96 */
97 public function enqueue_style() {
98 wp_register_style(
99 'jetpack-subscriptions',
100 plugins_url( 'subscriptions.css', __FILE__ ),
101 array(),
102 JETPACK__VERSION
103 );
104 wp_enqueue_style( 'jetpack-subscriptions' );
105 }
106
107 /**
108 * Renders a full widget either within the context of WordPress widget, or in response to a shortcode.
109 *
110 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
111 * @param array $instance The settings for the particular instance of the widget.
112 */
113 public function widget( $args, $instance ) {
114 if ( self::is_wpcom() && ! self::wpcom_has_status_message() && self::is_current_user_subscribed() ) {
115 return null;
116 }
117 if ( self::is_jetpack() &&
118 /** This filter is documented in modules/contact-form/grunion-contact-form.php */
119 false === apply_filters( 'jetpack_auto_fill_logged_in_user', false )
120 ) {
121 $subscribe_email = '';
122 } else {
123 $current_user = wp_get_current_user();
124 if ( ! empty( $current_user->user_email ) ) {
125 $subscribe_email = esc_attr( $current_user->user_email );
126 } else {
127 $subscribe_email = '';
128 }
129 }
130
131 $stats_action = self::is_jetpack() ? 'jetpack_subscriptions' : 'follow_blog';
132 /** This action is documented in modules/widgets/gravatar-profile.php */
133 do_action( 'jetpack_stats_extra', 'widget_view', $stats_action );
134
135 $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
136 $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
137 $instance = wp_parse_args( (array) $instance, static::defaults() );
138
139 echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
140
141 ++self::$instance_count;
142
143 self::render_widget_title( $args, $instance );
144
145 self::render_widget_status_messages( $instance );
146
147 self::render_widget_subscription_form( $args, $instance, $subscribe_email );
148
149 echo "\n" . $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
150 }
151
152 /**
153 * Prints the widget's title. If show_only_email_and_button is true, we will not show a title.
154 *
155 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
156 * @param array $instance The settings for the particular instance of the widget.
157 */
158 public static function render_widget_title( $args, $instance ) {
159 $show_only_email_and_button = $instance['show_only_email_and_button'];
160 $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
161 $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
162 if ( self::is_wpcom() && ! $show_only_email_and_button ) {
163 if ( self::is_current_user_subscribed() ) {
164 if ( ! empty( $instance['title_following'] ) ) {
165 echo $before_title . '<label for="subscribe-field' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' ) . '">' . esc_attr( $instance['title_following'] ) . '</label>' . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
166 }
167 } elseif ( ! empty( $instance['title'] ) ) {
168 echo $before_title . '<label for="subscribe-field' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' ) . '">' . $instance['title'] . '</label>' . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
169 }
170 }
171
172 if ( self::is_jetpack() && empty( $instance['show_only_email_and_button'] ) ) {
173 echo $args['before_title'] . $instance['title'] . $args['after_title'] . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
174 }
175 }
176
177 /**
178 * Prints the subscription block's status messages after someone has attempted to subscribe.
179 * Either a success message or an error message.
180 *
181 * @param array $instance The settings for the particular instance of the widget.
182 */
183 public static function render_widget_status_messages( $instance ) {
184 if ( self::is_jetpack() && isset( $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output.
185 $success_message = isset( $instance['success_message'] ) ? stripslashes( $instance['success_message'] ) : '';
186 $subscribers_total = self::fetch_subscriber_count();
187
188 switch ( $_GET['subscribe'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended
189 case 'invalid_email':
190 ?>
191 <p class="error"><?php esc_html_e( 'Oops! The email you used is invalid. Please try again.', 'jetpack' ); ?></p>
192 <?php
193 break;
194 case 'opted_out':
195 ?>
196 <p class="error">
197 <?php
198 printf(
199 wp_kses(
200 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link. */
201 __( 'Oops! It seems that the email you used has opted out of subscriptions. You can manage your preferences from the <a href="%1$s" title="%2$s" target="_blank">Subscriptions Manager</a>', 'jetpack' ),
202 self::$allowed_html_tags_for_message
203 ),
204 'https://subscribe.wordpress.com/',
205 esc_attr__( 'Subscriptions Manager', 'jetpack' )
206 );
207 ?>
208 </p>
209 <?php
210 break;
211 case 'already':
212 ?>
213 <p class="error">
214 <?php
215 printf(
216 wp_kses(
217 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link. */
218 __( 'You have already subscribed to this site. Please check your email inbox. You can manage your preferences from the <a href="%1$s" title="%2$s" target="_blank">Subscriptions Manager</a>.', 'jetpack' ),
219 self::$allowed_html_tags_for_message
220 ),
221 'https://subscribe.wordpress.com/',
222 esc_attr__( 'Subscriptions Manager', 'jetpack' )
223 );
224 ?>
225 </p>
226 <?php
227 break;
228 case 'many_pending_subs':
229 ?>
230 <p class="error">
231 <?php
232 printf(
233 wp_kses(
234 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
235 __( 'Oops! It seems you have several subscriptions pending confirmation. You can confirm or unsubscribe some from the <a href="%1$s" title="%2$s" target="_blank" rel="noopener noreferrer">Subscriptions Manager</a> before adding more.', 'jetpack' ),
236 self::$allowed_html_tags_for_message
237 ),
238 'https://subscribe.wordpress.com/',
239 esc_attr__( 'Subscriptions Manager', 'jetpack' )
240 );
241 ?>
242 </p>
243 <?php
244 break;
245 case 'pending':
246 ?>
247 <p class="error">
248 <?php
249 printf(
250 wp_kses(
251 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
252 __( 'It seems you already tried to subscribe with this email, but have not confirmed from the email link we sent. Please check your email inbox to confirm or you can manage your preferences from the <a href="%1$s" title="%2$s" target="_blank" rel="noopener noreferrer">Subscriptions Manager</a>.', 'jetpack' ),
253 self::$allowed_html_tags_for_message
254 ),
255 'https://subscribe.wordpress.com/',
256 esc_attr__( 'Subscriptions Manager', 'jetpack' )
257 );
258 ?>
259 </p>
260 <?php
261 break;
262 case 'success':
263 ?>
264 <div class="success"><?php echo wp_kses( wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total ), $success_message ) ), 'post' ); ?></div>
265 <?php
266 break;
267 default:
268 ?>
269 <p class="error"><?php esc_html_e( 'Oops! There was an error when subscribing. Please try again.', 'jetpack' ); ?></p>
270 <?php
271 break;
272 endswitch;
273 }
274
275 if ( self::is_wpcom() && self::wpcom_has_status_message() ) {
276 global $themecolors;
277 $message = '';
278
279 switch ( $_GET['blogsub'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
280 case 'confirming':
281 $message = __( 'Thank you! You can now check your email to confirm your subscription.', 'jetpack' );
282 break;
283 case 'blocked':
284 $message = __( 'Sorry but this email has been blocked for this subscription. <a href="https://en.support.wordpress.com/contact/">Contact us</a> if needed.', 'jetpack' );
285 break;
286 case 'flooded':
287 $message = __( 'Oops! It seems you have several subscriptions pending confirmation. You can confirm or unsubscribe some from the <a href="https://subscribe.wordpress.com/">Subscriptions Manager</a> before adding more.', 'jetpack' );
288 break;
289 case 'spammed':
290 /* translators: %s is a URL */
291 $message = sprintf( __( 'Sorry but this email has been blocked. It has too many subscriptions pending confirmation. Please confirm or unsubscribe some from the <a href="%s">Subscriptions Manager</a>.', 'jetpack' ), 'https://subscribe.wordpress.com/' );
292 break;
293 case 'subscribed':
294 $message = __( 'Hey! You were already subscribed.', 'jetpack' );
295 break;
296 case 'pending':
297 $message = __( 'It seems you already tried to subscribe. We just sent you another email so you can confirm the subscription.', 'jetpack' );
298 break;
299 case 'confirmed':
300 $message = __( 'Cool! You are now subscribed. Now you can check your email for more details and how to manage the subscription.', 'jetpack' );
301 break;
302 }
303
304 $border_color = isset( $themecolors['border'] ) ? " #{$themecolors['border']}" : '';
305
306 $redirect_fragment = self::get_redirect_fragment();
307 printf(
308 '<div id="%1$s" class="jetpack-sub-notification">%3$s</div>',
309 esc_attr( $redirect_fragment ),
310 esc_attr( $border_color ),
311 wp_kses_post( $message )
312 );
313 }
314 }
315
316 /**
317 * Generates the redirect fragment used after form submission.
318 *
319 * @param string $id is the specific id that will appear in the redirect fragment. If none is provided self::$instance_count will be used.
320 */
321 protected static function get_redirect_fragment( $id = null ) {
322 if ( $id === null ) {
323 return 'subscribe-blog' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' );
324 }
325
326 return 'subscribe-blog-' . $id;
327 }
328
329 /**
330 * Renders a form allowing folks to subscribe to the blog.
331 *
332 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
333 * @param array $instance The settings for the particular instance of the widget.
334 * @param string $subscribe_email The email to use to prefill the form.
335 */
336 public static function render_widget_subscription_form( $args, $instance, $subscribe_email ) {
337 $show_only_email_and_button = $instance['show_only_email_and_button'];
338 $show_subscribers_total = (bool) $instance['show_subscribers_total'];
339 $subscribers_total = self::fetch_subscriber_count();
340 $subscribe_text = empty( $instance['show_only_email_and_button'] ) ?
341 stripslashes( $instance['subscribe_text'] ) :
342 false;
343 $referer = esc_url_raw( ( is_ssl() ? 'https' : 'http' ) . '://' . ( isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : '' ) . ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '' ) );
344 $source = 'widget';
345 $widget_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : self::$instance_count;
346 $subscribe_button = ! empty( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : $instance['subscribe_button'];
347 $subscribe_placeholder = isset( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : '';
348 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? 'wp-block-button__link ' . $instance['submit_button_classes'] : 'wp-block-button__link';
349 $submit_button_styles = isset( $instance['submit_button_styles'] ) ? $instance['submit_button_styles'] : '';
350 $submit_button_wrapper_styles = isset( $instance['submit_button_wrapper_styles'] ) ? $instance['submit_button_wrapper_styles'] : '';
351 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
352 $email_field_styles = isset( $instance['email_field_styles'] ) ? $instance['email_field_styles'] : '';
353
354 // We need to include those in case Jetpack blocks are disabled
355 require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php';
356 require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
357 $post_access_level = \Jetpack_Memberships::get_post_access_level();
358
359 if ( self::is_wpcom() && ! self::wpcom_has_status_message() ) {
360 global $current_blog;
361
362 $url = defined( 'SUBSCRIBE_BLOG_URL' ) ? SUBSCRIBE_BLOG_URL : '';
363 $form_id = self::get_redirect_fragment();
364 ?>
365
366 <div class="wp-block-jetpack-subscriptions__container">
367 <form
368 action="<?php echo esc_url( $url ); ?>"
369 method="post"
370 accept-charset="utf-8"
371 data-blog="<?php echo esc_attr( get_current_blog_id() ); ?>"
372 data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>"
373 id="<?php echo esc_attr( $form_id ); ?>"
374 >
375 <?php
376 if ( ! $show_only_email_and_button ) {
377 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
378 echo wpautop( $subscribe_text );
379 }
380 $email_field_id = 'subscribe-field';
381 $email_field_id .= self::$instance_count > 1
382 ? '-' . self::$instance_count
383 : '';
384 $label_field_id = $email_field_id . '-label';
385 ?>
386 <p id="subscribe-email">
387 <label
388 id="<?php echo esc_attr( $label_field_id ); ?>"
389 for="<?php echo esc_attr( $email_field_id ); ?>"
390 class="screen-reader-text"
391 >
392 <?php echo esc_html__( 'Email Address:', 'jetpack' ); ?>
393 </label>
394
395 <?php
396 printf(
397 '<input
398 type="email"
399 name="email"
400 %1$s
401 style="%2$s"
402 placeholder="%3$s"
403 value=""
404 id="%4$s"
405 required
406 />',
407 ( ! empty( $email_field_classes )
408 ? 'class="' . esc_attr( $email_field_classes ) . '"'
409 : ''
410 ),
411 ( ! empty( $email_field_styles )
412 ? esc_attr( $email_field_styles )
413 : 'width: 95%; padding: 1px 10px'
414 ),
415 ( empty( $subscribe_placeholder ) ? esc_attr__( 'Enter your email address', 'jetpack' ) : esc_attr( $subscribe_placeholder ) ),
416 esc_attr( $email_field_id )
417 );
418 ?>
419 </p>
420
421 <p id="subscribe-submit"
422 <?php if ( ! empty( $submit_button_wrapper_styles ) ) { ?>
423 style="<?php echo esc_attr( $submit_button_wrapper_styles ); ?>"
424 <?php } ?>
425 >
426 <input type="hidden" name="action" value="subscribe"/>
427 <input type="hidden" name="blog_id" value="<?php echo (int) $current_blog->blog_id; ?>"/>
428 <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
429 <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
430 <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
431 <?php wp_nonce_field( 'blogsub_subscribe_' . $current_blog->blog_id, '_wpnonce', false ); ?>
432 <button type="submit"
433 <?php if ( ! empty( $submit_button_classes ) ) { ?>
434 class="<?php echo esc_attr( $submit_button_classes ); ?>"
435 <?php } ?>
436 <?php if ( ! empty( $submit_button_styles ) ) { ?>
437 style="<?php echo esc_attr( $submit_button_styles ); ?>"
438 <?php } ?>
439 >
440 <?php
441 echo wp_kses(
442 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
443 self::$allowed_html_tags_for_submit_button
444 );
445 ?>
446 </button>
447 </p>
448 </form>
449 <?php if ( $show_subscribers_total && $subscribers_total > 0 ) { ?>
450 <div class="wp-block-jetpack-subscriptions__subscount">
451 <?php
452 echo esc_html( Jetpack_Memberships::get_join_others_text( $subscribers_total ) );
453 ?>
454 </div>
455 <?php } ?>
456 </div>
457 <?php
458 }
459
460 if ( self::is_jetpack() ) {
461 /**
462 * Filter the subscription form's ID prefix.
463 *
464 * @module subscriptions
465 *
466 * @since 2.7.0
467 *
468 * @param string subscribe-field Subscription form field prefix.
469 * @param int $widget_id Widget ID.
470 */
471 $subscribe_field_id = apply_filters( 'subscribe_field_id', 'subscribe-field', $widget_id );
472
473 $form_id = self::get_redirect_fragment( $widget_id );
474 ?>
475 <div class="wp-block-jetpack-subscriptions__container">
476 <form action="#" method="post" accept-charset="utf-8" id="<?php echo esc_attr( $form_id ); ?>"
477 data-blog="<?php echo esc_attr( \Jetpack_Options::get_option( 'id' ) ); ?>"
478 data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>" >
479 <?php
480 if ( $subscribe_text && ( ! isset( $_GET['subscribe'] ) || 'success' !== $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output.
481 ?>
482 <div id="subscribe-text"><?php echo wp_kses( wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total ), $subscribe_text ) ), 'post' ); ?></div>
483 <?php
484 }
485
486 if ( ! isset( $_GET['subscribe'] ) || 'success' !== $_GET['subscribe'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display of unsubmitted form.
487 ?>
488 <p id="subscribe-email">
489 <label id="jetpack-subscribe-label"
490 class="screen-reader-text"
491 for="<?php echo esc_attr( $subscribe_field_id . '-' . $widget_id ); ?>">
492 <?php echo ! empty( $subscribe_placeholder ) ? esc_html( $subscribe_placeholder ) : esc_html__( 'Email Address:', 'jetpack' ); ?>
493 </label>
494 <input type="email" name="email" required="required"
495 <?php if ( ! empty( $email_field_classes ) ) { ?>
496 class="<?php echo esc_attr( $email_field_classes ); ?> required"
497 <?php } ?>
498 <?php if ( ! empty( $email_field_styles ) ) { ?>
499 style="<?php echo esc_attr( $email_field_styles ); ?>"
500 <?php } ?>
501 value="<?php echo esc_attr( $subscribe_email ); ?>"
502 id="<?php echo esc_attr( $subscribe_field_id . '-' . $widget_id ); ?>"
503 placeholder="<?php echo esc_attr( $subscribe_placeholder ); ?>"
504 />
505 </p>
506
507 <p id="subscribe-submit"
508 <?php if ( ! empty( $submit_button_wrapper_styles ) ) { ?>
509 style="<?php echo esc_attr( $submit_button_wrapper_styles ); ?>"
510 <?php } ?>
511 >
512 <input type="hidden" name="action" value="subscribe"/>
513 <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
514 <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
515 <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
516 <?php wp_nonce_field( 'blogsub_subscribe_' . \Jetpack_Options::get_option( 'id' ) ); ?>
517 <button type="submit"
518 <?php if ( ! empty( $submit_button_classes ) ) { ?>
519 class="<?php echo esc_attr( $submit_button_classes ); ?>"
520 <?php } ?>
521 <?php if ( ! empty( $submit_button_styles ) ) { ?>
522 style="<?php echo esc_attr( $submit_button_styles ); ?>"
523 <?php } ?>
524 name="jetpack_subscriptions_widget"
525 >
526 <?php
527 echo wp_kses(
528 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
529 self::$allowed_html_tags_for_submit_button
530 );
531 ?>
532 </button>
533 </p>
534 <?php } ?>
535 </form>
536 <?php if ( $show_subscribers_total && 0 < $subscribers_total ) { ?>
537 <div class="wp-block-jetpack-subscriptions__subscount">
538 <?php
539 echo esc_html( Jetpack_Memberships::get_join_others_text( $subscribers_total ) );
540 ?>
541 </div>
542 <?php } ?>
543 </div>
544 <?php
545 }
546 }
547
548 /**
549 * Determines if the current user is subscribed to the blog.
550 *
551 * @return bool Is the person already subscribed.
552 */
553 public static function is_current_user_subscribed() {
554 $subscribed = isset( $_GET['subscribe'] ) && 'success' === $_GET['subscribe']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
555
556 if ( self::is_wpcom() && class_exists( 'Blog_Subscription' ) && class_exists( 'Blog_Subscriber' ) ) {
557 $subscribed = is_user_logged_in() && Blog_Subscription::is_subscribed( new Blog_Subscriber() );
558 }
559
560 return $subscribed;
561 }
562
563 /**
564 * Is this script running in the wordpress.com environment?
565 *
566 * @return bool
567 */
568 public static function is_wpcom() {
569 return defined( 'IS_WPCOM' ) && IS_WPCOM;
570 }
571
572 /**
573 * Is this script running in a self-hosted environment?
574 *
575 * @return bool
576 */
577 public static function is_jetpack() {
578 return ! self::is_wpcom();
579 }
580
581 /**
582 * Used to determine if there is a valid status slug within the wordpress.com environment.
583 *
584 * @return bool
585 */
586 public static function wpcom_has_status_message() {
587 return isset( $_GET['blogsub'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
588 in_array(
589 $_GET['blogsub'], // phpcs:ignore WordPress.Security.NonceVerification.Recommended
590 array(
591 'confirming',
592 'blocked',
593 'flooded',
594 'spammed',
595 'subscribed',
596 'pending',
597 'confirmed',
598 ),
599 true
600 );
601 }
602
603 /**
604 * Determine the amount of folks currently subscribed to the blog.
605 *
606 * @return int
607 */
608 public static function fetch_subscriber_count() {
609 $subs_count = 0;
610 if ( self::is_jetpack() ) {
611 $cache_key = 'wpcom_subscribers_total';
612 $subs_count = get_transient( $cache_key );
613 if ( false === $subs_count || 'failed' === $subs_count['status'] ) {
614 $xml = new Jetpack_IXR_Client();
615 $xml->query( 'jetpack.fetchSubscriberCount' );
616
617 if ( $xml->isError() ) { // If we get an error from .com, set the status to failed so that we will try again next time the data is requested.
618
619 $subs_count = array(
620 'status' => 'failed',
621 'code' => $xml->getErrorCode(),
622 'message' => $xml->getErrorMessage(),
623 'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : 0,
624 );
625 } else {
626 $subs_count = array(
627 'status' => 'success',
628 'value' => $xml->getResponse(),
629 );
630 }
631 set_transient( $cache_key, $subs_count, 3600 ); // Try to cache the result for at least 1 hour.
632 }
633 return $subs_count['value'];
634 }
635
636 if ( self::is_wpcom() ) {
637 $subs_count = wpcom_reach_total_for_blog();
638 return $subs_count;
639 }
640 }
641
642 /**
643 * Updates a particular instance of a widget when someone saves it in wp-admin.
644 *
645 * @param array $new_instance New widget instance settings.
646 * @param array $old_instance Old widget instance settings.
647 *
648 * @return array
649 */
650 public function update( $new_instance, $old_instance ) {
651 $instance = $old_instance;
652
653 if ( self::is_jetpack() ) {
654 $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
655 $instance['subscribe_placeholder'] = wp_kses( stripslashes( $new_instance['subscribe_placeholder'] ), array() );
656 $instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
657 $instance['success_message'] = wp_kses( stripslashes( $new_instance['success_message'] ), array() );
658 }
659
660 if ( self::is_wpcom() ) {
661 $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
662 $instance['title_following'] = wp_strip_all_tags( stripslashes( $new_instance['title_following'] ) );
663 $instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
664 $instance['subscribe_button'] = wp_strip_all_tags( stripslashes( $new_instance['subscribe_button'] ) );
665 }
666
667 $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
668 $instance['show_only_email_and_button'] = isset( $new_instance['show_only_email_and_button'] ) && $new_instance['show_only_email_and_button'];
669 $instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
670
671 return $instance;
672 }
673
674 /**
675 * The default args for rendering a subscription form.
676 *
677 * @return array
678 */
679 public static function defaults() {
680 $defaults = array(
681 'show_subscribers_total' => true,
682 'show_only_email_and_button' => false,
683 'include_social_followers' => true,
684 );
685
686 $defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
687 $defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
688 $defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
689 $defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
690 $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' );
691
692 return $defaults;
693 }
694
695 /**
696 * Renders the widget's options form in wp-admin.
697 *
698 * @param array $instance Widget instance.
699 */
700 public function form( $instance ) {
701 $instance = wp_parse_args( (array) $instance, static::defaults() );
702 $show_subscribers_total = checked( $instance['show_subscribers_total'], true, false );
703
704 if ( self::is_wpcom() ) {
705 $title = esc_attr( stripslashes( $instance['title'] ) );
706 $title_following = esc_attr( stripslashes( $instance['title_following'] ) );
707 $subscribe_text = esc_attr( stripslashes( $instance['subscribe_text'] ) );
708 $subscribe_logged_in = esc_attr( stripslashes( $instance['subscribe_logged_in'] ) );
709 $subscribe_button = esc_attr( stripslashes( $instance['subscribe_button'] ) );
710 $subscribers_total = self::fetch_subscriber_count();
711 }
712
713 if ( self::is_jetpack() ) {
714 $title = stripslashes( $instance['title'] );
715 $subscribe_text = stripslashes( $instance['subscribe_text'] );
716 $subscribe_placeholder = stripslashes( $instance['subscribe_placeholder'] );
717 $subscribe_button = stripslashes( $instance['subscribe_button'] );
718 $success_message = stripslashes( $instance['success_message'] );
719 $subscribers_total = self::fetch_subscriber_count();
720 }
721
722 if ( self::is_wpcom() ) :
723 ?>
724 <p>
725 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
726 <?php esc_html_e( 'Widget title for non-followers:', 'jetpack' ); ?>
727 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
728 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
729 value="<?php echo esc_attr( $title ); ?>"/>
730 </label>
731 </p>
732 <p>
733 <label for="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>">
734 <?php esc_html_e( 'Widget title for followers:', 'jetpack' ); ?>
735 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>"
736 name="<?php echo esc_attr( $this->get_field_name( 'title_following' ) ); ?>" type="text"
737 value="<?php echo esc_attr( $title_following ); ?>"/>
738 </label>
739 </p>
740 <p>
741 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>">
742 <?php esc_html_e( 'Optional text to display to logged in WordPress.com users:', 'jetpack' ); ?>
743 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>"
744 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_logged_in' ) ); ?>"
745 type="text"><?php echo esc_html( $subscribe_logged_in ); ?></textarea>
746 </label>
747 </p>
748 <p>
749 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
750 <?php esc_html_e( 'Optional text to display to non-WordPress.com users:', 'jetpack' ); ?>
751 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
752 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
753 type="text"><?php echo esc_html( $subscribe_text ); ?></textarea>
754 </label>
755 </p>
756 <p>
757 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
758 <?php esc_html_e( 'Follow Button Text:', 'jetpack' ); ?>
759 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
760 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
761 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
762 </label>
763 </p>
764 <p>
765 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
766 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
767 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
768 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
769 <?php
770 /* translators: %s: Number of followers. */
771 echo esc_html( sprintf( _n( 'Show total number of followers? (%s follower)', 'Show total number of followers? (%s followers)', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
772 ?>
773 </label>
774 </p>
775 <?php
776 endif;
777
778 if ( self::is_jetpack() ) :
779 ?>
780 <p>
781 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
782 <?php esc_html_e( 'Widget title:', 'jetpack' ); ?>
783 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
784 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
785 value="<?php echo esc_attr( $title ); ?>"/>
786 </label>
787 </p>
788 <p>
789 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
790 <?php esc_html_e( 'Optional text to display to your readers:', 'jetpack' ); ?>
791 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
792 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
793 rows="3"><?php echo esc_html( $subscribe_text ); ?></textarea>
794 </label>
795 </p>
796 <p>
797 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>">
798 <?php esc_html_e( 'Subscribe Placeholder:', 'jetpack' ); ?>
799 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>"
800 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_placeholder' ) ); ?>" type="text"
801 value="<?php echo esc_attr( $subscribe_placeholder ); ?>"/>
802 </label>
803 </p>
804 <p>
805 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
806 <?php esc_html_e( 'Subscribe Button:', 'jetpack' ); ?>
807 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
808 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
809 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
810 </label>
811 </p>
812 <p>
813 <label for="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>">
814 <?php esc_html_e( 'Success Message Text:', 'jetpack' ); ?>
815 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>"
816 name="<?php echo esc_attr( $this->get_field_name( 'success_message' ) ); ?>"
817 rows="5"><?php echo esc_html( $success_message ); ?></textarea>
818 </label>
819 </p>
820 <p>
821 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
822 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
823 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
824 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
825 <?php
826 /* translators: %s: Number of subscribers. */
827 echo esc_html( sprintf( _n( 'Show total number of subscribers? (%s subscriber)', 'Show total number of subscribers? (%s subscribers)', $subscribers_total, 'jetpack' ), $subscribers_total ) );
828 ?>
829 </label>
830 </p>
831 <?php
832 endif;
833 }
834 }
835
836 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
837 class_alias( 'Jetpack_Subscriptions_Widget', 'Blog_Subscription_Widget' );
838 }
839
840 /**
841 * Classname / shortcode tag to use for the Subscriptions widget.
842 *
843 * @return string
844 */
845 function get_jetpack_blog_subscriptions_widget_classname() {
846 return ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ?
847 'Blog_Subscription_Widget' :
848 'Jetpack_Subscriptions_Widget';
849 }
850
851 /**
852 * Subscriptions widget form HTML output.
853 *
854 * @param array $instance Widget instance data.
855 */
856 function jetpack_do_subscription_form( $instance ) {
857 if ( empty( $instance ) || ! is_array( $instance ) ) {
858 $instance = array();
859 }
860
861 if ( empty( $instance['show_subscribers_total'] ) || 'false' === $instance['show_subscribers_total'] ) {
862 $instance['show_subscribers_total'] = false;
863 } else {
864 $instance['show_subscribers_total'] = true;
865 }
866
867 // the default behavior is to include the social followers
868 if ( empty( $instance['include_social_followers'] ) || 'true' === $instance['include_social_followers'] ) {
869 $instance['include_social_followers'] = true;
870 } else {
871 $instance['include_social_followers'] = false;
872 }
873
874 $show_only_email_and_button = isset( $instance['show_only_email_and_button'] ) ? $instance['show_only_email_and_button'] : false;
875 $submit_button_text = isset( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : '';
876
877 // Build up a string with the submit button's classes and styles and set it on the instance.
878 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? $instance['submit_button_classes'] : '';
879 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
880 $style = '';
881 $submit_button_styles = '';
882 $submit_button_wrapper_styles = '';
883 $email_field_styles = '';
884 $success_message = '';
885
886 if ( isset( $instance['custom_background_button_color'] ) && 'undefined' !== $instance['custom_background_button_color'] ) {
887 $submit_button_styles .= 'background: ' . $instance['custom_background_button_color'] . '; ';
888 }
889 if ( isset( $instance['custom_text_button_color'] ) && 'undefined' !== $instance['custom_text_button_color'] ) {
890 $submit_button_styles .= 'color: ' . $instance['custom_text_button_color'] . '; ';
891 }
892 if ( isset( $instance['custom_button_width'] ) && 'undefined' !== $instance['custom_button_width'] ) {
893 $submit_button_wrapper_styles .= 'width: ' . $instance['custom_button_width'] . '; ';
894 $submit_button_wrapper_styles .= 'max-width: 100%; ';
895
896 // Account for custom margins on inline forms.
897 if (
898 ! empty( $instance['custom_spacing'] ) &&
899 ! ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] )
900 ) {
901 $submit_button_styles .= 'width: calc(100% - ' . $instance['custom_spacing'] . 'px); ';
902 } else {
903 $submit_button_styles .= 'width: 100%; ';
904 }
905 }
906
907 if ( isset( $instance['custom_font_size'] ) && 'undefined' !== $instance['custom_font_size'] ) {
908 $style = 'font-size: ' . $instance['custom_font_size'];
909 $style .= is_numeric( $instance['custom_font_size'] ) ? 'px; ' : '; '; // Handle deprecated numeric font size values.
910
911 $submit_button_styles .= $style;
912 $email_field_styles .= $style;
913 }
914 if ( isset( $instance['custom_padding'] ) && 'undefined' !== $instance['custom_padding'] ) {
915 $style = 'padding: ' .
916 $instance['custom_padding'] . 'px ' .
917 round( $instance['custom_padding'] * 1.5 ) . 'px ' .
918 $instance['custom_padding'] . 'px ' .
919 round( $instance['custom_padding'] * 1.5 ) . 'px; ';
920
921 $submit_button_styles .= $style;
922 $email_field_styles .= $style;
923 }
924
925 $button_spacing = 0;
926 if ( ! empty( $instance['custom_spacing'] ) ) {
927 $button_spacing = $instance['custom_spacing'];
928 }
929 if ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] ) {
930 $submit_button_styles .= 'margin-top: ' . $button_spacing . 'px; ';
931 } else {
932 $submit_button_styles .= 'margin: 0px; '; // Reset Safari's 2px default margin for buttons affecting input and button union
933 $submit_button_styles .= 'margin-left: ' . $button_spacing . 'px; ';
934 }
935
936 if ( isset( $instance['custom_border_radius'] ) && 'undefined' !== $instance['custom_border_radius'] ) {
937 $style = 'border-radius: ' . $instance['custom_border_radius'] . 'px; ';
938 $submit_button_styles .= $style;
939 $email_field_styles .= $style;
940 }
941 if ( isset( $instance['custom_border_weight'] ) && 'undefined' !== $instance['custom_border_weight'] ) {
942 $style = 'border-width: ' . $instance['custom_border_weight'] . 'px; ';
943 $submit_button_styles .= $style;
944 $email_field_styles .= $style;
945 }
946 if ( isset( $instance['custom_border_color'] ) && 'undefined' !== $instance['custom_border_color'] ) {
947 $style =
948 'border-color: ' . $instance['custom_border_color'] . '; ' .
949 'border-style: solid;';
950
951 $submit_button_styles .= $style;
952 $email_field_styles .= $style;
953 }
954 if ( isset( $instance['success_message'] ) && 'undefined' !== $instance['success_message'] ) {
955 $success_message = wp_kses( stripslashes( $instance['success_message'] ), array() );
956 }
957
958 $instance = shortcode_atts(
959 Jetpack_Subscriptions_Widget::defaults(),
960 $instance,
961 'jetpack_subscription_form'
962 );
963
964 // These must come after the call to shortcode_atts().
965 $instance['submit_button_text'] = $submit_button_text;
966 $instance['show_only_email_and_button'] = $show_only_email_and_button;
967 if ( ! empty( $submit_button_classes ) ) {
968 $instance['submit_button_classes'] = $submit_button_classes;
969 }
970 if ( ! empty( $email_field_classes ) ) {
971 $instance['email_field_classes'] = $email_field_classes;
972 }
973
974 if ( ! empty( $submit_button_styles ) ) {
975 $instance['submit_button_styles'] = trim( $submit_button_styles );
976 }
977 if ( ! empty( $submit_button_wrapper_styles ) ) {
978 $instance['submit_button_wrapper_styles'] = trim( $submit_button_wrapper_styles );
979 }
980 if ( ! empty( $email_field_styles ) ) {
981 $instance['email_field_styles'] = trim( $email_field_styles );
982 }
983 if ( ! empty( $success_message ) ) {
984 $instance['success_message'] = trim( $success_message );
985 }
986
987 $args = array(
988 'before_widget' => '<div class="jetpack_subscription_widget">',
989 );
990 ob_start();
991 the_widget( get_jetpack_blog_subscriptions_widget_classname(), $instance, $args );
992 $output = ob_get_clean();
993
994 return $output;
995 }
996
997 add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' );
998 add_shortcode( 'blog_subscription_form', 'jetpack_do_subscription_form' );
999
1000 /**
1001 * Register the Subscriptions widget.
1002 */
1003 function jetpack_blog_subscriptions_init() {
1004 register_widget( get_jetpack_blog_subscriptions_widget_classname() );
1005 }
1006
1007 add_action( 'widgets_init', 'jetpack_blog_subscriptions_init' );
1008
1009 /**
1010 * Sets the default value for `subscription_options` site option.
1011 *
1012 * This default value is available across Simple, Atomic and Jetpack sites,
1013 * including the /sites/$site/settings endpoint.
1014 *
1015 * @param array $default Default `subscription_options` array.
1016 * @param string $option Option name.
1017 * @param bool $passed_default Whether `get_option()` passed a default value.
1018 *
1019 * @return array Default value of `subscription_options`.
1020 */
1021 function subscription_options_fallback( $default, $option, $passed_default ) {
1022 if ( $passed_default ) {
1023 return $default;
1024 }
1025
1026 $site_url = get_home_url();
1027 $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) );
1028
1029 return array(
1030 /* translators: Both %1$s and %2$s is site address */
1031 'invitation' => sprintf( __( "Howdy,\nYou recently subscribed to <a href='%1\$s'>%2\$s</a> and we need to verify the email you provided. Once you confirm below, you'll be able to receive and read new posts.\n\nIf you believe this is an error, ignore this message and nothing more will happen.", 'jetpack' ), $site_url, $display_url ),
1032 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ),
1033 /* translators: %1$s is the site address */
1034 'welcome' => sprintf( __( 'Cool, you are now subscribed to %1$s and will receive an email notification when a new post is published.', 'jetpack' ), $display_url ),
1035 );
1036 }
1037
1038 add_filter( 'default_option_subscription_options', 'subscription_options_fallback', 10, 3 );
1039