PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 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 All 507 releases
← 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 }