Changeset 16038 for trunk/wp-includes/admin-bar/admin-bar-class.php
- Timestamp:
- 10/28/2010 08:31:36 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/admin-bar/admin-bar-class.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/admin-bar/admin-bar-class.php
r15915 r16038 1 1 <?php 2 2 class WP_Admin_Bar { 3 var $ user;3 var $changed_locale = false; 4 4 var $menu; 5 5 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://'; 10 21 11 22 $this->user = new stdClass; … … 13 24 14 25 /* 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() ); 16 27 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() ); 18 29 $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); 19 30 $this->user->account_domain = $this->user->domain; … … 24 35 } 25 36 $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' ); 26 48 } 27 49 … … 45 67 $id = esc_attr( sanitize_title( trim( $title ) ) ); 46 68 47 if ( ! empty( $parent ) ) {69 if ( ! empty( $parent ) ) { 48 70 /* 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 ) ) 56 74 $child['meta'] = $meta; 57 75 … … 59 77 } else { 60 78 /* 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 ) ) 67 82 $this->menu->{$id}['meta'] = $meta; 68 83 } … … 74 89 75 90 function render() { 76 ?>91 ?> 77 92 <div id="wpadminbar" class="snap_nopreview no-grav"> 78 93 <div class="quicklinks"> … … 86 101 <div id="adminbarsearch-wrap"> 87 102 <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> 89 105 </form> 90 106 </div> … … 98 114 /* Helpers */ 99 115 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'] ) ) : ?> 106 146 <ul> 107 147 <?php foreach ( $menu_item['children'] as $child_id => $child_menu_item ) : ?> … … 111 151 <?php endif; ?> 112 152 113 <?php if ( ! empty( $menu_item['meta']['html'] ) ) : ?>153 <?php if ( ! empty( $menu_item['meta']['html'] ) ) : ?> 114 154 <?php echo $menu_item['meta']['html']; ?> 115 155 <?php endif; ?> … … 125 165 } 126 166 127 if ( ! empty( $menu->{$id}['children'] ) )167 if ( ! empty( $menu->{$id}['children'] ) ) 128 168 $this->add_node( $parent_id, $menu->{$id}['children'], $child ); 129 169 } 170 130 171 $child = null; 131 172 132 173 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'); 133 188 } 134 189 … … 140 195 } 141 196 142 if ( ! empty( $menu->{$menu_item_id}['children'] ) )197 if ( ! empty( $menu->{$menu_item_id}['children'] ) ) 143 198 $this->remove_node( $id, $menu->{$menu_item_id}['children'] ); 144 199 } … … 149 204 function load_user_locale_translations() { 150 205 $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; 152 208 $this->previous_translations = get_translations_for_domain( 'default' ); 153 209 $this->adminbar_locale_filter = lambda( '$_', '$GLOBALS["wp_admin_bar"]->user->locale;' ); … … 160 216 function unload_user_locale_translations() { 161 217 global $l10n; 162 if ( !$this->changed_locale ) return; 218 if ( ! $this->changed_locale ) 219 return; 163 220 remove_filter( 'locale', $this->adminbar_locale_filter ); 164 221 $l10n['default'] = &$this->previous_translations; 165 166 222 } 167 223 }
Note: See TracChangeset
for help on using the changeset viewer.