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

WIP - create global navbar in jetpack-mu-wpcom #35400

Closed
wants to merge 4 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 @@ -75,6 +75,8 @@ public static function load_features() {
require_once __DIR__ . '/features/media/heif-support.php';

require_once __DIR__ . '/features/block-patterns/block-patterns.php';

require_once __DIR__ . '/features/global-nav-bar/global-nav.php';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* WPCOM Global Navbar Class
*
* @package automattic/jetpack-mu-wpcom
*/

/**
* Provides custom admin bar instead of the default WordPress admin bar.
*/
class WPcom_Global_Nav {

/**
* Constructor
*/
public function __construct() {
add_action( 'admin_bar_init', array( $this, 'init' ) );
}

/**
* Initialize our masterbar.
*/
public function init() {
add_action( 'wp_before_admin_bar_render', array( $this, 'update_core_masterbar' ), 99999 );
}

/**
* Update and add items on the core masterbar.
*/
public function update_core_masterbar() {
global $wp_admin_bar;

if ( ! is_object( $wp_admin_bar ) ) {
return false;
}

$nodes = array();

// First, lets gather all nodes and remove them.
foreach ( $wp_admin_bar->get_nodes() as $node ) {
$nodes[ $node->id ] = $node;
$wp_admin_bar->remove_node( $node->id );
}

// Add custom groups and menus here

// Re-add original nodes
foreach ( $nodes as $id => $node ) {

Check warning on line 48 in projects/packages/jetpack-mu-wpcom/src/features/global-nav-bar/class-wpcom-global-nav.php

View workflow job for this annotation

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

Unused variable $id. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable)
$wp_admin_bar->add_node( $node );
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

Check failure on line 1 in projects/packages/jetpack-mu-wpcom/src/features/global-nav-bar/global-nav.php

View workflow job for this annotation

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

Missing file doc comment (Squiz.Commenting.FileComment.Missing)
/**
* WPCOM Global Navbar Loader
*
* @package automattic/jetpack-mu-wpcom
*/

require __DIR__ . '/class-wpcom-global-nav.php';

/**
* Determine if new global nav should be loaded.
*/
function should_use_new_global_nav() {
// True for the sake of simplicity in testing this right now. We may want to check a user
// setting or meta here.
return true;
}
add_filter( 'wpcom_global_nav_enabled', 'should_use_new_global_nav' );

if ( should_use_new_global_nav() ) {
new WPcom_Global_Nav();
}
4 changes: 3 additions & 1 deletion projects/plugins/jetpack/modules/masterbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
require __DIR__ . '/masterbar/admin-color-schemes/class-admin-color-schemes.php';
require __DIR__ . '/masterbar/inline-help/class-inline-help.php';

new Masterbar();
if ( ! apply_filters( 'wpcom_global_nav_enabled', false ) ) {
new Masterbar();
}
new Admin_Color_Schemes();

if ( ( new Host() )->is_woa_site() ) {
Expand Down
Loading