Hi people,
I just enabled viper007bond's Wordpress Admin Bar on my Wpmu Site ..
It works perfectly on User's (own) Blog but:
how can we show WP Admin Bar on other Blogs too ?! Like Wordpress.com's bar ..
The php Code looks like this:
<?php /*
**************************************************************************
Plugin Name: WordPress Admin Bar
Plugin URI: http://www.viper007bond.com/wordpress-plugins/wordpress-admin-bar/
Version: 2.0.2
Description: Creates an admin bar inspired by the one at <a href="http://wordpress.com/">WordPress.com</a>. Credits for the look of this plugin go to them.
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
**************************************************************************/
class WPAdminBar {
var $version = '2.0.2';
var $folder = '/wp-content/mu-plugins/';
var $breakat;
var $adminurl;
var $menu = array();
var $submenu = array();
// Plugin initialization
function WPAdminBar() {
// This plugin only supports WP 2.0+ (learn to upgrade please!)
if ( !function_exists('current_user_can') ) return;
// Only users that can "read" should be able to see the admin bar
if ( !current_user_can('read') ) return;
add_action( 'wp_head', array(&$this, 'LoadCSSandJS') );
add_action( 'wp_footer', array(&$this, 'OutputMenu') );
// Uncomment these next 2 lines to use this plugin in your admin area
//add_action( 'admin_head', array(&$this, 'LoadCSSandJS') );
//add_action( 'admin_footer', array(&$this, 'OutputMenu') );
// Add a link to the "Manage" menu when viewing a post or page
add_filter( 'wpabar_submenuitems', array(&$this, 'AddSingleEditLink') );
}
// Output the needed CSS and JS for the plugin
function LoadCSSandJS() { ?>
<link rel="stylesheet" href="<?php echo get_bloginfo('wpurl') . $this->folder; ?>/wordpress-admin-bar.css?ver=<?php echo $this->version; ?>" type="text/css" />
<!--[if lt IE 7]><style type="text/css">#wpabar { position: absolute; } #wpabar .wpabar-menupop li a { width: 100%; }</style><![endif]-->
<?php
}
// Generate and output the HTML for the admin menu
function OutputMenu() {
global $wpdb, $menu, $submenu, $_wp_submenu_nopriv;
if ( file_exists( ABSPATH . 'wp-admin/includes/admin.php' ) )
include_once( ABSPATH . 'wp-admin/includes/admin.php' ); // WP 2.3+
else
include_once( ABSPATH . 'wp-admin/admin-functions.php' );
include_once( ABSPATH . 'wp-admin/menu.php' );
$this->adminurl = get_bloginfo('wpurl') . '/wp-admin/';
$this->menu = apply_filters( 'wpabar_menuitems', $menu );
$this->submenu = apply_filters( 'wpabar_submenuitems', $submenu );
$this->breakat = apply_filters( 'wpabar_breakat', 23 ); // This variable says when to split from left to right
// Sort them incase any menus were added via filters
ksort($this->menu);
foreach ( $this->submenu as $id => $submenus ) {
ksort($submenus);
$this->submenu[$id] = $submenus;
}
?>
<!-- Start WordPress Admin Bar -->
<script type="text/javascript" src="<?php echo get_bloginfo('wpurl') . $this->folder; ?>/wordpress-admin-bar.js?ver=<?php echo $this->version; ?>"></script>
<div id="wpabar">
<div id="wpabar-leftside">
<ul>
<?php
foreach( $this->menu as $id => $menuitem ) {
if ( $id > $this->breakat ) break;
$this->OutputMenuItem( $menuitem );
}
?>
</ul>
</div>
<div id="wpabar-rightside">
<ul>
<?php
foreach( $this->menu as $id => $menuitem ) {
if ( $id <= $this->breakat ) continue;
$this->OutputMenuItem( $menuitem );
}
?>
<li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=logout"><?php _e('Sign Out'); ?></a></li>
</ul>
</div>
</div>
<?php
}
// Output a menu item and it's children
function OutputMenuItem( $menuitem ) {
if ( is_array( $this->submenu[$menuitem[2]] ) ) : ?>
<li class="wpabar-menupop" onmouseover="showNav(this)" onmouseout="hideNav(this)">
<a href="<?php
echo $this->adminurl;
if ( !empty($menuitem[3]) ) {
echo 'admin.php?page=';
$customtoplevel = TRUE;
}
echo $menuitem[2];
?>"><span class="wpabar-dropdown"><?php echo $menuitem[0]; ?></span></a>
<ul>
<?php
foreach( $this->submenu[$menuitem[2]] as $submenuitem ) {
$toplevelpage = ( TRUE == $customtoplevel ) ? 'admin.php' : $menuitem[2];
$url = ( !empty($submenuitem[3]) ) ? $toplevelpage . '?page=' . $submenuitem[2] : $submenuitem[2];
echo ' <li><a href="' . $this->adminurl . $url . '">' . $submenuitem[0] . "</a></li>\n";
}
?>
</ul>
</li>
<?php else : ?>
<li><a href="<?php echo $this->adminurl . $menuitem[2]; ?>"><?php echo $menuitem[0]; ?></a></li>
<?php
endif;
}
// If viewing a single post or page, filter in a link to edit it
function AddSingleEditLink( $submenu ) {
global $post;
if ( function_exists('get_edit_post_link') )
$editlink = str_replace( get_bloginfo('wpurl') . '/wp-admin/', '', get_edit_post_link( $post->ID ) );
else
$editlink = 'post.php?action=edit&post=' . $post->ID;
if ( is_single() && current_user_can( 'edit_post', $post->ID ) )
$submenu['edit.php'][2] = array( __('Edit This'), 'edit_posts', $editlink );
elseif ( is_page() && current_user_can( 'edit_page', $post->ID ) )
$submenu['edit.php'][2] = array( __('Edit This'), 'edit_pages', $editlink );
return $submenu;
}
}
// Start this plugin once all other files and plugins are fully loaded
add_action( 'plugins_loaded', create_function( '', 'global $WPAdminBar; $WPAdminBar = new WPAdminBar();' ) );
?>
hope you understand me ..
Many thanks