diff --git a/modules/sso.php b/modules/sso.php index 96a60858e0c6..8d3d78a7603c 100644 --- a/modules/sso.php +++ b/modules/sso.php @@ -37,7 +37,7 @@ private function __construct() { add_action( 'login_form_logout', array( $this, 'store_wpcom_profile_cookies_on_logout' ) ); add_action( 'jetpack_unlinked_user', array( $this, 'delete_connection_for_user') ); add_action( 'wp_login', array( 'Jetpack_SSO', 'clear_cookies_after_login' ) ); - add_action( 'jetpack_jitm_received_envelopes', array( $this, 'inject_sso_jitm' ) ); + add_action( 'jetpack_jitm_received_envelopes', array( $this, 'inject_sso_jitm' ), 10, 2 ); // Adding this action so that on login_init, the action won't be sanitized out of the $action global. add_action( 'login_form_jetpack-sso', '__return_true' ); @@ -1087,13 +1087,21 @@ public function get_user_data( $user_id ) { * * @since 6.9.0 * - * @param array $envelopes Array of JITM messages received after API call. + * @param array $envelopes Array of JITM messages received after API call. + * @param string $message_path The message path to ask for. * * @return array $envelopes New array of JITM messages. May now contain only one message, about SSO. */ - public function inject_sso_jitm( $envelopes ) { - // Bail early if that's not the first time the user uses SSO. - if ( true != Jetpack_Options::get_option( 'sso_first_login' ) ) { + public function inject_sso_jitm( $envelopes, $message_path = null) { + /* + * Bail early if: + * - the request does not originate from wp-admin main dashboard. + * - that's not the first time the user uses SSO. + */ + if ( + 'wp:dashboard:admin_notices' !== $message_path + || true !== Jetpack_Options::get_option( 'sso_first_login' ) + ) { return $envelopes; } diff --git a/packages/jitm/src/class-jitm.php b/packages/jitm/src/class-jitm.php index 79a2947f22a9..8a66b5e08742 100644 --- a/packages/jitm/src/class-jitm.php +++ b/packages/jitm/src/class-jitm.php @@ -543,10 +543,12 @@ public function get_messages( $message_path, $query ) { * Allow adding your own custom JITMs after a set of JITMs has been received. * * @since 6.9.0 + * @since 8.3.0 - Added Message path. * - * @param array $envelopes array of existing JITMs. + * @param array $envelopes array of existing JITMs. + * @param string $message_path The message path to ask for. */ - $envelopes = apply_filters( 'jetpack_jitm_received_envelopes', $envelopes ); + $envelopes = apply_filters( 'jetpack_jitm_received_envelopes', $envelopes, $message_path ); foreach ( $envelopes as $idx => &$envelope ) {