PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 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 All 506 releases
← All changes | extensions/blocks/subscriptions/class-jetpack-subscription-site.php +31 -13 13.5.2 → 16.3-a.7 View file →
@@ -110,21 +110,37 @@
110 110 return false;
111 111 }
112 112
113 113 /**
114 + * Returns true if context is recognized as a single post element.
115 + *
116 + * @param WP_Block_Template|WP_Post|array $context The block template, template part, or pattern the anchor block belongs to.
117 + *
118 + * @return bool
119 + */
120 + protected function is_single_post_context( $context ) {
121 + /**
122 + * Some themes are not returning a WP_Block_Template. In that case, we need to check with is_singular function.
123 + */
124 + if ( is_array( $context ) ) {
125 + return is_singular( 'post' );
126 + }
127 +
128 + return $context instanceof WP_Block_Template && $context->slug === 'single';
129 + }
130 +
131 + /**
114 132 * Handles Subscription block navigation placement.
115 133 *
116 134 * @return void
117 135 */
118 136 protected function handle_subscribe_block_navigation_placement() {
119 - global $wp_version;
120 -
121 137 $is_enabled = get_option( 'jetpack_subscriptions_subscribe_navigation_enabled', false );
122 138 if ( ! $is_enabled ) {
123 139 return;
124 140 }
125 141
126 - if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // TODO Fallback for classic themes and wp core < 6.5-beta2.
142 + if ( ! wp_is_block_theme() ) { // TODO Fallback for classic themes.
127 143 return;
128 144 }
129 145
130 146 add_filter(
@@ -154,8 +170,9 @@
154 170 ? $hooked_block['attrs']['className'] . ' is-style-button'
155 171 : 'is-style-button';
156 172
157 173 $hooked_block['attrs']['className'] = $class_name;
174 + $hooked_block['attrs']['appSource'] = 'subscribe-block-navigation';
158 175 }
159 176
160 177 return $hooked_block;
161 178 },
@@ -169,22 +186,20 @@
169 186 *
170 187 * @return void
171 188 */
172 189 protected function handle_subscribe_block_post_end_placement() {
173 - global $wp_version;
174 -
175 190 $subscribe_post_end_enabled = get_option( 'jetpack_subscriptions_subscribe_post_end_enabled', false );
176 191 if ( ! $subscribe_post_end_enabled ) {
177 192 return;
178 193 }
179 194
180 - if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // Fallback for classic themes and wp core < 6.5-beta2.
195 + if ( ! wp_is_block_theme() ) { // Fallback for classic themes.
181 196 add_filter(
182 197 'the_content',
183 198 function ( $content ) {
184 199 // Check if we're inside the main loop in a single Post.
185 200 if (
186 - is_singular() &&
201 + is_single() &&
187 202 in_the_loop() &&
188 203 is_main_query() &&
189 204 $this->user_can_view_post()
190 205 ) {
@@ -189,9 +204,9 @@
189 204 $this->user_can_view_post()
190 205 ) {
191 206 // translators: %s is the name of the site.
192 207 $discover_more_from_text = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) );
193 - $subscribe_text = __( 'Subscribe to get the latest posts to your email.', 'jetpack' );
208 + $subscribe_text = __( 'Subscribe to get the latest posts sent to your email.', 'jetpack' );
194 209
195 210 return $content . do_blocks(
196 211 <<<HTML
197 212 <!-- wp:group {"style":{"spacing":{"padding":{"top":"0px","bottom":"0px","left":"0px","right":"0px"},"margin":{"top":"32px","bottom":"32px"}},"border":{"width":"0px","style":"none"}},"className":"has-border-color","layout":{"type":"default"}} -->
@@ -209,9 +224,9 @@
209 224 <!-- /wp:paragraph -->
210 225
211 226 <!-- wp:group {"layout":{"type":"constrained","contentSize":"480px"}} -->
212 227 <div class="wp-block-group">
213 - <!-- wp:jetpack/subscriptions /-->
228 + <!-- wp:jetpack/subscriptions {"appSource":"subscribe-block-post-end"} /-->
214 229 </div>
215 230 <!-- /wp:group -->
216 231 </div>
217 232 <!-- /wp:group -->
@@ -229,12 +244,13 @@
229 244 }
230 245
231 246 add_filter(
232 247 'hooked_block_types',
233 - function ( $hooked_blocks, $relative_position, $anchor_block ) {
248 + function ( $hooked_blocks, $relative_position, $anchor_block, $context ) {
234 249 if (
235 250 $anchor_block === 'core/post-content' &&
236 251 $relative_position === 'after' &&
252 + self::is_single_post_context( $context ) &&
237 253 $this->user_can_view_post()
238 254 ) {
239 255 $hooked_blocks[] = 'jetpack/subscriptions';
240 256 }
@@ -241,9 +257,9 @@
241 257
242 258 return $hooked_blocks;
243 259 },
244 260 10,
245 - 3
261 + 4
246 262 );
247 263
248 264 add_filter(
249 265 'hooked_block_jetpack/subscriptions',
@@ -269,9 +285,9 @@
269 285 );
270 286
271 287 // translators: %s is the name of the site.
272 288 $discover_more_from_text = sprintf( __( 'Discover more from %s', 'jetpack' ), get_bloginfo( 'name' ) );
273 - $subscribe_text = __( 'Subscribe to get the latest posts to your email.', 'jetpack' );
289 + $subscribe_text = __( 'Subscribe to get the latest posts sent to your email.', 'jetpack' );
274 290 $inner_content_begin = <<<HTML
275 291 <div class="wp-block-group" style="margin-top:48px;margin-bottom:48px;padding-top:5px;padding-bottom:5px">
276 292 <!-- wp:separator {"style":{"spacing":{"margin":{"bottom":"36px"}}},"className":"is-style-wide"} -->
277 293 <hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-bottom:36px"/>
@@ -287,13 +303,15 @@
287 303
288 304 <!-- wp:group {"layout":{"type":"constrained","contentSize":"480px"}} -->
289 305 <div class="wp-block-group">
290 306 HTML;
291 - $inner_content_end = <<<HTML
307 + $inner_content_end = <<<'HTML'
292 308 </div>
293 309 <!-- /wp:group -->
294 310 </div>
295 311 HTML;
312 +
313 + $hooked_block['attrs']['appSource'] = 'subscribe-block-post-end';
296 314
297 315 return array(
298 316 'blockName' => 'core/group',
299 317 'attrs' => $attrs,