以下内容摘自Jetpack,并在管理栏中启用相同的菜单项。
请注意:
标题中的图标是从Jetpack的样式表中提取出来的,脚本是直接打印的,而不是使用wp_enqueue_style
和wp_enqueue_script
.喷气背包使用add_menu
而不是add_node
(根据法典的首选方法)
Jetpack填充meta->html
具有iframe
add_action( \'init\', \'wpse_72564_action_init\' );
function wpse_72564_action_init()
{
if ( !has_filter( \'show_admin_bar\', \'__return_true\' ) && !is_user_logged_in() )
return;
add_action( \'admin_bar_menu\', \'wpse_72564_admin_bar_menu\', 120 );
add_action( \'wp_head\', \'wpse_72564_styles_and_scripts\' );
add_action( \'admin_head\', \'wpse_72564_styles_and_scripts\' );
}
function wpse_72564_admin_bar_menu()
{
global $wp_admin_bar, $current_blog;
if ( !is_object( $wp_admin_bar ) )
return;
$classes = \'wpse-loading wpse-read\';
$wp_admin_bar->add_menu( array(
\'id\' => \'wpse_menu\',
\'title\' => \'<span id="wpse-admin-bar-menu" class="\' . esc_attr( $classes ) . \'">
<span class="noticon noticon-notification" /></span>
</span>\',
\'meta\' => array(
\'html\' => \'<div id="wpse-notes-panel" style="display:none"><div class="wpse-notes-panel-header"><span class="wpse-notes-header">\' . __(\'Notifications\', \'jetpack\') . \'</span><span class="wpse-notes-panel-link"></span></div></div>\',
\'class\' => \'menupop\',
),
\'parent\' => \'top-secondary\',
) );
}
function wpse_72564_styles_and_scripts()
{
?>
<script language="javascript" type="text/javascript">
jQuery(document).ready(function($) {
$(\'#wpse-admin-bar-menu\').click(function()
{
$(\'#wpse-notes-panel\').toggle();
});
});
</script>
<?php
}