Created
December 5, 2020 14:34
-
-
Save Zodiac1978/fc8bd328e36b1a016f92567e74729113 to your computer and use it in GitHub Desktop.
Add new menu for custom toolbar items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Custom Toolbar | |
* Description: Add custom toolbar items in frontent to check page and/or site. | |
* Plugin URI: https://torstenlandsiedel.de | |
* Version: 1.0 | |
* Author: Torsten Landsiedel | |
* Author URI: http://torstenlandsiedel.de | |
* Licence: GPL 2 | |
* License URI: http://opensource.org/licenses/GPL-2.0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
/** | |
* Add toolbar item | |
* | |
* @param Object $admin_bar WPAdminBar object. | |
*/ | |
function add_admin_bar_items( $admin_bar ) { | |
// Bail early if no admin. | |
if ( ! current_user_can( 'manage_options' ) ) { | |
return; | |
} | |
// Bail early if in admin area. | |
if ( is_admin() ) { | |
return; | |
} | |
$menu = array( | |
array( | |
'id' => 'quick_menu', | |
'title' => 'Quick Menu', | |
), | |
array( | |
'id' => 'check_w3c', | |
'title' => 'Validate HTML', | |
'href' => 'https://validator.w3.org/nu/?doc=' . rawurlencode( get_permalink() ), | |
'parent' => 'quick_menu', | |
'meta' => array( | |
'title' => __( 'Menu Title', 'textdomain' ), | |
'target' => '_blank', | |
), | |
), | |
); | |
foreach ( $menu as $args ) { | |
$admin_bar->add_node( $args ); | |
} | |
} | |
add_action( 'admin_bar_menu', 'add_admin_bar_items', 500 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment