PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.0.3
Jetpack – WP Security, Backup, Speed, & Growth v12.0.3
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
readme.md 7 years ago subscriptions.css 7 years ago views.php 3 years ago
views.php
1055 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS;
3
4 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
5
6 /**
7 * Jetpack_Subscriptions_Widget main view class.
8 */
9 class Jetpack_Subscriptions_Widget extends WP_Widget {
10
11 const ID_BASE = 'blog_subscription';
12
13 /**
14 * Track number of rendered Subscription widgets. The count is used for class names and widget IDs.
15 *
16 * @var int
17 */
18 public static $instance_count = 0;
19
20 /**
21 * When printing the submit button, what tags are allowed.
22 *
23 * @var array
24 */
25 public static $allowed_html_tags_for_submit_button = array(
26 'br' => array(),
27 's' => array(),
28 'strong' => array(),
29 'em' => array(),
30 );
31
32 /**
33 * Use this variable when printing the message after submitting an email in subscription widgets
34 *
35 * @var array what tags are allowed
36 */
37 public static $allowed_html_tags_for_message = array(
38 'a' => array(
39 'href' => array(),
40 'title' => array(),
41 'rel' => array(),
42 'target' => array(),
43 ),
44 'br' => array(),
45 );
46
47 /**
48 * Jetpack_Subscriptions_Widget constructor.
49 */
50 public function __construct() {
51 $widget_ops = array(
52 'classname' => 'widget_blog_subscription jetpack_subscription_widget',
53 'description' => __( 'Add an email signup form to allow people to subscribe to your blog.', 'jetpack' ),
54 'customize_selective_refresh' => true,
55 'show_instance_in_rest' => true,
56 );
57
58 $name = self::is_jetpack() ?
59 /** This filter is documented in modules/widgets/facebook-likebox.php */
60 apply_filters( 'jetpack_widget_name', __( 'Blog Subscriptions', 'jetpack' ) ) :
61 __( 'Follow Blog', 'jetpack' );
62
63 parent::__construct(
64 'blog_subscription',
65 $name,
66 $widget_ops
67 );
68
69 if ( self::is_jetpack() &&
70 (
71 is_active_widget( false, false, $this->id_base ) ||
72 is_active_widget( false, false, 'monster' ) ||
73 is_customize_preview()
74 )
75 ) {
76 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
77 }
78
79 add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
80 }
81
82 /**
83 * Remove the "Blog Subscription" widget from the Legacy Widget block
84 *
85 * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block.
86 * @return array $widget_types New list of widgets that will be removed.
87 */
88 public function hide_widget_in_block_editor( $widget_types ) {
89 $widget_types[] = self::ID_BASE;
90 return $widget_types;
91 }
92
93 /**
94 * Enqueue the form's CSS.
95 *
96 * @since 4.5.0
97 */
98 public function enqueue_style() {
99 wp_register_style(
100 'jetpack-subscriptions',
101 plugins_url( 'subscriptions.css', __FILE__ ),
102 array(),
103 JETPACK__VERSION
104 );
105 wp_enqueue_style( 'jetpack-subscriptions' );
106 }
107
108 /**
109 * Renders a full widget either within the context of WordPress widget, or in response to a shortcode.
110 *
111 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
112 * @param array $instance The settings for the particular instance of the widget.
113 */
114 public function widget( $args, $instance ) {
115 if ( self::is_jetpack() &&
116 /** This filter is documented in modules/contact-form/grunion-contact-form.php */
117 false === apply_filters( 'jetpack_auto_fill_logged_in_user', false )
118 ) {
119 $subscribe_email = '';
120 } else {
121 $current_user = wp_get_current_user();
122 if ( ! empty( $current_user->user_email ) ) {
123 $subscribe_email = esc_attr( $current_user->user_email );
124 } else {
125 $subscribe_email = '';
126 }
127 }
128
129 $stats_action = self::is_jetpack() ? 'jetpack_subscriptions' : 'follow_blog';
130 /** This action is documented in modules/widgets/gravatar-profile.php */
131 do_action( 'jetpack_stats_extra', 'widget_view', $stats_action );
132
133 $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
134 $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
135 $instance = wp_parse_args( (array) $instance, $this->defaults() );
136
137 echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
138
139 ++self::$instance_count;
140
141 self::render_widget_title( $args, $instance );
142
143 self::render_widget_status_messages( $instance );
144
145 self::render_widget_subscription_form( $args, $instance, $subscribe_email );
146
147 echo "\n" . $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
148 }
149
150 /**
151 * Prints the widget's title. If show_only_email_and_button is true, we will not show a title.
152 *
153 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
154 * @param array $instance The settings for the particular instance of the widget.
155 */
156 public static function render_widget_title( $args, $instance ) {
157 $show_only_email_and_button = $instance['show_only_email_and_button'];
158 $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
159 $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
160 if ( self::is_wpcom() && ! $show_only_email_and_button ) {
161 if ( self::is_current_user_subscribed() ) {
162 if ( ! empty( $instance['title_following'] ) ) {
163 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
164 }
165 } elseif ( ! empty( $instance['title'] ) ) {
166 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
167 }
168 }
169
170 if ( self::is_jetpack() && empty( $instance['show_only_email_and_button'] ) ) {
171 echo $args['before_title'] . $instance['title'] . $args['after_title'] . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
172 }
173 }
174
175 /**
176 * Prints the subscription block's status messages after someone has attempted to subscribe.
177 * Either a success message or an error message.
178 *
179 * @param array $instance The settings for the particular instance of the widget.
180 */
181 public static function render_widget_status_messages( $instance ) {
182 if ( self::is_jetpack() && isset( $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output.
183 $success_message = isset( $instance['success_message'] ) ? stripslashes( $instance['success_message'] ) : '';
184 $subscribers_total = self::fetch_subscriber_count();
185
186 switch ( $_GET['subscribe'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended
187 case 'invalid_email':
188 ?>
189 <p class="error"><?php esc_html_e( 'Oops! The email you used is invalid. Please try again.', 'jetpack' ); ?></p>
190 <?php
191 break;
192 case 'opted_out':
193 ?>
194 <p class="error">
195 <?php
196 printf(
197 wp_kses(
198 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link. */
199 __( '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' ),
200 self::$allowed_html_tags_for_message
201 ),
202 'https://subscribe.wordpress.com/',
203 esc_attr__( 'Subscriptions Manager', 'jetpack' )
204 );
205 ?>
206 </p>
207 <?php
208 break;
209 case 'already':
210 ?>
211 <p class="error">
212 <?php
213 printf(
214 wp_kses(
215 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link. */
216 __( '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' ),
217 self::$allowed_html_tags_for_message
218 ),
219 'https://subscribe.wordpress.com/',
220 esc_attr__( 'Subscriptions Manager', 'jetpack' )
221 );
222 ?>
223 </p>
224 <?php
225 break;
226 case 'many_pending_subs':
227 ?>
228 <p class="error">
229 <?php
230 printf(
231 wp_kses(
232 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
233 __( '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' ),
234 self::$allowed_html_tags_for_message
235 ),
236 'https://subscribe.wordpress.com/',
237 esc_attr__( 'Subscriptions Manager', 'jetpack' )
238 );
239 ?>
240 </p>
241 <?php
242 break;
243 case 'pending':
244 ?>
245 <p class="error">
246 <?php
247 printf(
248 wp_kses(
249 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
250 __( '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' ),
251 self::$allowed_html_tags_for_message
252 ),
253 'https://subscribe.wordpress.com/',
254 esc_attr__( 'Subscriptions Manager', 'jetpack' )
255 );
256 ?>
257 </p>
258 <?php
259 break;
260 case 'success':
261 ?>
262 <div class="success"><?php echo wp_kses( wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total ), $success_message ) ), 'post' ); ?></div>
263 <?php
264 break;
265 default:
266 ?>
267 <p class="error"><?php esc_html_e( 'Oops! There was an error when subscribing. Please try again.', 'jetpack' ); ?></p>
268 <?php
269 break;
270 endswitch;
271 }
272
273 if ( self::is_wpcom() && self::wpcom_has_status_message() ) {
274 global $themecolors;
275 $message = '';
276
277 switch ( $_GET['blogsub'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
278 case 'confirming':
279 $message = __( 'Thank you! You can now check your email to confirm your subscription.', 'jetpack' );
280 break;
281 case 'blocked':
282 $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' );
283 break;
284 case 'flooded':
285 $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' );
286 break;
287 case 'spammed':
288 /* translators: %s is a URL */
289 $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/' );
290 break;
291 case 'subscribed':
292 $message = __( 'Hey! You were already subscribed.', 'jetpack' );
293 break;
294 case 'pending':
295 $message = __( 'It seems you already tried to subscribe. We just sent you another email so you can confirm the subscription.', 'jetpack' );
296 break;
297 case 'confirmed':
298 $message = __( 'Cool! You are now subscribed. Now you can check your email for more details and how to manage the subscription.', 'jetpack' );
299 break;
300 }
301
302 $border_color = isset( $themecolors['border'] ) ? " #{$themecolors['border']}" : '';
303
304 $redirect_fragment = self::get_redirect_fragment();
305 printf(
306 '<div id="%1$s" class="jetpack-sub-notification">%3$s</div>',
307 esc_attr( $redirect_fragment ),
308 esc_attr( $border_color ),
309 wp_kses_post( $message )
310 );
311 }
312 }
313
314 /**
315 * Generates the redirect fragment used after form submission.
316 *
317 * @param string $id is the specific id that will appear in the redirect fragment. If none is provided self::$instance_count will be used.
318 */
319 protected static function get_redirect_fragment( $id = null ) {
320 if ( $id === null ) {
321 return 'subscribe-blog' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' );
322 }
323
324 return 'subscribe-blog-' . $id;
325 }
326
327 /**
328 * Generates the source parameter to pass to the iframe
329 *
330 * @return string the actaul post access level (see projects/plugins/jetpack/extensions/blocks/subscriptions/settings.js for the values).
331 */
332 protected static function get_post_access_level() {
333 $post_id = get_the_ID();
334 if ( ! $post_id ) {
335 return 'everybody';
336 }
337 require_once __DIR__ . '/../../extensions/blocks/subscriptions/constants.php';
338 $meta = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
339 if ( empty( $meta ) ) {
340 $meta = 'everybody';
341 }
342 return $meta;
343 }
344
345 /**
346 * Renders a form allowing folks to subscribe to the blog.
347 *
348 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
349 * @param array $instance The settings for the particular instance of the widget.
350 * @param string $subscribe_email The email to use to prefill the form.
351 */
352 public static function render_widget_subscription_form( $args, $instance, $subscribe_email ) {
353 $show_only_email_and_button = $instance['show_only_email_and_button'];
354 $show_subscribers_total = (bool) $instance['show_subscribers_total'];
355 $subscribers_total = self::fetch_subscriber_count();
356 $subscribe_text = empty( $instance['show_only_email_and_button'] ) ?
357 stripslashes( $instance['subscribe_text'] ) :
358 false;
359 $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'] ) : '' ) );
360 $source = 'widget';
361 $widget_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : self::$instance_count;
362 $subscribe_button = ! empty( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : $instance['subscribe_button'];
363 $subscribe_placeholder = isset( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : '';
364 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? 'wp-block-button__link ' . $instance['submit_button_classes'] : 'wp-block-button__link';
365 $submit_button_styles = isset( $instance['submit_button_styles'] ) ? $instance['submit_button_styles'] : '';
366 $submit_button_wrapper_styles = isset( $instance['submit_button_wrapper_styles'] ) ? $instance['submit_button_wrapper_styles'] : '';
367 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
368 $email_field_styles = isset( $instance['email_field_styles'] ) ? $instance['email_field_styles'] : '';
369 $post_access_level = self::get_post_access_level();
370
371 if ( self::is_wpcom() && ! self::wpcom_has_status_message() ) {
372 global $current_blog;
373
374 $url = defined( 'SUBSCRIBE_BLOG_URL' ) ? SUBSCRIBE_BLOG_URL : '';
375 $form_id = self::get_redirect_fragment();
376 ?>
377
378 <div class="wp-block-jetpack-subscriptions__container">
379 <form
380 action="<?php echo esc_url( $url ); ?>"
381 method="post"
382 accept-charset="utf-8"
383 data-blog="<?php echo esc_attr( get_current_blog_id() ); ?>"
384 data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>"
385 id="<?php echo esc_attr( $form_id ); ?>"
386 >
387 <?php
388 if ( ! $show_only_email_and_button ) {
389 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
390 echo wpautop( $subscribe_text );
391 }
392 $email_field_id = 'subscribe-field';
393 $email_field_id .= self::$instance_count > 1
394 ? '-' . self::$instance_count
395 : '';
396 $label_field_id = $email_field_id . '-label';
397 ?>
398 <p id="subscribe-email">
399 <label
400 id="<?php echo esc_attr( $label_field_id ); ?>"
401 for="<?php echo esc_attr( $email_field_id ); ?>"
402 class="screen-reader-text"
403 >
404 <?php echo esc_html__( 'Email Address:', 'jetpack' ); ?>
405 </label>
406
407 <?php
408 printf(
409 '<input
410 type="email"
411 name="email"
412 %1$s
413 style="%2$s"
414 placeholder="%3$s"
415 value=""
416 id="%4$s"
417 required
418 />',
419 ( ! empty( $email_field_classes )
420 ? 'class="' . esc_attr( $email_field_classes ) . '"'
421 : ''
422 ),
423 ( ! empty( $email_field_styles )
424 ? esc_attr( $email_field_styles )
425 : 'width: 95%; padding: 1px 10px'
426 ),
427 ( empty( $subscribe_placeholder ) ? esc_attr__( 'Enter your email address', 'jetpack' ) : esc_attr( $subscribe_placeholder ) ),
428 esc_attr( $email_field_id )
429 );
430 ?>
431 </p>
432
433 <p id="subscribe-submit"
434 <?php if ( ! empty( $submit_button_wrapper_styles ) ) { ?>
435 style="<?php echo esc_attr( $submit_button_wrapper_styles ); ?>"
436 <?php } ?>
437 >
438 <input type="hidden" name="action" value="subscribe"/>
439 <input type="hidden" name="blog_id" value="<?php echo (int) $current_blog->blog_id; ?>"/>
440 <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
441 <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
442 <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
443 <?php wp_nonce_field( 'blogsub_subscribe_' . $current_blog->blog_id, '_wpnonce', false ); ?>
444 <button type="submit"
445 <?php if ( ! empty( $submit_button_classes ) ) { ?>
446 class="<?php echo esc_attr( $submit_button_classes ); ?>"
447 <?php } ?>
448 <?php if ( ! empty( $submit_button_styles ) ) { ?>
449 style="<?php echo esc_attr( $submit_button_styles ); ?>"
450 <?php } ?>
451 >
452 <?php
453 echo wp_kses(
454 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
455 self::$allowed_html_tags_for_submit_button
456 );
457 ?>
458 </button>
459 </p>
460 </form>
461 <?php if ( $show_subscribers_total && $subscribers_total ) { ?>
462 <div class="wp-block-jetpack-subscriptions__subscount">
463 <?php
464 /* translators: %s: number of folks following the blog */
465 echo esc_html( sprintf( _n( 'Join %s other subscriber', 'Join %s other subscribers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
466 ?>
467 </div>
468 <?php } ?>
469 </div>
470 <?php
471 }
472
473 if ( self::is_jetpack() ) {
474 /**
475 * Filter the subscription form's ID prefix.
476 *
477 * @module subscriptions
478 *
479 * @since 2.7.0
480 *
481 * @param string subscribe-field Subscription form field prefix.
482 * @param int $widget_id Widget ID.
483 */
484 $subscribe_field_id = apply_filters( 'subscribe_field_id', 'subscribe-field', $widget_id );
485
486 $form_id = self::get_redirect_fragment( $widget_id );
487 ?>
488 <div class="wp-block-jetpack-subscriptions__container">
489 <form action="#" method="post" accept-charset="utf-8" id="<?php echo esc_attr( $form_id ); ?>"
490 data-blog="<?php echo esc_attr( \Jetpack_Options::get_option( 'id' ) ); ?>"
491 data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>" >
492 <?php
493 if ( $subscribe_text && ( ! isset( $_GET['subscribe'] ) || 'success' !== $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output.
494 ?>
495 <div id="subscribe-text"><?php echo wp_kses( wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total ), $subscribe_text ) ), 'post' ); ?></div>
496 <?php
497 }
498
499 if ( ! isset( $_GET['subscribe'] ) || 'success' !== $_GET['subscribe'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display of unsubmitted form.
500 ?>
501 <p id="subscribe-email">
502 <label id="jetpack-subscribe-label"
503 class="screen-reader-text"
504 for="<?php echo esc_attr( $subscribe_field_id . '-' . $widget_id ); ?>">
505 <?php echo ! empty( $subscribe_placeholder ) ? esc_html( $subscribe_placeholder ) : esc_html__( 'Email Address:', 'jetpack' ); ?>
506 </label>
507 <input type="email" name="email" required="required"
508 <?php if ( ! empty( $email_field_classes ) ) { ?>
509 class="<?php echo esc_attr( $email_field_classes ); ?> required"
510 <?php } ?>
511 <?php if ( ! empty( $email_field_styles ) ) { ?>
512 style="<?php echo esc_attr( $email_field_styles ); ?>"
513 <?php } ?>
514 value="<?php echo esc_attr( $subscribe_email ); ?>"
515 id="<?php echo esc_attr( $subscribe_field_id . '-' . $widget_id ); ?>"
516 placeholder="<?php echo esc_attr( $subscribe_placeholder ); ?>"
517 />
518 </p>
519
520 <p id="subscribe-submit"
521 <?php if ( ! empty( $submit_button_wrapper_styles ) ) { ?>
522 style="<?php echo esc_attr( $submit_button_wrapper_styles ); ?>"
523 <?php } ?>
524 >
525 <input type="hidden" name="action" value="subscribe"/>
526 <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
527 <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
528 <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
529 <?php
530 if ( is_user_logged_in() ) {
531 wp_nonce_field( 'blogsub_subscribe_' . get_current_blog_id(), '_wpnonce', false );
532 }
533 ?>
534 <button type="submit"
535 <?php if ( ! empty( $submit_button_classes ) ) { ?>
536 class="<?php echo esc_attr( $submit_button_classes ); ?>"
537 <?php } ?>
538 <?php if ( ! empty( $submit_button_styles ) ) { ?>
539 style="<?php echo esc_attr( $submit_button_styles ); ?>"
540 <?php } ?>
541 name="jetpack_subscriptions_widget"
542 >
543 <?php
544 echo wp_kses(
545 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
546 self::$allowed_html_tags_for_submit_button
547 );
548 ?>
549 </button>
550 </p>
551 <?php } ?>
552 </form>
553 <?php if ( $show_subscribers_total && 0 < $subscribers_total ) { ?>
554 <div class="wp-block-jetpack-subscriptions__subscount">
555 <?php
556 /* translators: %s: number of folks following the blog */
557 echo esc_html( sprintf( _n( 'Join %s other subscriber', 'Join %s other subscribers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
558 ?>
559 </div>
560 <?php } ?>
561 </div>
562 <?php
563 }
564 }
565
566 /**
567 * Determines if the current user is subscribed to the blog.
568 *
569 * @return bool Is the person already subscribed.
570 */
571 public static function is_current_user_subscribed() {
572 $subscribed = isset( $_GET['subscribe'] ) && 'success' === $_GET['subscribe']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
573
574 if ( self::is_wpcom() && class_exists( 'Blog_Subscription' ) && class_exists( 'Blog_Subscriber' ) ) {
575 $subscribed = is_user_logged_in() && Blog_Subscription::is_subscribed( new Blog_Subscriber() );
576 }
577
578 return $subscribed;
579 }
580
581 /**
582 * Is this script running in the wordpress.com environment?
583 *
584 * @return bool
585 */
586 public static function is_wpcom() {
587 return defined( 'IS_WPCOM' ) && IS_WPCOM;
588 }
589
590 /**
591 * Is this script running in a self-hosted environment?
592 *
593 * @return bool
594 */
595 public static function is_jetpack() {
596 return ! self::is_wpcom();
597 }
598
599 /**
600 * Used to determine if there is a valid status slug within the wordpress.com environment.
601 *
602 * @return bool
603 */
604 public static function wpcom_has_status_message() {
605 return isset( $_GET['blogsub'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
606 in_array(
607 $_GET['blogsub'], // phpcs:ignore WordPress.Security.NonceVerification.Recommended
608 array(
609 'confirming',
610 'blocked',
611 'flooded',
612 'spammed',
613 'subscribed',
614 'pending',
615 'confirmed',
616 ),
617 true
618 );
619 }
620
621 /**
622 * Determine the amount of folks currently subscribed to the blog.
623 *
624 * @return int
625 */
626 public static function fetch_subscriber_count() {
627 $subs_count = 0;
628 if ( self::is_jetpack() ) {
629 $cache_key = 'wpcom_subscribers_total';
630 $subs_count = get_transient( $cache_key );
631 if ( false === $subs_count || 'failed' === $subs_count['status'] ) {
632 $xml = new Jetpack_IXR_Client();
633 $xml->query( 'jetpack.fetchSubscriberCount' );
634
635 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.
636
637 $subs_count = array(
638 'status' => 'failed',
639 'code' => $xml->getErrorCode(),
640 'message' => $xml->getErrorMessage(),
641 'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : 0,
642 );
643 } else {
644 $subs_count = array(
645 'status' => 'success',
646 'value' => $xml->getResponse(),
647 );
648 }
649 set_transient( $cache_key, $subs_count, 3600 ); // Try to cache the result for at least 1 hour.
650 }
651 return $subs_count['value'];
652 }
653
654 if ( self::is_wpcom() ) {
655 $subs_count = wpcom_reach_total_for_blog();
656 return $subs_count;
657 }
658 }
659
660 /**
661 * Updates a particular instance of a widget when someone saves it in wp-admin.
662 *
663 * @param array $new_instance New widget instance settings.
664 * @param array $old_instance Old widget instance settings.
665 *
666 * @return array
667 */
668 public function update( $new_instance, $old_instance ) {
669 $instance = $old_instance;
670
671 if ( self::is_jetpack() ) {
672 $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
673 $instance['subscribe_placeholder'] = wp_kses( stripslashes( $new_instance['subscribe_placeholder'] ), array() );
674 $instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
675 $instance['success_message'] = wp_kses( stripslashes( $new_instance['success_message'] ), array() );
676 }
677
678 if ( self::is_wpcom() ) {
679 $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
680 $instance['title_following'] = wp_strip_all_tags( stripslashes( $new_instance['title_following'] ) );
681 $instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
682 $instance['subscribe_button'] = wp_strip_all_tags( stripslashes( $new_instance['subscribe_button'] ) );
683 }
684
685 $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
686 $instance['show_only_email_and_button'] = isset( $new_instance['show_only_email_and_button'] ) && $new_instance['show_only_email_and_button'];
687 $instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
688
689 return $instance;
690 }
691
692 /**
693 * The default args for rendering a subscription form.
694 *
695 * @return array
696 */
697 public static function defaults() {
698 $defaults = array(
699 'show_subscribers_total' => true,
700 'show_only_email_and_button' => false,
701 'include_social_followers' => true,
702 );
703
704 $defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
705 $defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
706 $defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
707 $defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
708 $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' );
709
710 return $defaults;
711 }
712
713 /**
714 * Renders the widget's options form in wp-admin.
715 *
716 * @param array $instance Widget instance.
717 */
718 public function form( $instance ) {
719 $instance = wp_parse_args( (array) $instance, $this->defaults() );
720 $show_subscribers_total = checked( $instance['show_subscribers_total'], true, false );
721
722 if ( self::is_wpcom() ) {
723 $title = esc_attr( stripslashes( $instance['title'] ) );
724 $title_following = esc_attr( stripslashes( $instance['title_following'] ) );
725 $subscribe_text = esc_attr( stripslashes( $instance['subscribe_text'] ) );
726 $subscribe_logged_in = esc_attr( stripslashes( $instance['subscribe_logged_in'] ) );
727 $subscribe_button = esc_attr( stripslashes( $instance['subscribe_button'] ) );
728 $subscribers_total = self::fetch_subscriber_count();
729 }
730
731 if ( self::is_jetpack() ) {
732 $title = stripslashes( $instance['title'] );
733 $subscribe_text = stripslashes( $instance['subscribe_text'] );
734 $subscribe_placeholder = stripslashes( $instance['subscribe_placeholder'] );
735 $subscribe_button = stripslashes( $instance['subscribe_button'] );
736 $success_message = stripslashes( $instance['success_message'] );
737 $subscribers_total = self::fetch_subscriber_count();
738 }
739
740 if ( self::is_wpcom() ) :
741 ?>
742 <p>
743 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
744 <?php esc_html_e( 'Widget title for non-followers:', 'jetpack' ); ?>
745 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
746 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
747 value="<?php echo esc_attr( $title ); ?>"/>
748 </label>
749 </p>
750 <p>
751 <label for="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>">
752 <?php esc_html_e( 'Widget title for followers:', 'jetpack' ); ?>
753 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>"
754 name="<?php echo esc_attr( $this->get_field_name( 'title_following' ) ); ?>" type="text"
755 value="<?php echo esc_attr( $title_following ); ?>"/>
756 </label>
757 </p>
758 <p>
759 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>">
760 <?php esc_html_e( 'Optional text to display to logged in WordPress.com users:', 'jetpack' ); ?>
761 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>"
762 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_logged_in' ) ); ?>"
763 type="text"><?php echo esc_html( $subscribe_logged_in ); ?></textarea>
764 </label>
765 </p>
766 <p>
767 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
768 <?php esc_html_e( 'Optional text to display to non-WordPress.com users:', 'jetpack' ); ?>
769 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
770 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
771 type="text"><?php echo esc_html( $subscribe_text ); ?></textarea>
772 </label>
773 </p>
774 <p>
775 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
776 <?php esc_html_e( 'Follow Button Text:', 'jetpack' ); ?>
777 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
778 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
779 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
780 </label>
781 </p>
782 <p>
783 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
784 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
785 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
786 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
787 <?php
788 /* translators: %s: Number of followers. */
789 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 ) ) );
790 ?>
791 </label>
792 </p>
793 <?php
794 endif;
795
796 if ( self::is_jetpack() ) :
797 ?>
798 <p>
799 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
800 <?php esc_html_e( 'Widget title:', 'jetpack' ); ?>
801 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
802 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
803 value="<?php echo esc_attr( $title ); ?>"/>
804 </label>
805 </p>
806 <p>
807 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
808 <?php esc_html_e( 'Optional text to display to your readers:', 'jetpack' ); ?>
809 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
810 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
811 rows="3"><?php echo esc_html( $subscribe_text ); ?></textarea>
812 </label>
813 </p>
814 <p>
815 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>">
816 <?php esc_html_e( 'Subscribe Placeholder:', 'jetpack' ); ?>
817 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>"
818 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_placeholder' ) ); ?>" type="text"
819 value="<?php echo esc_attr( $subscribe_placeholder ); ?>"/>
820 </label>
821 </p>
822 <p>
823 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
824 <?php esc_html_e( 'Subscribe Button:', 'jetpack' ); ?>
825 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
826 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
827 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
828 </label>
829 </p>
830 <p>
831 <label for="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>">
832 <?php esc_html_e( 'Success Message Text:', 'jetpack' ); ?>
833 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>"
834 name="<?php echo esc_attr( $this->get_field_name( 'success_message' ) ); ?>"
835 rows="5"><?php echo esc_html( $success_message ); ?></textarea>
836 </label>
837 </p>
838 <p>
839 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
840 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
841 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
842 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
843 <?php
844 /* translators: %s: Number of subscribers. */
845 echo esc_html( sprintf( _n( 'Show total number of subscribers? (%s subscriber)', 'Show total number of subscribers? (%s subscribers)', $subscribers_total, 'jetpack' ), $subscribers_total ) );
846 ?>
847 </label>
848 </p>
849 <?php
850 endif;
851 }
852 }
853
854 if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'class_alias' ) ) {
855 class_alias( 'Jetpack_Subscriptions_Widget', 'Blog_Subscription_Widget' );
856 }
857
858 /**
859 * Classname / shortcode tag to use for the Subscriptions widget.
860 *
861 * @return string
862 */
863 function get_jetpack_blog_subscriptions_widget_classname() {
864 return ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ?
865 'Blog_Subscription_Widget' :
866 'Jetpack_Subscriptions_Widget';
867 }
868
869 /**
870 * Subscriptions widget form HTML output.
871 *
872 * @param array $instance Widget instance data.
873 */
874 function jetpack_do_subscription_form( $instance ) {
875 if ( empty( $instance ) || ! is_array( $instance ) ) {
876 $instance = array();
877 }
878
879 if ( empty( $instance['show_subscribers_total'] ) || 'false' === $instance['show_subscribers_total'] ) {
880 $instance['show_subscribers_total'] = false;
881 } else {
882 $instance['show_subscribers_total'] = true;
883 }
884
885 // the default behavior is to include the social followers
886 if ( empty( $instance['include_social_followers'] ) || 'true' === $instance['include_social_followers'] ) {
887 $instance['include_social_followers'] = true;
888 } else {
889 $instance['include_social_followers'] = false;
890 }
891
892 $show_only_email_and_button = isset( $instance['show_only_email_and_button'] ) ? $instance['show_only_email_and_button'] : false;
893 $submit_button_text = isset( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : '';
894
895 // Build up a string with the submit button's classes and styles and set it on the instance.
896 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? $instance['submit_button_classes'] : '';
897 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
898 $style = '';
899 $submit_button_styles = '';
900 $submit_button_wrapper_styles = '';
901 $email_field_styles = '';
902 $success_message = '';
903
904 if ( isset( $instance['custom_background_button_color'] ) && 'undefined' !== $instance['custom_background_button_color'] ) {
905 $submit_button_styles .= 'background: ' . $instance['custom_background_button_color'] . '; ';
906 }
907 if ( isset( $instance['custom_text_button_color'] ) && 'undefined' !== $instance['custom_text_button_color'] ) {
908 $submit_button_styles .= 'color: ' . $instance['custom_text_button_color'] . '; ';
909 }
910 if ( isset( $instance['custom_button_width'] ) && 'undefined' !== $instance['custom_button_width'] ) {
911 $submit_button_wrapper_styles .= 'width: ' . $instance['custom_button_width'] . '; ';
912 $submit_button_wrapper_styles .= 'max-width: 100%; ';
913
914 // Account for custom margins on inline forms.
915 if (
916 ! empty( $instance['custom_spacing'] ) &&
917 ! ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] )
918 ) {
919 $submit_button_styles .= 'width: calc(100% - ' . $instance['custom_spacing'] . 'px); ';
920 } else {
921 $submit_button_styles .= 'width: 100%; ';
922 }
923 }
924
925 if ( isset( $instance['custom_font_size'] ) && 'undefined' !== $instance['custom_font_size'] ) {
926 $style = 'font-size: ' . $instance['custom_font_size'];
927 $style .= is_numeric( $instance['custom_font_size'] ) ? 'px; ' : '; '; // Handle deprecated numeric font size values.
928
929 $submit_button_styles .= $style;
930 $email_field_styles .= $style;
931 }
932 if ( isset( $instance['custom_padding'] ) && 'undefined' !== $instance['custom_padding'] ) {
933 $style = 'padding: ' .
934 $instance['custom_padding'] . 'px ' .
935 round( $instance['custom_padding'] * 1.5 ) . 'px ' .
936 $instance['custom_padding'] . 'px ' .
937 round( $instance['custom_padding'] * 1.5 ) . 'px; ';
938
939 $submit_button_styles .= $style;
940 $email_field_styles .= $style;
941 }
942
943 $button_spacing = 0;
944 if ( ! empty( $instance['custom_spacing'] ) ) {
945 $button_spacing = $instance['custom_spacing'];
946 }
947 if ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] ) {
948 $submit_button_styles .= 'margin-top: ' . $button_spacing . 'px; ';
949 } else {
950 $submit_button_styles .= 'margin: 0px; '; // Reset Safari's 2px default margin for buttons affecting input and button union
951 $submit_button_styles .= 'margin-left: ' . $button_spacing . 'px; ';
952 }
953
954 if ( isset( $instance['custom_border_radius'] ) && 'undefined' !== $instance['custom_border_radius'] ) {
955 $style = 'border-radius: ' . $instance['custom_border_radius'] . 'px; ';
956 $submit_button_styles .= $style;
957 $email_field_styles .= $style;
958 }
959 if ( isset( $instance['custom_border_weight'] ) && 'undefined' !== $instance['custom_border_weight'] ) {
960 $style = 'border-width: ' . $instance['custom_border_weight'] . 'px; ';
961 $submit_button_styles .= $style;
962 $email_field_styles .= $style;
963 }
964 if ( isset( $instance['custom_border_color'] ) && 'undefined' !== $instance['custom_border_color'] ) {
965 $style =
966 'border-color: ' . $instance['custom_border_color'] . '; ' .
967 'border-style: solid;';
968
969 $submit_button_styles .= $style;
970 $email_field_styles .= $style;
971 }
972 if ( isset( $instance['success_message'] ) && 'undefined' !== $instance['success_message'] ) {
973 $success_message = wp_kses( stripslashes( $instance['success_message'] ), array() );
974 }
975
976 $instance = shortcode_atts(
977 Jetpack_Subscriptions_Widget::defaults(),
978 $instance,
979 'jetpack_subscription_form'
980 );
981
982 // These must come after the call to shortcode_atts().
983 $instance['submit_button_text'] = $submit_button_text;
984 $instance['show_only_email_and_button'] = $show_only_email_and_button;
985 if ( ! empty( $submit_button_classes ) ) {
986 $instance['submit_button_classes'] = $submit_button_classes;
987 }
988 if ( ! empty( $email_field_classes ) ) {
989 $instance['email_field_classes'] = $email_field_classes;
990 }
991
992 if ( ! empty( $submit_button_styles ) ) {
993 $instance['submit_button_styles'] = trim( $submit_button_styles );
994 }
995 if ( ! empty( $submit_button_wrapper_styles ) ) {
996 $instance['submit_button_wrapper_styles'] = trim( $submit_button_wrapper_styles );
997 }
998 if ( ! empty( $email_field_styles ) ) {
999 $instance['email_field_styles'] = trim( $email_field_styles );
1000 }
1001 if ( ! empty( $success_message ) ) {
1002 $instance['success_message'] = trim( $success_message );
1003 }
1004
1005 $args = array(
1006 'before_widget' => '<div class="jetpack_subscription_widget">',
1007 );
1008 ob_start();
1009 the_widget( get_jetpack_blog_subscriptions_widget_classname(), $instance, $args );
1010 $output = ob_get_clean();
1011
1012 return $output;
1013 }
1014
1015 add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' );
1016 add_shortcode( 'blog_subscription_form', 'jetpack_do_subscription_form' );
1017
1018 /**
1019 * Register the Subscriptions widget.
1020 */
1021 function jetpack_blog_subscriptions_init() {
1022 register_widget( get_jetpack_blog_subscriptions_widget_classname() );
1023 }
1024
1025 add_action( 'widgets_init', 'jetpack_blog_subscriptions_init' );
1026
1027 /**
1028 * Sets the default value for `subscription_options` site option.
1029 *
1030 * This default value is available across Simple, Atomic and Jetpack sites,
1031 * including the /sites/$site/settings endpoint.
1032 *
1033 * @param array $default Default `subscription_options` array.
1034 * @param string $option Option name.
1035 * @param bool $passed_default Whether `get_option()` passed a default value.
1036 *
1037 * @return array Default value of `subscription_options`.
1038 */
1039 function subscription_options_fallback( $default, $option, $passed_default ) {
1040 if ( $passed_default ) {
1041 return $default;
1042 }
1043
1044 $site_url = get_home_url();
1045 $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) );
1046
1047 return array(
1048 /* translators: Both %1$s and %2$s is site address */
1049 '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 ),
1050 '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' ),
1051 );
1052 }
1053
1054 add_filter( 'default_option_subscription_options', 'subscription_options_fallback', 10, 3 );
1055