← All changes
|
extensions/blocks/subscriptions/class-jetpack-subscription-site.php
+23
-4
13.7.2
→
16.3-a.1
View file →
| @@ -110,8 +110,26 @@ | ||
| 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 | */ |
| @@ -179,9 +197,9 @@ | ||
| 179 | 197 | 'the_content', |
| 180 | 198 | function ( $content ) { |
| 181 | 199 | // Check if we're inside the main loop in a single Post. |
| 182 | 200 | if ( |
| 183 | - is_singular() && | |
| 201 | + is_single() && | |
| 184 | 202 | in_the_loop() && |
| 185 | 203 | is_main_query() && |
| 186 | 204 | $this->user_can_view_post() |
| 187 | 205 | ) { |
| @@ -226,12 +244,13 @@ | ||
| 226 | 244 | } |
| 227 | 245 | |
| 228 | 246 | add_filter( |
| 229 | 247 | 'hooked_block_types', |
| 230 | - function ( $hooked_blocks, $relative_position, $anchor_block ) { | |
| 248 | + function ( $hooked_blocks, $relative_position, $anchor_block, $context ) { | |
| 231 | 249 | if ( |
| 232 | 250 | $anchor_block === 'core/post-content' && |
| 233 | 251 | $relative_position === 'after' && |
| 252 | + self::is_single_post_context( $context ) && | |
| 234 | 253 | $this->user_can_view_post() |
| 235 | 254 | ) { |
| 236 | 255 | $hooked_blocks[] = 'jetpack/subscriptions'; |
| 237 | 256 | } |
| @@ -238,9 +257,9 @@ | ||
| 238 | 257 | |
| 239 | 258 | return $hooked_blocks; |
| 240 | 259 | }, |
| 241 | 260 | 10, |
| 242 | - 3 | |
| 261 | + 4 | |
| 243 | 262 | ); |
| 244 | 263 | |
| 245 | 264 | add_filter( |
| 246 | 265 | 'hooked_block_jetpack/subscriptions', |
| @@ -284,9 +303,9 @@ | ||
| 284 | 303 | |
| 285 | 304 | <!-- wp:group {"layout":{"type":"constrained","contentSize":"480px"}} --> |
| 286 | 305 | <div class="wp-block-group"> |
| 287 | 306 | HTML; |
| 288 | - $inner_content_end = <<<HTML | |
| 307 | + $inner_content_end = <<<'HTML' | |
| 289 | 308 | </div> |
| 290 | 309 | <!-- /wp:group --> |
| 291 | 310 | </div> |
| 292 | 311 | HTML; |