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 +26 -10 13.6.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 ) {
@@ -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',
@@ -287,9 +303,9 @@
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;