Skip to content

Instantly share code, notes, and snippets.

@MrMaz
Created September 18, 2012 13:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MrMaz/3743211 to your computer and use it in GitHub Desktop.
Save MrMaz/3743211 to your computer and use it in GitHub Desktop.
WordPress Admin Bar: Modal Window Link
<?php
/**
* Setup admin bar item which opens URL in a thickbox window
*
* @param WP_Admin_Bar $wp_admin_bar
*/
function admin_bar_menu_modal_window( $wp_admin_bar )
{
// add "tools" node
// this is just our root node, nothing special here
$wp_admin_bar->add_node( array(
'id' => 'mytools',
'title' => 'My Tools',
'meta' => array(
'class' => 'mytools-top'
)
));
// add "do stuff" link
$wp_admin_bar->add_node( array(
// id is required, but not important in this case
'id' => 'mytools-dostuff',
// set the parent to our root node
'parent' => 'mytools',
// this title is the <a> tag *content*
'title' => 'Do Stuff',
// notice the plugin page and thickbox iframe hint params
'href' => admin_url( 'admin.php' ) . '?page=mytools&_iframe=true',
// these meta attributes allow us to work some jQuery magic
'meta' => array(
// optional class for styling
'class' => 'mytools-sub'
// the link title *attribute* becomes the thickbox window title
'title' => 'Do Stuff Window Title',
// call jQuery statically to add the thickbox class on click
'onclick' => 'jQuery(this).addClass("thickbox");'
)
));
}
add_action( 'admin_bar_menu', 'admin_bar_menu_modal_window', 999 );
?>
@valuser
Copy link

valuser commented Sep 11, 2013

Thanks for this.

typo - missing comma

change ‘class’ => ‘mytools-sub’ to ‘class’ => ‘mytools-sub’,

Also please

how/where to enter content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment