← All changes
|
extensions/blocks/subscriber-login/class-jetpack-subscription-site.php
+24
-12
13.3.3
→
16.3-beta
View file →
| @@ -2,13 +2,16 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Adds support for Jetpack Subscription Site feature. |
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | - * @since $$next_version$$ | |
| 6 | + * @since 13.3 | |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | namespace Automattic\Jetpack\Extensions\Subscriber_Login; |
| 10 | 10 | |
| 11 | +use WP_Block_Template; | |
| 12 | +use WP_Post; | |
| 13 | + | |
| 11 | 14 | /** |
| 12 | 15 | * Jetpack_Subscription_Site class. |
| 13 | 16 | */ |
| 14 | 17 | class Jetpack_Subscription_Site { |
| @@ -35,23 +38,28 @@ | ||
| 35 | 38 | * |
| 36 | 39 | * @return void |
| 37 | 40 | */ |
| 38 | 41 | public function handle_subscriber_login_block_placements() { |
| 39 | - if ( ! $this->is_subscription_site_feature_enabled() ) { | |
| 40 | - return; | |
| 41 | - } | |
| 42 | - | |
| 43 | 42 | $this->handle_subscriber_login_block_navigation_placement(); |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | 45 | /** |
| 47 | - * Returns true if Subscription Site feature is enabled. | |
| 46 | + * Returns true if context is recognized as a header element. | |
| 48 | 47 | * |
| 48 | + * @param WP_Block_Template|WP_Post|array $context The block template, template part, or pattern the anchor block belongs to. | |
| 49 | + * | |
| 49 | 50 | * @return bool |
| 50 | 51 | */ |
| 51 | - protected function is_subscription_site_feature_enabled() { | |
| 52 | - // It's temporary. Allows to enable the Subscription Site feature. | |
| 53 | - return (bool) apply_filters( 'jetpack_subscription_site_enabled', false ); | |
| 52 | + protected function is_header_context( $context ) { | |
| 53 | + if ( $context instanceof WP_Post && $context->post_type === 'wp_navigation' ) { | |
| 54 | + return true; | |
| 55 | + } | |
| 56 | + | |
| 57 | + if ( $context instanceof WP_Block_Template && $context->area === 'header' ) { | |
| 58 | + return true; | |
| 59 | + } | |
| 60 | + | |
| 61 | + return false; | |
| 54 | 62 | } |
| 55 | 63 | |
| 56 | 64 | /** |
| 57 | 65 | * Handles Subscriber Login block navigation placement. |
| @@ -69,10 +77,14 @@ | ||
| 69 | 77 | } |
| 70 | 78 | |
| 71 | 79 | add_filter( |
| 72 | 80 | 'hooked_block_types', |
| 73 | - function ( $hooked_blocks, $relative_position, $anchor_block ) { | |
| 74 | - if ( $anchor_block === 'core/navigation' && $relative_position === 'last_child' ) { | |
| 81 | + function ( $hooked_blocks, $relative_position, $anchor_block, $context ) { | |
| 82 | + if ( | |
| 83 | + $anchor_block === 'core/navigation' && | |
| 84 | + $relative_position === 'last_child' && | |
| 85 | + self::is_header_context( $context ) | |
| 86 | + ) { | |
| 75 | 87 | $hooked_blocks[] = 'jetpack/subscriber-login'; |
| 76 | 88 | } |
| 77 | 89 | |
| 78 | 90 | return $hooked_blocks; |
| @@ -77,8 +89,8 @@ | ||
| 77 | 89 | |
| 78 | 90 | return $hooked_blocks; |
| 79 | 91 | }, |
| 80 | 92 | 10, |
| 81 | - 3 | |
| 93 | + 4 | |
| 82 | 94 | ); |
| 83 | 95 | } |
| 84 | 96 | } |