Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 3 additions & 5 deletions _inc/lib/class.core-rest-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public static function get_plans( $request ) {
public static function get_jitm_message( $request ) {
$jitm = new JITM_Manager();

if ( ! $jitm ) {
if ( ! $jitm->register() ) {
return array();
}

Expand All @@ -511,11 +511,9 @@ public static function get_jitm_message( $request ) {
* @return bool Always True
*/
public static function delete_jitm_message( $request ) {
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-jitm.php' );

$jitm = Jetpack_JITM::init();
$jitm = new JITM_Manager();

if ( ! $jitm ) {
if ( ! $jitm->register() ) {
return true;
}

Expand Down
11 changes: 10 additions & 1 deletion class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use \Automattic\Jetpack\Assets\Logo as Jetpack_Logo;

require_once( JETPACK__PLUGIN_DIR . '_inc/lib/class.media.php' );
require_once( dirname( __FILE__ ) . '/_inc/lib/tracks/client.php' );

class Jetpack {
public $xmlrpc_server = null;
Expand Down Expand Up @@ -689,7 +690,8 @@ private function __construct() {
add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 );

// A filter to control all just in time messages
add_filter( 'jetpack_just_in_time_msgs', '__return_true', 9 );
add_filter( 'jetpack_just_in_time_msgs', array( $this, 'is_active_and_not_development_mode' ), 9 );

add_filter( 'jetpack_just_in_time_msg_cache', '__return_true', 9);

// If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin.
Expand Down Expand Up @@ -7104,4 +7106,11 @@ public static function user_meta_cleanup( $user_id ) {
}
}
}

function is_active_and_not_development_mode( $maybe ) {
if ( ! \Jetpack::is_active() || \Jetpack::is_development_mode() ) {
return false;
}
return true;
}
}
1 change: 1 addition & 0 deletions jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function jetpack_admin_missing_autoloader() { ?>
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' );
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-affiliate.php' );
$jitm = new Automattic\Jetpack\JITM\Manager();
$jitm->register();
jetpack_require_lib( 'debugger' );
}

Expand Down
31 changes: 2 additions & 29 deletions packages/jitm/src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ class Manager {

const PACKAGE_VERSION = '1.0';

/**
* @var Jetpack_JITM
**/
private static $instance = null;

/**
* Initializes the class, or returns the singleton
*
* @return Manager | false
*/
static function init() {
public function register() {
/**
* Filter to turn off all just in time messages
*
Expand All @@ -38,25 +28,8 @@ static function init() {
if ( ! apply_filters( 'jetpack_just_in_time_msgs', false ) ) {
return false;
}

if ( is_null( self::$instance ) ) {
self::$instance = new Manager();
}

return self::$instance;
}

/**
* Jetpack_JITM constructor.
*/
public function __construct() {
/*
$jetpack_connection = new Jetpack_Connection();
if ( ! $jetpack_connection->is_active() || $jetpack_connection->is_development_mode() ) {
return;
}
*/
add_action( 'current_screen', array( $this, 'prepare_jitms' ) );
return true;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/jitm/tests/php/test_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function test_jitm_disabled_by_filter() {
array( 'jetpack_just_in_time_msgs', false, false ),
) );

$this->assertFalse( Jetpack_JITM::init() );
$jitm = new Jetpack_JITM();
$this->assertFalse( $jitm->register() );

$this->clear_mock_filters();
}
Expand All @@ -36,7 +37,8 @@ public function test_jitm_enabled_by_default() {
array( 'jetpack_just_in_time_msgs', false, true ),
) );

$this->assertTrue( ! ! Jetpack_JITM::init() );
$jitm = new Jetpack_JITM();
$this->assertTrue( $jitm->register() );

$this->clear_mock_filters();
}
Expand Down