Make WordPress Core


Ignore:
Timestamp:
10/28/2010 08:31:36 AM (16 years ago)
Author:
westi
Message:

Admin bar cleanup. See #14772 props filosofo.
Moves CSS into seperate files.
Patch cleanup included moving function call arguments back on to one line where not necessary to split them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/admin-bar/admin-bar-class.php

    r15915 r16038  
    11<?php
    22class WP_Admin_Bar {
    3         var $user;
     3        var $changed_locale = false;
    44        var $menu;
    55        var $need_to_change_locale = false;
    6         var $changed_locale = false;
    7 
    8         function WP_Admin_Bar() {
    9                 global $current_user, $blog_id;
     6        var $proto = 'http://';
     7        var $user;
     8
     9        function initialize() {
     10                global $blog_id;
     11
     12                /* Only load super admin menu code if the logged in user is a super admin */
     13                if ( is_super_admin() ) {
     14                        require( ABSPATH . WPINC . '/admin-bar/admin-bar-debug.php' );
     15                        require( ABSPATH . WPINC . '/admin-bar/admin-bar-superadmin.php' );
     16                }
     17               
     18                /* Set the protocol used throughout this code */
     19                if ( is_ssl() )
     20                        $this->proto = 'https://';
    1021
    1122                $this->user = new stdClass;
    … …  
    1324
    1425                /* Populate settings we need for the menu based on the current user. */
    15                 $this->user->blogs = get_blogs_of_user( $current_user->id );
     26                $this->user->blogs = get_blogs_of_user( get_current_user_id() );
    1627                if ( is_multisite() ) {
    17                         $this->user->active_blog = get_active_blog_for_user( $current_user->id );
     28                        $this->user->active_blog = get_active_blog_for_user( get_current_user_id() );
    1829                        $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) );
    1930                        $this->user->account_domain = $this->user->domain;
    … …  
    2435                }
    2536                $this->user->locale = get_locale();
     37
     38                add_action( 'wp_head', 'wp_admin_bar_header' );
     39                add_action( 'admin_head', 'wp_admin_bar_header' );
     40
     41                wp_enqueue_style( 'admin-bar' );
     42
     43                if ( is_super_admin() ) {
     44                        wp_enqueue_style( 'super-admin-bar' );
     45                }
     46               
     47                do_action( 'admin_bar_init' );
    2648        }
    2749
    … …  
    4567                        $id = esc_attr( sanitize_title( trim( $title ) ) );
    4668
    47                 if ( !empty( $parent ) ) {
     69                if ( ! empty( $parent ) ) {
    4870                        /* Add the menu to the parent item */
    49                         $child = array(
    50                                 'id' => $id,
    51                                 'title' => $title,
    52                                 'href' => $href
    53                         );
    54 
    55                         if ( !empty( $meta ) )
     71                        $child = array( 'id' => $id, 'title' => $title, 'href' => $href );
     72
     73                        if ( ! empty( $meta ) )
    5674                                $child['meta'] = $meta;
    5775
    … …  
    5977                } else {
    6078                        /* Add the menu item */
    61                         $this->menu->{$id} = array(
    62                                 'title' => $title,
    63                                 'href' => $href
    64                         );
    65 
    66                         if ( !empty( $meta ) )
     79                        $this->menu->{$id} = array( 'title' => $title, 'href' => $href );
     80
     81                        if ( ! empty( $meta ) )
    6782                                $this->menu->{$id}['meta'] = $meta;
    6883                }
    … …  
    7489       
    7590        function render() {
    76         ?>
     91                ?>
    7792                <div id="wpadminbar" class="snap_nopreview no-grav">
    7893                        <div class="quicklinks">
    … …  
    86101                        <div id="adminbarsearch-wrap">
    87102                                <form action="<?php echo home_url(); ?>" method="get" id="adminbarsearch">
    88                                         <input class="adminbar-input" name="s" id="s" type="text" value="<?php esc_attr_e( 'Search' ); ?>" maxlength="150" onfocus="this.value=(this.value=='<?php esc_attr_e( 'Search' ); ?>') ? '' : this.value;" onblur="this.value=(this.value=='') ? '<?php esc_attr_e( 'Search' ); ?>' : this.value;" /> <button type="submit" class="adminbar-button"><span><?php _e('Search'); ?></span></button>
     103                                        <input class="adminbar-input" name="s" id="adminbar-search" type="text" title="<?php esc_attr_e( 'Search' ); ?>" value="" maxlength="150" />
     104                                        <button type="submit" class="adminbar-button"><span><?php _e('Search'); ?></span></button>
    89105                                </form>
    90106                        </div>
    … …  
    98114        /* Helpers */
    99115        function recursive_render( $id, &$menu_item ) { ?>
    100                 <?php $menuclass = ( !empty( $menu_item['children'] ) ) ? 'menupop ' : ''; ?>
    101 
    102                 <li class="<?php echo $menuclass . "ab-$id" ?><?php if ( !empty( $menu_item['meta']['class'] ) ) : ?><?php echo ' ' . $menu_item['meta']['class'] ?><?php endif; ?>">
    103                         <a href="<?php echo strip_tags( $menu_item['href'] ) ?>"<?php if ( !empty( $menu_item['meta']['onclick'] ) ) :?> onclick="<?php echo $menu_item['meta']['onclick'] ?>"<?php endif; ?><?php if ( !empty( $menu_item['meta']['target'] ) ) :?> target="<?php echo $menu_item['meta']['target'] ?>"<?php endif; ?>><?php if ( !empty( $menuclass ) ) : ?><span><?php endif; ?><?php echo $menu_item['title'] ?><?php if ( !empty( $menuclass ) ) : ?></span><?php endif; ?></a>
    104 
    105                         <?php if ( !empty( $menu_item['children'] ) ) : ?>
     116                <?php $menuclass = ( ! empty( $menu_item['children'] ) ) ? 'menupop ' : ''; ?>
     117
     118                <li class="<?php echo $menuclass . "ab-$id" ?><?php
     119                        if ( ! empty( $menu_item['meta']['class'] ) ) :
     120                                echo ' ' . $menu_item['meta']['class'];
     121                        endif;
     122                ?>">
     123                        <a href="<?php echo strip_tags( $menu_item['href'] ) ?>"<?php
     124                                if ( ! empty( $menu_item['meta']['onclick'] ) ) :
     125                                        ?> onclick="<?php echo $menu_item['meta']['onclick']; ?>"<?php
     126                                endif;
     127                        if ( ! empty( $menu_item['meta']['target'] ) ) :
     128                                ?> target="<?php echo $menu_item['meta']['target']; ?>"<?php
     129                        endif;
     130                       
     131                        ?>><?php
     132                       
     133                        if ( ! empty( $menuclass ) ) :
     134                                ?><span><?php
     135                        endif;
     136                       
     137                        echo $menu_item['title'];
     138                       
     139                        if ( ! empty( $menuclass ) ) :
     140                                ?></span><?php
     141                        endif;
     142                       
     143                        ?></a>
     144
     145                        <?php if ( ! empty( $menu_item['children'] ) ) : ?>
    106146                        <ul>
    107147                                <?php foreach ( $menu_item['children'] as $child_id => $child_menu_item ) : ?>
    … …  
    111151                        <?php endif; ?>
    112152
    113                         <?php if ( !empty( $menu_item['meta']['html'] ) ) : ?>
     153                        <?php if ( ! empty( $menu_item['meta']['html'] ) ) : ?>
    114154                                <?php echo $menu_item['meta']['html']; ?>
    115155                        <?php endif; ?>
    … …  
    125165                        }
    126166
    127                         if ( !empty( $menu->{$id}['children'] ) )
     167                        if ( ! empty( $menu->{$id}['children'] ) )
    128168                                $this->add_node( $parent_id, $menu->{$id}['children'], $child );
    129169                }
     170               
    130171                $child = null;
    131172
    132173                return false;
     174        }
     175
     176        function add_menus() {
     177                add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_me_separator', 10 );
     178                add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_account_menu', 20 );
     179                add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_blogs_menu', 30 );
     180                add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_blog_separator', 40 );
     181                add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_bloginfo_menu', 50 );
     182                add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_edit_menu', 100 );
     183               
     184                if ( is_multisite() && is_super_admin() && function_exists('wp_admin_bar_superadmin_settings_menu') )
     185                        add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_superadmin_settings_menu', 1000 );
     186
     187                do_action('add_admin_bar_menus');
    133188        }
    134189
    … …  
    140195                        }
    141196
    142                         if ( !empty( $menu->{$menu_item_id}['children'] ) )
     197                        if ( ! empty( $menu->{$menu_item_id}['children'] ) )
    143198                                $this->remove_node( $id, $menu->{$menu_item_id}['children'] );
    144199                }
    … …  
    149204        function load_user_locale_translations() {
    150205                $this->need_to_change_locale = ( get_locale() != $this->user->locale );
    151                 if ( !$this->need_to_change_locale ) return;
     206                if ( ! $this->need_to_change_locale )
     207                        return;
    152208                $this->previous_translations = get_translations_for_domain( 'default' );
    153209                $this->adminbar_locale_filter = lambda( '$_', '$GLOBALS["wp_admin_bar"]->user->locale;' );
    … …  
    160216        function unload_user_locale_translations() {
    161217                global $l10n;
    162                 if ( !$this->changed_locale ) return;
     218                if ( ! $this->changed_locale )
     219                        return;
    163220                remove_filter( 'locale', $this->adminbar_locale_filter );
    164221                $l10n['default'] = &$this->previous_translations;
    165 
    166222        }
    167223}
Note: See TracChangeset for help on using the changeset viewer.