Skip to content

Instantly share code, notes, and snippets.

@nerrad
Last active February 13, 2019 16:33
Show Gist options
  • Save nerrad/bb66d1c3862475113cc9cebed2e73b8e to your computer and use it in GitHub Desktop.
Save nerrad/bb66d1c3862475113cc9cebed2e73b8e to your computer and use it in GitHub Desktop.
Add admin bar notification when gutenberg plugin is active

Installation

Drop this file in your wp-content/mu-plugin folder if you want to fire and forget or just into your wp-content/plugins folder if you want to be able to activate.

Purpose

Now that WordPress 5.0+ has the new block editor merged in, the Gutenberg plugin is for development of features that are not in WordPress core. Since I contribute to the plugin among other projects I do I find that sometimes I forget whether or not the GB plugin is active or not. So I created this handy snippet that inserts a GB is Active indicator in the WordPress admin bar menu when the plugin is active.

<?php
/**
* Plugin Name: Gutenberg plugin active indicator
* Plugin URI: https://gist.github.com/nerrad/bb66d1c3862475113cc9cebed2e73b8e
* Author: Darren Ethier <[email protected]>
*
*/
add_action(
'plugins_loaded',
function () {
if (function_exists('gutenberg_dir_path')) {
add_action(
'admin_bar_menu',
function ($admin_bar) {
$admin_bar->add_menu(
[
'id' => 'is-gb-active',
'title' => 'GB ACTIVE!',
'href' => '#',
'meta' => [
'title' => 'GB ACTIVE!',
'class' => 'gb-is-active'
],
]
);
},
2000
);
add_action(
'admin_print_styles',
function () {
echo '<style type="text/css">'
. '#wpadminbar ul #wp-admin-bar-is-gb-active { font-weight: bolder; background-color: darkred; color: white }'
. '</style>';
}
);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment