Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Jetpack: Add filter for avoiding initalization #22553

Merged
merged 7 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Added filter for disabling the initialization of the My Jetpack package
42 changes: 31 additions & 11 deletions projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@ class Initializer {
* @return void
*/
public static function init() {
if ( did_action( 'my_jetpack_init' ) ) {
return;
}

// Feature flag while we are developing it.
if ( ! defined( 'JETPACK_ENABLE_MY_JETPACK' ) || ! JETPACK_ENABLE_MY_JETPACK ) {
return;
}

// Do not initialize My Jetpack if site is not connected.
if ( ! ( new Connection_Manager() )->is_connected() ) {
if ( ! self::should_initialize() ) {
return;
}

Expand Down Expand Up @@ -178,6 +168,36 @@ public static function permissions_callback() {
return current_user_can( 'manage_options' );
}

/**
* Return true if we should initialize the My Jetpack
*/
public static function should_initialize() {
if ( did_action( 'my_jetpack_init' ) ) {
return false;
}

/**
* Allows filtering whether My Jetpack should be initialized
*
* @since 0.5.0-alpha
*
* @param bool $shoud_initialize Should we initialize My Jetpack?
*/
$should = apply_filters( 'jetpack_my_jetpack_should_initialize', true );
oskosk marked this conversation as resolved.
Show resolved Hide resolved

// Feature flag while we are developing it.
if ( ! defined( 'JETPACK_ENABLE_MY_JETPACK' ) || ! JETPACK_ENABLE_MY_JETPACK ) {
return false;
}

// Do not initialize My Jetpack if site is not connected.
if ( ! ( new Connection_Manager() )->is_connected() ) {
return false;
}

return $should;
}

/**
* Site full-data endpoint.
*
Expand Down