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

Update approved screens for JITMs to a const #41748

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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

Refactor approved screens in preparation for https://github.com/Automattic/jetpack/pull/41252
22 changes: 19 additions & 3 deletions projects/packages/jitm/src/class-jitm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ class JITM {

const PACKAGE_VERSION = '4.0.6';

/**
* List of screen IDs where JITMs are allowed to display.
*
* @var string[]
*/
const APPROVED_SCREEN_IDS = array(
'jetpack',
'woo',
'shop',
'product',
);

/**
* The configuration method that is called from the jetpack-config package.
*/
Expand All @@ -36,7 +48,7 @@ public static function configure() {
* @return Post_Connection_JITM|Pre_Connection_JITM JITM instance.
*/
public static function get_instance() {
if ( ( new Connection_Manager() )->is_connected() ) {
if ( ( new Connection_Manager() )->is_connected() || defined( 'IS_WPCOM' ) && IS_WPCOM ) {
getdave marked this conversation as resolved.
Show resolved Hide resolved
$jitm = new Post_Connection_JITM();
} else {
$jitm = new Pre_Connection_JITM();
Expand Down Expand Up @@ -127,6 +139,7 @@ public function prepare_jitms( $screen ) {
add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) );
add_action( 'admin_notices', array( $this, 'ajax_message' ) );
add_action( 'edit_form_top', array( $this, 'ajax_message' ) );

}
}

Expand Down Expand Up @@ -156,7 +169,10 @@ public function is_a8c_admin_page() {
return (
$current_screen
&& $current_screen->id
&& (bool) preg_match( '/jetpack|woo|shop|product/', $current_screen->id )
&& (bool) preg_match(
'/' . implode( '|', self::APPROVED_SCREEN_IDS ) . '/',
$current_screen->id
)
);
}

Expand Down Expand Up @@ -226,7 +242,7 @@ public function ajax_message() {
return;
}

// Only add this to Jetpack or Woo admin pages.
// Only add this to specifically whitelisted pages.
getdave marked this conversation as resolved.
Show resolved Hide resolved
if ( ! $this->is_a8c_admin_page() ) {
return;
}
Expand Down
Loading