Skip to content

Commit

Permalink
Masterbar: allow logging out of wpcom when logging out of site. (#12457)
Browse files Browse the repository at this point in the history
Fixes #12456

This change avoids initialiazing all of the Masterbar after admin_bar_init. We want the module to be available after logging out as well, so the function hooked into wp_logout can be triggered.
  • Loading branch information
jeherve authored May 24, 2019
1 parent ff16087 commit 865ea01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 1 addition & 11 deletions modules/masterbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,4 @@

require dirname( __FILE__ ) . '/masterbar/masterbar.php';

// In order to be able to tell if it's an AMP request or not we have to hook into parse_query at a later priority.
add_action( 'admin_bar_init', 'jetpack_initialize_masterbar', 99 );

/**
* Initializes the Masterbar in case the request is not AMP.
*/
function jetpack_initialize_masterbar() {
if ( ! Jetpack_AMP_Support::is_amp_request() ) {
new A8C_WPCOM_Masterbar();
}
}
new A8C_WPCOM_Masterbar();
20 changes: 18 additions & 2 deletions modules/masterbar/masterbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ class A8C_WPCOM_Masterbar {
* Constructor
*/
public function __construct() {
add_action( 'admin_bar_init', array( $this, 'init' ) );

// Post logout on the site, also log the user out of WordPress.com.
add_action( 'wp_logout', array( $this, 'maybe_logout_user_from_wpcom' ) );
}

/**
* Initialize our masterbar.
*/
public function init() {
$this->locale = $this->get_locale();
$this->user_id = get_current_user_id();

Expand All @@ -88,6 +98,14 @@ public function __construct() {
return;
}

// Disable the Masterbar on AMP views.
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return;
}

Jetpack::dns_prefetch(
array(
'//s0.wp.com',
Expand Down Expand Up @@ -141,8 +159,6 @@ public function __construct() {
// Override Notification module to include RTL styles.
add_action( 'a8c_wpcom_masterbar_enqueue_rtl_notification_styles', '__return_true' );
}

add_action( 'wp_logout', array( $this, 'maybe_logout_user_from_wpcom' ) );
}

/**
Expand Down

0 comments on commit 865ea01

Please sign in to comment.