Clean up the 'Site Name' admin bar functions.
git-svn-id: https://develop.svn.wordpress.org/trunk@18919 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
70a7bb3fe0
commit
e33486dbb6
@ -219,11 +219,13 @@ function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the "Blog Name" menu in the front end.
|
* Add the "Site Name" menu.
|
||||||
*
|
*
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*/
|
*/
|
||||||
function wp_admin_bar_blog_front_menu( $wp_admin_bar ) {
|
function wp_admin_bar_site_menu( $wp_admin_bar ) {
|
||||||
|
global $current_site;
|
||||||
|
|
||||||
if ( ! is_user_logged_in() )
|
if ( ! is_user_logged_in() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -232,65 +234,46 @@ function wp_admin_bar_blog_front_menu( $wp_admin_bar ) {
|
|||||||
if ( empty( $blogname ) )
|
if ( empty( $blogname ) )
|
||||||
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
|
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
|
||||||
|
|
||||||
|
if ( is_network_admin() ) {
|
||||||
|
$blogname = sprintf( __('Network Admin: %s'), esc_html( $current_site->site_name ) );
|
||||||
|
} elseif ( is_user_admin() ) {
|
||||||
|
$blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );
|
||||||
|
}
|
||||||
|
|
||||||
$title = wp_html_excerpt( $blogname, 40 );
|
$title = wp_html_excerpt( $blogname, 40 );
|
||||||
if ( $title != $blogname )
|
if ( $title != $blogname )
|
||||||
$title = trim( $title ) . '…';
|
$title = trim( $title ) . '…';
|
||||||
|
|
||||||
$wp_admin_bar->add_menu( array(
|
$wp_admin_bar->add_menu( array(
|
||||||
'id' => 'blog-name',
|
'id' => 'site-name',
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'href' => admin_url(),
|
'href' => is_admin() ? home_url() : admin_url(),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
// Add Dashboard item.
|
// Create submenu items.
|
||||||
$wp_admin_bar->add_menu( array(
|
|
||||||
'id' => 'dashboard',
|
|
||||||
'title' => __( 'Dashboard' ),
|
|
||||||
'href' => admin_url(),
|
|
||||||
'parent' => 'blog-name',
|
|
||||||
) );
|
|
||||||
|
|
||||||
wp_admin_bar_appearance_menu( $wp_admin_bar );
|
if ( is_admin() ) {
|
||||||
}
|
// Add an option to visit the site.
|
||||||
|
$wp_admin_bar->add_menu( array(
|
||||||
|
'parent' => 'site-name',
|
||||||
|
'id' => 'view-site',
|
||||||
|
'title' => __( 'Visit Site' ),
|
||||||
|
'href' => home_url(),
|
||||||
|
) );
|
||||||
|
|
||||||
/**
|
// We're on the front end, print a copy of the admin menu.
|
||||||
* Add the "Blog Name" menu in the admin.
|
|
||||||
*
|
|
||||||
* @since 3.3.0
|
|
||||||
*/
|
|
||||||
function wp_admin_bar_blog_admin_menu( $wp_admin_bar ) {
|
|
||||||
global $current_site;
|
|
||||||
|
|
||||||
if ( is_network_admin() ) {
|
|
||||||
$title = sprintf( __('Network Admin: %s'), esc_html($current_site->site_name) );
|
|
||||||
$url = '#';
|
|
||||||
} elseif ( is_user_admin() ) {
|
|
||||||
$title = sprintf( __('Global Dashboard: %s'), esc_html($current_site->site_name) );
|
|
||||||
$url = '#';
|
|
||||||
} else {
|
} else {
|
||||||
$title = get_bloginfo('name');
|
// Add the dashboard item.
|
||||||
$url = get_home_url();
|
$wp_admin_bar->add_menu( array(
|
||||||
|
'parent' => 'site-name',
|
||||||
|
'id' => 'dashboard',
|
||||||
|
'title' => __( 'Dashboard' ),
|
||||||
|
'href' => admin_url(),
|
||||||
|
) );
|
||||||
|
|
||||||
if ( empty( $title ) )
|
// Add the appearance menu.
|
||||||
$title = preg_replace( '#^(https?://)?(www.)?#', '', $url );
|
wp_admin_bar_appearance_menu( $wp_admin_bar );
|
||||||
}
|
}
|
||||||
|
|
||||||
$title_excerpt = wp_html_excerpt( $title, 40 );
|
|
||||||
if ( $title != $title_excerpt )
|
|
||||||
$title_excerpt = trim( $title_excerpt ) . '…';
|
|
||||||
|
|
||||||
$wp_admin_bar->add_menu( array(
|
|
||||||
'id' => 'blog-name',
|
|
||||||
'title' => $title_excerpt,
|
|
||||||
'href' => $url,
|
|
||||||
) );
|
|
||||||
|
|
||||||
$wp_admin_bar->add_menu( array(
|
|
||||||
'parent' => 'blog-name',
|
|
||||||
'id' => 'view-site',
|
|
||||||
'title' => __( 'Visit Site' ),
|
|
||||||
'href' => home_url(),
|
|
||||||
) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -586,7 +569,7 @@ function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
|
|||||||
'id' => 'appearance',
|
'id' => 'appearance',
|
||||||
'title' => __('Appearance'),
|
'title' => __('Appearance'),
|
||||||
'href' => admin_url('themes.php'),
|
'href' => admin_url('themes.php'),
|
||||||
'parent' => 'blog-name',
|
'parent' => 'site-name',
|
||||||
) );
|
) );
|
||||||
|
|
||||||
if ( ! current_user_can( 'edit_theme_options' ) )
|
if ( ! current_user_can( 'edit_theme_options' ) )
|
||||||
|
@ -179,6 +179,7 @@ class WP_Admin_Bar {
|
|||||||
// Site related.
|
// Site related.
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
|
add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
|
add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
|
||||||
|
add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 );
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 40 );
|
add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 40 );
|
||||||
|
|
||||||
// Content related.
|
// Content related.
|
||||||
@ -188,10 +189,8 @@ class WP_Admin_Bar {
|
|||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 );
|
add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 );
|
||||||
|
|
||||||
if ( ! is_admin() ) {
|
if ( ! is_admin() ) {
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_blog_front_menu', 30 );
|
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 100 );
|
add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 100 );
|
||||||
} else {
|
} else {
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_blog_admin_menu', 30 );
|
|
||||||
add_action( 'admin_bar_menu', 'wp_admin_bar_help_menu', 90 );
|
add_action( 'admin_bar_menu', 'wp_admin_bar_help_menu', 90 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user