PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 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 All 504 releases
← All changes | modules/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php +85 -88 12.5.2 → 16.3-a.1 View file →
@@ -5,9 +5,10 @@
5 5 * @package automattic/jetpack-mu-wpcom
6 6 * @since 12.4
7 7 */
8 8
9 -use Automattic\Jetpack\Status\Host;
9 +use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Abstract_Token_Subscription_Service;
10 +use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS;
10 11
11 12 /**
12 13 * Jetpack_Subscribe_Modal class.
13 14 */
@@ -60,8 +61,49 @@
60 61 public function enqueue_assets() {
61 62 if ( $this->should_user_see_modal() ) {
62 63 wp_enqueue_style( 'subscribe-modal-css', plugins_url( 'subscribe-modal.css', __FILE__ ), array(), JETPACK__VERSION );
63 64 wp_enqueue_script( 'subscribe-modal-js', plugins_url( 'subscribe-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true );
65 +
66 + /**
67 + * Filter how many milliseconds until the Subscribe Modal appears.
68 + *
69 + * @module subscriptions
70 + *
71 + * @since 13.4
72 + *
73 + * @param int 60000 Time in milliseconds for the Subscribe Modal to appear.
74 + */
75 + $load_time = absint( apply_filters( 'jetpack_subscribe_modal_load_time', 60000 ) );
76 +
77 + /**
78 + * Filter how many percentage of the page should be scrolled before the Subscribe Modal appears.
79 + *
80 + * @module subscriptions
81 + *
82 + * @since 13.6
83 + *
84 + * @param int Percentage of the page scrolled before the Subscribe Modal appears.
85 + */
86 + $scroll_threshold = absint( apply_filters( 'jetpack_subscribe_modal_scroll_threshold', 50 ) );
87 +
88 + /**
89 + * Filter to control the interval at which the subscribe modal is shown to the same user. The default interval is 24 hours.
90 + *
91 + * @since 13.7
92 + *
93 + * @param int 24 Hours before we show the same user the Subscribe Modal to again.
94 + */
95 + $modal_interval = absint( apply_filters( 'jetpack_subscribe_modal_interval', 24 ) );
96 +
97 + wp_localize_script(
98 + 'subscribe-modal-js',
99 + 'Jetpack_Subscriptions',
100 + array(
101 + 'modalLoadTime' => $load_time,
102 + 'modalScrollThreshold' => $scroll_threshold,
103 + 'modalInterval' => ( $modal_interval * HOUR_IN_SECONDS * 1000 ),
104 + )
105 + );
64 106 }
65 107 }
66 108
67 109 /**
@@ -116,9 +158,9 @@
116 158 $template->title = __( 'Jetpack Subscribe modal', 'jetpack' );
117 159 $template->status = 'publish';
118 160 $template->has_theme_file = false;
119 161 $template->is_custom = true;
120 - $template->description = __( 'A subscribe form that pops up when someone visits your site', 'jetpack' );
162 + $template->description = __( 'A subscribe form that pops up when someone visits your site.', 'jetpack' );
121 163
122 164 return $template;
123 165 }
124 166
@@ -130,27 +172,28 @@
130 172 */
131 173 public function get_subscribe_template_content() {
132 174 // translators: %s is the name of the site.
133 175 $discover_more_from = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) );
134 - $continue_reading = __( 'Continue Reading', 'jetpack' );
135 - $subscribe_text = __( 'Subscribe to the newsletter to keep reading and get access to the full archive.', 'jetpack' );
176 + $continue_reading = __( 'Continue reading', 'jetpack' );
177 + $subscribe_text = __( 'Subscribe now to keep reading and get access to the full archive.', 'jetpack' );
178 + $group_block_name = esc_attr__( 'Subscription pop-up container', 'jetpack' );
136 179
137 180 return <<<HTML
138 - <!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|70","bottom":"var:preset|spacing|70","left":"var:preset|spacing|70","right":"var:preset|spacing|70"},"margin":{"top":"0","bottom":"0"}},"border":{"color":"#dddddd","width":"1px"}},"layout":{"type":"constrained","contentSize":"450px"}} -->
139 - <div class="wp-block-group has-border-color" style="border-color:#dddddd;border-width:1px;margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--70);padding-right:var(--wp--preset--spacing--70);padding-bottom:var(--wp--preset--spacing--70);padding-left:var(--wp--preset--spacing--70)">
181 + <!-- wp:group {"metadata":{"name":"$group_block_name"},"style":{"spacing":{"padding":{"top":"32px","bottom":"32px","left":"32px","right":"32px"},"margin":{"top":"0","bottom":"0"}},"border":{"color":"#dddddd","width":"1px"}},"layout":{"type":"constrained","contentSize":"450px"}} -->
182 + <div class="wp-block-group has-border-color" style="border-color:#dddddd;border-width:1px;margin-top:0;margin-bottom:0;padding-top:32px;padding-right:32px;padding-bottom:32px;padding-left:32px">
140 183
141 - <!-- wp:heading {"textAlign":"center","style":{"typography":{"fontStyle":"normal","fontWeight":"600","fontSize":"26px"},"layout":{"selfStretch":"fit","flexSize":null},"spacing":{"margin":{"top":"4px","bottom":"4px"}}}} -->
142 - <h2 class="wp-block-heading has-text-align-center" style="margin-top:4px;margin-bottom:4px;font-size:26px;font-style:normal;font-weight:600">$discover_more_from</h2>
184 + <!-- wp:heading {"textAlign":"center","style":{"typography":{"fontStyle":"normal","fontWeight":"600","fontSize":"26px"},"layout":{"selfStretch":"fit","flexSize":null},"spacing":{"margin":{"top":"4px","bottom":"10px"}}}} -->
185 + <h2 class="wp-block-heading has-text-align-center" style="margin-top:4px;margin-bottom:10px;font-size:26px;font-style:normal;font-weight:600">$discover_more_from</h2>
143 186 <!-- /wp:heading -->
144 187
145 188 <!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"15px"},"spacing":{"margin":{"top":"4px","bottom":"0px"}}}} -->
146 - <p class='has-text-align-center' style='margin-top:4px;margin-bottom:0px;font-size:15px'>$subscribe_text</p>
189 + <p class='has-text-align-center' style='margin-top:4px;margin-bottom:1em;font-size:15px'>$subscribe_text</p>
147 190 <!-- /wp:paragraph -->
148 191
149 - <!-- wp:jetpack/subscriptions {"buttonBackgroundColor":"primary","textColor":"secondary","borderRadius":50,"borderColor":"primary","className":"is-style-compact"} /-->
192 + <!-- wp:jetpack/subscriptions {"borderRadius":50,"className":"is-style-compact","appSource":"subscribe-modal"} /-->
150 193
151 - <!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"14px"}},"className":"jetpack-subscribe-modal__close"} -->
152 - <p class="has-text-align-center jetpack-subscribe-modal__close" style="font-size:14px"><a href="#">$continue_reading</a></p>
194 + <!-- wp:paragraph {"align":"center","style":{"spacing":{"margin":{"top":"20px"}},"typography":{"fontSize":"14px"}},"className":"jetpack-subscribe-modal__close"} -->
195 + <p class="has-text-align-center jetpack-subscribe-modal__close" style="margin-top:20px;margin-bottom:0;font-size:14px"><a href="#">$continue_reading</a></p>
153 196 <!-- /wp:paragraph -->
154 197 </div>
155 198 <!-- /wp:group -->
156 199 HTML;
@@ -156,39 +199,30 @@
156 199 HTML;
157 200 }
158 201
159 202 /**
160 - * Returns true if we should load Newsletter content.
161 - * This is currently limited to lettre theme or newsletter sites.
162 - * We could open it to all themes or site intents.
203 + * Returns true if a site visitor should see
204 + * the Subscribe Modal.
163 205 *
164 206 * @return bool
165 207 */
166 - public static function should_load_subscriber_modal() {
167 - // Adding extra check/flag to load only on WP.com
168 - // When ready for Jetpack release, remove this.
169 - $is_wpcom = ( new Host() )->is_wpcom_platform();
170 - if ( ! $is_wpcom ) {
208 + public function should_user_see_modal() {
209 + // Only show when viewing frontend single post.
210 + if ( is_admin() || ! is_singular( 'post' ) ) {
171 211 return false;
172 212 }
173 - if ( 'lettre' !== get_option( 'stylesheet' ) && 'newsletter' !== get_option( 'site_intent' ) ) {
213 +
214 + // Needed because Elementor editor makes is_admin() return false
215 + // See https://coreysalzano.com/wordpress/why-elementor-disobeys-is_admin/
216 + // Ignore nonce warning as just checking if is set
217 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
218 + if ( isset( $_GET['elementor-preview'] ) ) {
174 219 return false;
175 220 }
176 - if ( ! wp_is_block_theme() ) {
177 - return false;
178 - }
179 - return true;
180 - }
181 221
182 - /**
183 - * Returns true if a site visitor should see
184 - * the Subscribe Modal.
185 - *
186 - * @return bool
187 - */
188 - public function should_user_see_modal() {
189 - // Only show when viewing frontend single post.
190 - if ( is_admin() || ! is_singular( 'post' ) ) {
222 + // Don't show when previewing blog posts or site's theme
223 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
224 + if ( isset( $_GET['preview'] ) || isset( $_GET['theme_preview'] ) || isset( $_GET['customize_preview'] ) || isset( $_GET['hide_banners'] ) ) {
191 225 return false;
192 226 }
193 227
194 228 // Don't show if one of subscribe query params is set.
@@ -198,74 +232,37 @@
198 232 if ( isset( $_GET['subscribe'] ) || isset( $_GET['blogsub'] ) ) {
199 233 return false;
200 234 }
201 235
202 - // Dont show if user is member of site.
203 - if ( is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
236 + // Don't show if post is not a post, is for subscribers only, or has paywall block
237 + global $post;
238 + if ( ! $post instanceof WP_Post ) {
204 239 return false;
205 240 }
241 + if ( defined( 'Automattic\\Jetpack\\Extensions\\Subscriptions\\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS' ) ) {
242 + $access_level = get_post_meta( $post->ID, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
243 + } else {
244 + $access_level = get_post_meta( $post->ID, '_jetpack_newsletter_access', true );
245 + }
246 + require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
247 + $is_accessible_by_everyone = Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_EVERYBODY === $access_level || empty( $access_level );
248 + if ( ! $is_accessible_by_everyone ) {
249 + return false;
250 + }
206 251
207 252 // Don't show if user is subscribed to blog.
208 253 require_once __DIR__ . '/../views.php';
209 - if ( $this->has_subscription_cookie() || Jetpack_Subscriptions_Widget::is_current_user_subscribed() ) {
254 + if ( ! class_exists( 'Jetpack_Memberships' ) || Jetpack_Memberships::is_current_user_subscribed() ) {
210 255 return false;
211 256 }
212 257 return true;
213 258 }
214 -
215 - /**
216 - * Returns true if site visitor has subscribed
217 - * to the blog and has a subscription cookie.
218 - *
219 - * @return bool
220 - */
221 - public function has_subscription_cookie() {
222 - $cookies = $_COOKIE;
223 - foreach ( $cookies as $name => $value ) {
224 - if ( strpos( $name, 'jetpack_blog_subscribe_' ) !== false ) {
225 - return true;
226 - }
227 - }
228 - return false;
229 - }
230 259 }
231 260
232 -add_filter(
233 - 'jetpack_subscriptions_modal_enabled',
234 - array(
235 - 'Jetpack_Subscribe_Modal',
236 - 'should_load_subscriber_modal',
237 - )
238 -);
261 +Jetpack_Subscribe_Modal::init();
239 262
240 -/**
241 - * Filter for enabling or disabling the Jetpack Subscribe Modal
242 - * feature. We use this filter here and in several other places
243 - * to conditionally load options and functionality related to
244 - * this feature.
245 - *
246 - * @since 12.4
247 - *
248 - * @param bool Defaults to false.
249 - */
250 -if ( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) ) {
251 - Jetpack_Subscribe_Modal::init();
252 -}
253 -
254 263 add_action(
255 264 'rest_api_switched_to_blog',
256 265 function () {
257 - /**
258 - * Filter for enabling or disabling the Jetpack Subscribe Modal
259 - * feature. We use this filter here and in several other places
260 - * to conditionally load options and functionality related to
261 - * this feature.
262 - *
263 - * @since 12.4
264 - *
265 - * @param bool Defaults to false.
266 - */
267 - if ( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) ) {
268 - Jetpack_Subscribe_Modal::init();
269 - }
266 + Jetpack_Subscribe_Modal::init();
270 267 }
271 268 );