Skip to content

Commit

Permalink
SSO: do not display JITM when not in wp-admin (#14622)
Browse files Browse the repository at this point in the history
* JITM: pass extra parameter to filter used to customize messages

* SSO: do not display JITM when not in wp-admin

Fixes #14547

* Use strict comparison

* Set default parameter for new argument

Co-authored-by: Brandon Kraft <public@brandonkraft.com>
  • Loading branch information
jeherve and kraftbj authored Feb 13, 2020
1 parent 2b39234 commit c85a654
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 13 additions & 5 deletions modules/sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/jitm/src/class-jitm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down

0 comments on commit c85a654

Please sign in to comment.