-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscription Site: Hook Subscriber Login block into the navigation (#…
- Loading branch information
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-subscription-site-login-navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: other | ||
|
||
Subscription Site: Hook Subscriber Login block into the navigation |
84 changes: 84 additions & 0 deletions
84
...ts/plugins/jetpack/extensions/blocks/subscriber-login/class-jetpack-subscription-site.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Adds support for Jetpack Subscription Site feature. | ||
* | ||
* @package automattic/jetpack | ||
* @since $$next_version$$ | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Extensions\Subscriber_Login; | ||
|
||
/** | ||
* Jetpack_Subscription_Site class. | ||
*/ | ||
class Jetpack_Subscription_Site { | ||
/** | ||
* Jetpack_Subscription_Site singleton instance. | ||
* | ||
* @var Jetpack_Subscription_Site|null | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* Jetpack_Subscription_Site instance init. | ||
*/ | ||
public static function init() { | ||
if ( self::$instance === null ) { | ||
self::$instance = new Jetpack_Subscription_Site(); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* Handles Subscriber Login block placements. | ||
* | ||
* @return void | ||
*/ | ||
public function handle_subscriber_login_block_placements() { | ||
if ( ! $this->is_subscription_site_feature_enabled() ) { | ||
return; | ||
} | ||
|
||
$this->handle_subscriber_login_block_navigation_placement(); | ||
} | ||
|
||
/** | ||
* Returns true if Subscription Site feature is enabled. | ||
* | ||
* @return bool | ||
*/ | ||
protected function is_subscription_site_feature_enabled() { | ||
// It's temporary. Allows to enable the Subscription Site feature. | ||
return (bool) apply_filters( 'jetpack_subscription_site_enabled', false ); | ||
} | ||
|
||
/** | ||
* Handles Subscriber Login block navigation placement. | ||
* | ||
* @return void | ||
*/ | ||
protected function handle_subscriber_login_block_navigation_placement() { | ||
$subscriber_login_navigation_enabled = get_option( 'jetpack_subscriptions_login_navigation_enabled', false ); | ||
if ( ! $subscriber_login_navigation_enabled ) { | ||
return; | ||
} | ||
|
||
if ( ! wp_is_block_theme() ) { // TODO Fallback for classic themes. | ||
return; | ||
} | ||
|
||
add_filter( | ||
'hooked_block_types', | ||
function ( $hooked_blocks, $relative_position, $anchor_block ) { | ||
if ( $anchor_block === 'core/navigation' && $relative_position === 'last_child' ) { | ||
$hooked_blocks[] = 'jetpack/subscriber-login'; | ||
} | ||
|
||
return $hooked_blocks; | ||
}, | ||
10, | ||
3 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters