Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exploring masterbar module for new global nav changes #35381

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@
* Class Atomic_Admin_Menu.
*/
class Atomic_Admin_Menu extends Admin_Menu {
/**
* If the new global navbar should be used;
*
* @var bool
*/
private $use_new_global_navbar;

/**
* Atomic_Admin_Menu constructor.
*/
protected function __construct() {
parent::__construct();
$this->use_new_global_navbar = true;

add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_scripts' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'dequeue_scripts' ), 20 );
if ( ! $this->use_new_global_navbar ) {
add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_scripts' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'dequeue_scripts' ), 20 );
}
add_action( 'wp_ajax_sidebar_state', array( $this, 'ajax_sidebar_state' ) );
add_action( 'wp_ajax_jitm_dismiss', array( $this, 'wp_ajax_jitm_dismiss' ) );
add_action( 'wp_ajax_upsell_nudge_jitm', array( $this, 'wp_ajax_upsell_nudge_jitm' ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
* @var bool
*/
private $site_woa;
/**
* If the new global navbar should be used;
*
* @var bool
*/
private $use_new_global_navbar;

/**
* Constructor
Expand All @@ -127,6 +133,8 @@
$this->is_rtl = isset( $this->user_data['text_direction'] ) && 'rtl' === $this->user_data['text_direction'];
$this->user_locale = isset( $this->user_data['user_locale'] ) ? $this->user_data['user_locale'] : '';
$this->site_woa = ( new Host() )->is_woa_site();
// true for simplicity right now, this chould check user meta or something else...
$this->use_new_global_navbar = $this->site_woa && true;

// Store part of the connected user data as user options so it can be used
// by other files of the masterbar module without making another XMLRPC
Expand Down Expand Up @@ -269,7 +277,7 @@

$classes = array( 'jetpack-masterbar', trim( $admin_body_classes ) );

if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' || $this->use_new_global_navbar ) {
$classes[] = 'wpcom-admin-interface';
}

Expand All @@ -285,7 +293,7 @@
* so let's not remove them when the module is active.
* Also, don't remove the styles if the user has opted to use wp-admin.
*/
if ( ! Jetpack::is_module_active( 'notes' ) && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
if ( ! Jetpack::is_module_active( 'notes' ) && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' && ! $this->use_new_global_navbar ) {
wp_dequeue_style( 'admin-bar' );
}
}
Expand All @@ -296,7 +304,7 @@
public function add_styles_and_scripts() {
// WoA sites: If wpcom_admin_interface is set to wp-admin, load the wp-admin styles.
// These include only styles to enable the "My Sites" and "Reader" links that will be added.
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' && ! $this->use_new_global_navbar ) {
$css_file = $this->is_rtl ? 'masterbar-wp-admin-rtl.css' : 'masterbar-wp-admin.css';
wp_enqueue_style( 'a8c-wpcom-masterbar-overrides', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/' . $css_file ), array(), JETPACK__VERSION );
return;
Expand All @@ -306,11 +314,14 @@
wp_enqueue_style( 'a8c-wpcom-masterbar-rtl', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/rtl/wpcom-admin-bar-rtl.css' ), array(), JETPACK__VERSION );
wp_enqueue_style( 'a8c-wpcom-masterbar-overrides-rtl', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/rtl/masterbar-rtl.css' ), array(), JETPACK__VERSION );
} else {
// Fixes size of site logos and other things?
wp_enqueue_style( 'a8c-wpcom-masterbar', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/wpcom-admin-bar.css' ), array(), JETPACK__VERSION );
// includes styles that make the slide-out hidden, but also effects the dropdowns button styles on core menus.
wp_enqueue_style( 'a8c-wpcom-masterbar-overrides', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/masterbar.css' ), array(), JETPACK__VERSION );
}

// Local overrides.
// Effects size of buttons in the my sides dropdown
wp_enqueue_style( 'a8c_wpcom_css_override', plugins_url( 'overrides.css', __FILE__ ), array(), JETPACK__VERSION );

if ( ! Jetpack::is_module_active( 'notes ' ) ) {
Expand All @@ -336,6 +347,7 @@
false
);

// Adds scripts to prevent popup submenus and make them click toggles.
wp_enqueue_script(
'a8c_wpcom_masterbar_overrides',
$this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/masterbar.js' ),
Expand Down Expand Up @@ -371,7 +383,7 @@
return false;
}

if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' || $this->use_new_global_navbar ) {
$this->build_wp_admin_interface_bar( $wp_admin_bar );
return;
}
Expand Down Expand Up @@ -403,12 +415,17 @@
}

// This disables a submenu from being placed under the My Sites button.
add_filter( 'jetpack_load_admin_menu_class', '__return_true' );
if ( ! $this->use_new_global_navbar ) {
add_filter( 'jetpack_load_admin_menu_class', '__return_true' );
}

// Here we add the My sites and Reader buttons
$this->wpcom_adminbar_add_secondary_groups( $bar );
$this->add_my_sites_submenu( $bar );
$this->add_reader_submenu( $bar );

if ( ! $this->use_new_global_navbar ) {
$this->add_reader_submenu( $bar );
}

foreach ( $nodes as $id => $node ) {

Expand Down Expand Up @@ -686,15 +703,17 @@
)
);

$wp_admin_bar->add_group(
array(
'parent' => 'blog',
'id' => 'blog-secondary',
'meta' => array(
'class' => 'ab-sub-secondary',
),
)
);
// This seems unused...

// $wp_admin_bar->add_group(

Check warning on line 708 in projects/plugins/jetpack/modules/masterbar/masterbar/class-masterbar.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

This comment is 51% valid code; is this commented out code? (Squiz.PHP.CommentedOutCode.Found)
// array(
// 'parent' => 'blog',
// 'id' => 'blog-secondary',
// 'meta' => array(
// 'class' => 'ab-sub-secondary',
// ),
// )
// );

$wp_admin_bar->add_group(
array(
Expand Down Expand Up @@ -946,7 +965,7 @@

$my_site_url = 'https://wordpress.com/sites/' . $this->primary_site_url;
$my_site_title = _n( 'My Site', 'My Sites', $this->user_site_count, 'jetpack' );
if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) {
if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) || $this->use_new_global_navbar ) {
$my_site_url = 'https://wordpress.com/sites';
$my_site_title = esc_html__( 'My Sites', 'jetpack' );
}
Expand All @@ -964,7 +983,7 @@
);

/** This filter is documented in modules/masterbar.php */
if ( apply_filters( 'jetpack_load_admin_menu_class', false ) ) {
if ( apply_filters( 'jetpack_load_admin_menu_class', false ) && ! $this->use_new_global_navbar ) {
return;
}

Expand Down
Loading