PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.8.3
Jetpack – WP Security, Backup, Speed, & Growth v12.8.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
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
1043 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
517 if ( is_user_logged_in() ) {
518 wp_nonce_field( 'blogsub_subscribe_' . get_current_blog_id(), '_wpnonce', false );
519 }
520 ?>
521 <button type="submit"
522 <?php if ( ! empty( $submit_button_classes ) ) { ?>
523 class="<?php echo esc_attr( $submit_button_classes ); ?>"
524 <?php } ?>
525 <?php if ( ! empty( $submit_button_styles ) ) { ?>
526 style="<?php echo esc_attr( $submit_button_styles ); ?>"
527 <?php } ?>
528 name="jetpack_subscriptions_widget"
529 >
530 <?php
531 echo wp_kses(
532 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
533 self::$allowed_html_tags_for_submit_button
534 );
535 ?>
536 </button>
537 </p>
538 <?php } ?>
539 </form>
540 <?php if ( $show_subscribers_total && 0 < $subscribers_total ) { ?>
541 <div class="wp-block-jetpack-subscriptions__subscount">
542 <?php
543 echo esc_html( Jetpack_Memberships::get_join_others_text( $subscribers_total ) );
544 ?>
545 </div>
546 <?php } ?>
547 </div>
548 <?php
549 }
550 }
551
552 /**
553 * Determines if the current user is subscribed to the blog.
554 *
555 * @return bool Is the person already subscribed.
556 */
557 public static function is_current_user_subscribed() {
558 $subscribed = isset( $_GET['subscribe'] ) && 'success' === $_GET['subscribe']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
559
560 if ( self::is_wpcom() && class_exists( 'Blog_Subscription' ) && class_exists( 'Blog_Subscriber' ) ) {
561 $subscribed = is_user_logged_in() && Blog_Subscription::is_subscribed( new Blog_Subscriber() );
562 }
563
564 return $subscribed;
565 }
566
567 /**
568 * Is this script running in the wordpress.com environment?
569 *
570 * @return bool
571 */
572 public static function is_wpcom() {
573 return defined( 'IS_WPCOM' ) && IS_WPCOM;
574 }
575
576 /**
577 * Is this script running in a self-hosted environment?
578 *
579 * @return bool
580 */
581 public static function is_jetpack() {
582 return ! self::is_wpcom();
583 }
584
585 /**
586 * Used to determine if there is a valid status slug within the wordpress.com environment.
587 *
588 * @return bool
589 */
590 public static function wpcom_has_status_message() {
591 return isset( $_GET['blogsub'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
592 in_array(
593 $_GET['blogsub'], // phpcs:ignore WordPress.Security.NonceVerification.Recommended
594 array(
595 'confirming',
596 'blocked',
597 'flooded',
598 'spammed',
599 'subscribed',
600 'pending',
601 'confirmed',
602 ),
603 true
604 );
605 }
606
607 /**
608 * Determine the amount of folks currently subscribed to the blog.
609 *
610 * @return int
611 */
612 public static function fetch_subscriber_count() {
613 $subs_count = 0;
614 if ( self::is_jetpack() ) {
615 $cache_key = 'wpcom_subscribers_total';
616 $subs_count = get_transient( $cache_key );
617 if ( false === $subs_count || 'failed' === $subs_count['status'] ) {
618 $xml = new Jetpack_IXR_Client();
619 $xml->query( 'jetpack.fetchSubscriberCount' );
620
621 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.
622
623 $subs_count = array(
624 'status' => 'failed',
625 'code' => $xml->getErrorCode(),
626 'message' => $xml->getErrorMessage(),
627 'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : 0,
628 );
629 } else {
630 $subs_count = array(
631 'status' => 'success',
632 'value' => $xml->getResponse(),
633 );
634 }
635 set_transient( $cache_key, $subs_count, 3600 ); // Try to cache the result for at least 1 hour.
636 }
637 return $subs_count['value'];
638 }
639
640 if ( self::is_wpcom() ) {
641 $subs_count = wpcom_reach_total_for_blog();
642 return $subs_count;
643 }
644 }
645
646 /**
647 * Updates a particular instance of a widget when someone saves it in wp-admin.
648 *
649 * @param array $new_instance New widget instance settings.
650 * @param array $old_instance Old widget instance settings.
651 *
652 * @return array
653 */
654 public function update( $new_instance, $old_instance ) {
655 $instance = $old_instance;
656
657 if ( self::is_jetpack() ) {
658 $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
659 $instance['subscribe_placeholder'] = wp_kses( stripslashes( $new_instance['subscribe_placeholder'] ), array() );
660 $instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
661 $instance['success_message'] = wp_kses( stripslashes( $new_instance['success_message'] ), array() );
662 }
663
664 if ( self::is_wpcom() ) {
665 $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
666 $instance['title_following'] = wp_strip_all_tags( stripslashes( $new_instance['title_following'] ) );
667 $instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
668 $instance['subscribe_button'] = wp_strip_all_tags( stripslashes( $new_instance['subscribe_button'] ) );
669 }
670
671 $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
672 $instance['show_only_email_and_button'] = isset( $new_instance['show_only_email_and_button'] ) && $new_instance['show_only_email_and_button'];
673 $instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
674
675 return $instance;
676 }
677
678 /**
679 * The default args for rendering a subscription form.
680 *
681 * @return array
682 */
683 public static function defaults() {
684 $defaults = array(
685 'show_subscribers_total' => true,
686 'show_only_email_and_button' => false,
687 'include_social_followers' => true,
688 );
689
690 $defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
691 $defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
692 $defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
693 $defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
694 $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' );
695
696 return $defaults;
697 }
698
699 /**
700 * Renders the widget's options form in wp-admin.
701 *
702 * @param array $instance Widget instance.
703 */
704 public function form( $instance ) {
705 $instance = wp_parse_args( (array) $instance, static::defaults() );
706 $show_subscribers_total = checked( $instance['show_subscribers_total'], true, false );
707
708 if ( self::is_wpcom() ) {
709 $title = esc_attr( stripslashes( $instance['title'] ) );
710 $title_following = esc_attr( stripslashes( $instance['title_following'] ) );
711 $subscribe_text = esc_attr( stripslashes( $instance['subscribe_text'] ) );
712 $subscribe_logged_in = esc_attr( stripslashes( $instance['subscribe_logged_in'] ) );
713 $subscribe_button = esc_attr( stripslashes( $instance['subscribe_button'] ) );
714 $subscribers_total = self::fetch_subscriber_count();
715 }
716
717 if ( self::is_jetpack() ) {
718 $title = stripslashes( $instance['title'] );
719 $subscribe_text = stripslashes( $instance['subscribe_text'] );
720 $subscribe_placeholder = stripslashes( $instance['subscribe_placeholder'] );
721 $subscribe_button = stripslashes( $instance['subscribe_button'] );
722 $success_message = stripslashes( $instance['success_message'] );
723 $subscribers_total = self::fetch_subscriber_count();
724 }
725
726 if ( self::is_wpcom() ) :
727 ?>
728 <p>
729 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
730 <?php esc_html_e( 'Widget title for non-followers:', 'jetpack' ); ?>
731 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
732 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
733 value="<?php echo esc_attr( $title ); ?>"/>
734 </label>
735 </p>
736 <p>
737 <label for="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>">
738 <?php esc_html_e( 'Widget title for followers:', 'jetpack' ); ?>
739 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>"
740 name="<?php echo esc_attr( $this->get_field_name( 'title_following' ) ); ?>" type="text"
741 value="<?php echo esc_attr( $title_following ); ?>"/>
742 </label>
743 </p>
744 <p>
745 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>">
746 <?php esc_html_e( 'Optional text to display to logged in WordPress.com users:', 'jetpack' ); ?>
747 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>"
748 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_logged_in' ) ); ?>"
749 type="text"><?php echo esc_html( $subscribe_logged_in ); ?></textarea>
750 </label>
751 </p>
752 <p>
753 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
754 <?php esc_html_e( 'Optional text to display to non-WordPress.com users:', 'jetpack' ); ?>
755 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
756 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
757 type="text"><?php echo esc_html( $subscribe_text ); ?></textarea>
758 </label>
759 </p>
760 <p>
761 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
762 <?php esc_html_e( 'Follow Button Text:', 'jetpack' ); ?>
763 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
764 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
765 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
766 </label>
767 </p>
768 <p>
769 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
770 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
771 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
772 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
773 <?php
774 /* translators: %s: Number of followers. */
775 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 ) ) );
776 ?>
777 </label>
778 </p>
779 <?php
780 endif;
781
782 if ( self::is_jetpack() ) :
783 ?>
784 <p>
785 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
786 <?php esc_html_e( 'Widget title:', 'jetpack' ); ?>
787 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
788 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
789 value="<?php echo esc_attr( $title ); ?>"/>
790 </label>
791 </p>
792 <p>
793 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
794 <?php esc_html_e( 'Optional text to display to your readers:', 'jetpack' ); ?>
795 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
796 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
797 rows="3"><?php echo esc_html( $subscribe_text ); ?></textarea>
798 </label>
799 </p>
800 <p>
801 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>">
802 <?php esc_html_e( 'Subscribe Placeholder:', 'jetpack' ); ?>
803 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>"
804 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_placeholder' ) ); ?>" type="text"
805 value="<?php echo esc_attr( $subscribe_placeholder ); ?>"/>
806 </label>
807 </p>
808 <p>
809 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
810 <?php esc_html_e( 'Subscribe Button:', 'jetpack' ); ?>
811 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
812 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
813 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
814 </label>
815 </p>
816 <p>
817 <label for="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>">
818 <?php esc_html_e( 'Success Message Text:', 'jetpack' ); ?>
819 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>"
820 name="<?php echo esc_attr( $this->get_field_name( 'success_message' ) ); ?>"
821 rows="5"><?php echo esc_html( $success_message ); ?></textarea>
822 </label>
823 </p>
824 <p>
825 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
826 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
827 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
828 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
829 <?php
830 /* translators: %s: Number of subscribers. */
831 echo esc_html( sprintf( _n( 'Show total number of subscribers? (%s subscriber)', 'Show total number of subscribers? (%s subscribers)', $subscribers_total, 'jetpack' ), $subscribers_total ) );
832 ?>
833 </label>
834 </p>
835 <?php
836 endif;
837 }
838 }
839
840 if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'class_alias' ) ) {
841 class_alias( 'Jetpack_Subscriptions_Widget', 'Blog_Subscription_Widget' );
842 }
843
844 /**
845 * Classname / shortcode tag to use for the Subscriptions widget.
846 *
847 * @return string
848 */
849 function get_jetpack_blog_subscriptions_widget_classname() {
850 return ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ?
851 'Blog_Subscription_Widget' :
852 'Jetpack_Subscriptions_Widget';
853 }
854
855 /**
856 * Subscriptions widget form HTML output.
857 *
858 * @param array $instance Widget instance data.
859 */
860 function jetpack_do_subscription_form( $instance ) {
861 if ( empty( $instance ) || ! is_array( $instance ) ) {
862 $instance = array();
863 }
864
865 if ( empty( $instance['show_subscribers_total'] ) || 'false' === $instance['show_subscribers_total'] ) {
866 $instance['show_subscribers_total'] = false;
867 } else {
868 $instance['show_subscribers_total'] = true;
869 }
870
871 // the default behavior is to include the social followers
872 if ( empty( $instance['include_social_followers'] ) || 'true' === $instance['include_social_followers'] ) {
873 $instance['include_social_followers'] = true;
874 } else {
875 $instance['include_social_followers'] = false;
876 }
877
878 $show_only_email_and_button = isset( $instance['show_only_email_and_button'] ) ? $instance['show_only_email_and_button'] : false;
879 $submit_button_text = isset( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : '';
880
881 // Build up a string with the submit button's classes and styles and set it on the instance.
882 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? $instance['submit_button_classes'] : '';
883 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
884 $style = '';
885 $submit_button_styles = '';
886 $submit_button_wrapper_styles = '';
887 $email_field_styles = '';
888 $success_message = '';
889
890 if ( isset( $instance['custom_background_button_color'] ) && 'undefined' !== $instance['custom_background_button_color'] ) {
891 $submit_button_styles .= 'background: ' . $instance['custom_background_button_color'] . '; ';
892 }
893 if ( isset( $instance['custom_text_button_color'] ) && 'undefined' !== $instance['custom_text_button_color'] ) {
894 $submit_button_styles .= 'color: ' . $instance['custom_text_button_color'] . '; ';
895 }
896 if ( isset( $instance['custom_button_width'] ) && 'undefined' !== $instance['custom_button_width'] ) {
897 $submit_button_wrapper_styles .= 'width: ' . $instance['custom_button_width'] . '; ';
898 $submit_button_wrapper_styles .= 'max-width: 100%; ';
899
900 // Account for custom margins on inline forms.
901 if (
902 ! empty( $instance['custom_spacing'] ) &&
903 ! ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] )
904 ) {
905 $submit_button_styles .= 'width: calc(100% - ' . $instance['custom_spacing'] . 'px); ';
906 } else {
907 $submit_button_styles .= 'width: 100%; ';
908 }
909 }
910
911 if ( isset( $instance['custom_font_size'] ) && 'undefined' !== $instance['custom_font_size'] ) {
912 $style = 'font-size: ' . $instance['custom_font_size'];
913 $style .= is_numeric( $instance['custom_font_size'] ) ? 'px; ' : '; '; // Handle deprecated numeric font size values.
914
915 $submit_button_styles .= $style;
916 $email_field_styles .= $style;
917 }
918 if ( isset( $instance['custom_padding'] ) && 'undefined' !== $instance['custom_padding'] ) {
919 $style = 'padding: ' .
920 $instance['custom_padding'] . 'px ' .
921 round( $instance['custom_padding'] * 1.5 ) . 'px ' .
922 $instance['custom_padding'] . 'px ' .
923 round( $instance['custom_padding'] * 1.5 ) . 'px; ';
924
925 $submit_button_styles .= $style;
926 $email_field_styles .= $style;
927 }
928
929 $button_spacing = 0;
930 if ( ! empty( $instance['custom_spacing'] ) ) {
931 $button_spacing = $instance['custom_spacing'];
932 }
933 if ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] ) {
934 $submit_button_styles .= 'margin-top: ' . $button_spacing . 'px; ';
935 } else {
936 $submit_button_styles .= 'margin: 0px; '; // Reset Safari's 2px default margin for buttons affecting input and button union
937 $submit_button_styles .= 'margin-left: ' . $button_spacing . 'px; ';
938 }
939
940 if ( isset( $instance['custom_border_radius'] ) && 'undefined' !== $instance['custom_border_radius'] ) {
941 $style = 'border-radius: ' . $instance['custom_border_radius'] . 'px; ';
942 $submit_button_styles .= $style;
943 $email_field_styles .= $style;
944 }
945 if ( isset( $instance['custom_border_weight'] ) && 'undefined' !== $instance['custom_border_weight'] ) {
946 $style = 'border-width: ' . $instance['custom_border_weight'] . 'px; ';
947 $submit_button_styles .= $style;
948 $email_field_styles .= $style;
949 }
950 if ( isset( $instance['custom_border_color'] ) && 'undefined' !== $instance['custom_border_color'] ) {
951 $style =
952 'border-color: ' . $instance['custom_border_color'] . '; ' .
953 'border-style: solid;';
954
955 $submit_button_styles .= $style;
956 $email_field_styles .= $style;
957 }
958 if ( isset( $instance['success_message'] ) && 'undefined' !== $instance['success_message'] ) {
959 $success_message = wp_kses( stripslashes( $instance['success_message'] ), array() );
960 }
961
962 $instance = shortcode_atts(
963 Jetpack_Subscriptions_Widget::defaults(),
964 $instance,
965 'jetpack_subscription_form'
966 );
967
968 // These must come after the call to shortcode_atts().
969 $instance['submit_button_text'] = $submit_button_text;
970 $instance['show_only_email_and_button'] = $show_only_email_and_button;
971 if ( ! empty( $submit_button_classes ) ) {
972 $instance['submit_button_classes'] = $submit_button_classes;
973 }
974 if ( ! empty( $email_field_classes ) ) {
975 $instance['email_field_classes'] = $email_field_classes;
976 }
977
978 if ( ! empty( $submit_button_styles ) ) {
979 $instance['submit_button_styles'] = trim( $submit_button_styles );
980 }
981 if ( ! empty( $submit_button_wrapper_styles ) ) {
982 $instance['submit_button_wrapper_styles'] = trim( $submit_button_wrapper_styles );
983 }
984 if ( ! empty( $email_field_styles ) ) {
985 $instance['email_field_styles'] = trim( $email_field_styles );
986 }
987 if ( ! empty( $success_message ) ) {
988 $instance['success_message'] = trim( $success_message );
989 }
990
991 $args = array(
992 'before_widget' => '<div class="jetpack_subscription_widget">',
993 );
994 ob_start();
995 the_widget( get_jetpack_blog_subscriptions_widget_classname(), $instance, $args );
996 $output = ob_get_clean();
997
998 return $output;
999 }
1000
1001 add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' );
1002 add_shortcode( 'blog_subscription_form', 'jetpack_do_subscription_form' );
1003
1004 /**
1005 * Register the Subscriptions widget.
1006 */
1007 function jetpack_blog_subscriptions_init() {
1008 register_widget( get_jetpack_blog_subscriptions_widget_classname() );
1009 }
1010
1011 add_action( 'widgets_init', 'jetpack_blog_subscriptions_init' );
1012
1013 /**
1014 * Sets the default value for `subscription_options` site option.
1015 *
1016 * This default value is available across Simple, Atomic and Jetpack sites,
1017 * including the /sites/$site/settings endpoint.
1018 *
1019 * @param array $default Default `subscription_options` array.
1020 * @param string $option Option name.
1021 * @param bool $passed_default Whether `get_option()` passed a default value.
1022 *
1023 * @return array Default value of `subscription_options`.
1024 */
1025 function subscription_options_fallback( $default, $option, $passed_default ) {
1026 if ( $passed_default ) {
1027 return $default;
1028 }
1029
1030 $site_url = get_home_url();
1031 $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) );
1032
1033 return array(
1034 /* translators: Both %1$s and %2$s is site address */
1035 '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 ),
1036 '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' ),
1037 /* translators: %1$s is the site address */
1038 '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 ),
1039 );
1040 }
1041
1042 add_filter( 'default_option_subscription_options', 'subscription_options_fallback', 10, 3 );
1043