-
-
Save stanwmusic/2eda0c360fcc871d69a389a720cf6365 to your computer and use it in GitHub Desktop.
Adding a custom link to the WordPress Admin/Toolbar complete with icon.
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 Admin Bar Link | |
Plugin URI: http://www.creare.co.uk | |
Description: This simple plugin adds custom link to the Admin Bar Menu with the option of having a supporting icon. | |
Version: 0.1 | |
Author: James Bavington | |
Author URI: https://twitter.com/jamesbavington | |
*/ | |
// Check if WooCommerce is active | |
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
add_action( 'admin_bar_menu', 'custom_wp_toolbar_link', 999 ); | |
function custom_wp_toolbar_link( $wp_admin_bar ) { | |
if( current_user_can( 'level_3' ) ){ | |
$args = array( | |
'id' => 'woo-orders', | |
'title' => '<span class="ab-icon"></span><span class="ab-label">'.__( 'Customer Orders', 'some-textdomain' ).'</span>', | |
'href' => '/wp-admin/edit.php?post_type=shop_order', | |
'meta' => array( | |
'target' => '_self', | |
'class' => 'woo-orders', | |
'title' => 'View all customer orders' | |
) | |
); | |
$wp_admin_bar->add_node($args); | |
} | |
} | |
add_action( 'admin_enqueue_scripts', 'custom_wp_toolbar_css_admin' ); | |
add_action( 'wp_enqueue_scripts', 'custom_wp_toolbar_css_admin' ); | |
function custom_wp_toolbar_css_admin() { | |
if( current_user_can( 'level_3' ) ){ | |
wp_register_style( 'add_custom_wp_toolbar_css', plugin_dir_url( __FILE__ ) . 'custom-admin-link.css','','', 'screen' ); | |
wp_enqueue_style( 'add_custom_wp_toolbar_css' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment