automattic / jetpack-jitm
Just in time messages for Jetpack
Installs: 18 683
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 1
Type:jetpack-library
Requires
- automattic/jetpack-a8c-mc-stats: ^1.4.18
- automattic/jetpack-assets: ^1.17.30
- automattic/jetpack-connection: ^1.49.1
- automattic/jetpack-device-detection: ^1.4.23
- automattic/jetpack-logo: ^1.5.21
- automattic/jetpack-partner: ^1.7.21
- automattic/jetpack-redirect: ^1.7.23
- automattic/jetpack-status: ^1.16.1
Requires (Dev)
- automattic/jetpack-changelogger: ^3.3.1
- brain/monkey: 2.6.1
- yoast/phpunit-polyfills: 1.0.4
- dev-trunk / 2.2.x-dev
- v2.2.40
- v2.2.39
- v2.2.38
- v2.2.37
- v2.2.36
- v2.2.35
- v2.2.34
- v2.2.33
- v2.2.32
- v2.2.31
- v2.2.30
- v2.2.29
- v2.2.28
- v2.2.27
- v2.2.26
- v2.2.25
- v2.2.24
- v2.2.23
- v2.2.22
- v2.2.21
- v2.2.20
- v2.2.19
- v2.2.18
- v2.2.17
- v2.2.16
- v2.2.15
- v2.2.14
- v2.2.13
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.1
- v2.1.0
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.16.2
- v1.16.1
- v1.16.0
- v1.15.1
- v1.15.0
- 1.14.1
- v1.14.0
- v1.13.5
- v1.13.4
- v1.13.3
- v1.13.2
- v1.13.1
- v1.13.0
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.5
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-prerelease
- dev-fix/slack-workflow-branch-detection
- dev-fix/release-branch-typo
- dev-update/generate-branch-plugin
- dev-release/v1.15.1
- dev-release-v1.14.0
- dev-release-v1.13.5
- dev-release-v1.13.4
- dev-release-v1.13.3
- dev-release-v1.13.2
- dev-release-v1.13.1
- dev-feature/reorg
- dev-release-v1.13.0
- dev-release-v1.12.2
- dev-release-v1.12.1
- dev-release-v1.12.0
- dev-release-v1.11.2
- dev-release-v1.11.1
- dev-release-v1.11.0
- dev-release-v1.10.4
- dev-release-v1.10.3
- dev-release-v1.10.2
- dev-release-v1.10.1
- dev-release-v1.10.0
- dev-release-v1.9.1
- dev-release-v1.9.0
- dev-release-v1.8.2
- dev-release-v1.8.1
- dev-release-v1.8.0
- dev-release-v1.7.2
- dev-release-v1.7.1
- dev-release-v1.7.0
- dev-release-v1.6.5
- dev-release-v1.6.4
- dev-release-v1.6.3
- dev-release-v1.6.2
- dev-release-v1.6.1
- dev-release-v1.6.0
- dev-release-v1.5.1
- dev-release-v1.5.0
- dev-release-v1.4.0
- dev-release-v1.3.0
This package is auto-updated.
Last update: 2023-02-01 19:33:20 UTC
README
A package encapsulating Just In Time Messages.
Just In Time Messages (JITMs) are real-time contextual in-admin notices. Such notices are displayed on specific admin pages, based on multiple parameters (page visited, Jetpack connection status, plan status, features active, ...).
There are 2 main ways to use JITMs:
- You can create static notices within the Jetpack plugin. Those will be displayed before the site is connected to WordPress.com. See
Pre_Connection_JITM
to find out more. - You can create dynamic notices once the Jetpack plugin is connected to WordPress.com. Those notices will be pulled from WordPress.com depending on the parameters mentioned above. See
Post_Connection_JITM
to find out more.
Usage
Using the Config Package
The JITMs can be enabled using the Config package:
use Automattic/Jetpack/Config;
// Configuring as early as plugins_loaded priority 1
// to make sure every action handler gets properly set.
add_action( 'plugins_loaded', 'configure_jitm', 1 );
function configure_jitm() {
$config = new Config();
$config->ensure( 'jitm' );
}
Directly Using the JITM Package
The JITMs can also be enabled by using the JITM package directly:
Automattic\Jetpack\JITMS\JITM::configure();
Where the JITM will be displayed
JITMs can be shown on any admin page that has the <div id="jp-admin-notices" />
element within the dom, as it's where the messages are injected.
You may need to add or adjust this element to fit in your plugin.
Adding Pre-Connection JITMs
Plugins can add pre-connection JITMs uisng the jetpack_pre_connection_jitms
filter. Each JITM message must be an array and must contain the following keys:
- id
- message_path
- message
- description
- button_link
- button_caption
If a JITM is missing one of the above keys, the JITM will not be displayed.
The JITM message array may also contain the following optional keys:
- icon - When the 'icon' key does not exist, the Jetpack icon is used by default. The available settings for this option are:
- 'jetpack' for the Jetpack icon.
- 'woocommerce' for the WooCommerce icon.
- An empty string for no icon.
The Jetpack plugin's pre-connection JITMs can be found in the Jetpack_Pre_Connection_JITMs
class.
Example
function add_preconnection_jitms( $messages ) {
$example_jitm = array(
'id' => 'example-jitm',
'message_path' => '/wp:plugins:admin_notices/',
'message' => __( 'An example message.', 'jetpack' ),
'description' => __( 'An example description.', 'jetpack' ),
'button_link' => 'https://example.com/path',
'button_caption' => __( 'Example button text', 'jetpack' ),
);
if ( ! is_array( $messages ) ) {
return array( $example_jitm );
}
return array_merge( $messages, array( $example_jitm ) );
}
add_filter( 'jetpack_pre_connection_jitms', 'add_preconnection_jitms' );