This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Toolbar API: Top-level Toolbar functionality |
||
| 4 | * |
||
| 5 | * @package WordPress |
||
| 6 | * @subpackage Toolbar |
||
| 7 | * @since 3.1.0 |
||
| 8 | */ |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Instantiate the admin bar object and set it up as a global for access elsewhere. |
||
| 12 | * |
||
| 13 | * UNHOOKING THIS FUNCTION WILL NOT PROPERLY REMOVE THE ADMIN BAR. |
||
| 14 | * For that, use show_admin_bar(false) or the {@see 'show_admin_bar'} filter. |
||
| 15 | * |
||
| 16 | * @since 3.1.0 |
||
| 17 | * @access private |
||
| 18 | * |
||
| 19 | * @global WP_Admin_Bar $wp_admin_bar |
||
| 20 | * |
||
| 21 | * @return bool Whether the admin bar was successfully initialized. |
||
| 22 | */ |
||
| 23 | function _wp_admin_bar_init() { |
||
| 24 | global $wp_admin_bar; |
||
| 25 | |||
| 26 | if ( ! is_admin_bar_showing() ) |
||
| 27 | return false; |
||
| 28 | |||
| 29 | /* Load the admin bar class code ready for instantiation */ |
||
| 30 | require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' ); |
||
| 31 | |||
| 32 | /* Instantiate the admin bar */ |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Filters the admin bar class to instantiate. |
||
| 36 | * |
||
| 37 | * @since 3.1.0 |
||
| 38 | * |
||
| 39 | * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'. |
||
| 40 | */ |
||
| 41 | $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); |
||
| 42 | if ( class_exists( $admin_bar_class ) ) |
||
| 43 | $wp_admin_bar = new $admin_bar_class; |
||
| 44 | else |
||
| 45 | return false; |
||
| 46 | |||
| 47 | $wp_admin_bar->initialize(); |
||
| 48 | $wp_admin_bar->add_menus(); |
||
| 49 | |||
| 50 | return true; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Renders the admin bar to the page based on the $wp_admin_bar->menu member var. |
||
| 55 | * |
||
| 56 | * This is called very late on the footer actions so that it will render after |
||
| 57 | * anything else being added to the footer. |
||
| 58 | * |
||
| 59 | * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and |
||
| 60 | * add new menus to the admin bar. That way you can be sure that you are adding at most |
||
| 61 | * optimal point, right before the admin bar is rendered. This also gives you access to |
||
| 62 | * the `$post` global, among others. |
||
| 63 | * |
||
| 64 | * @since 3.1.0 |
||
| 65 | * |
||
| 66 | * @global WP_Admin_Bar $wp_admin_bar |
||
| 67 | */ |
||
| 68 | function wp_admin_bar_render() { |
||
| 69 | global $wp_admin_bar; |
||
| 70 | |||
| 71 | if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) |
||
| 72 | return; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Load all necessary admin bar items. |
||
| 76 | * |
||
| 77 | * This is the hook used to add, remove, or manipulate admin bar items. |
||
| 78 | * |
||
| 79 | * @since 3.1.0 |
||
| 80 | * |
||
| 81 | * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference |
||
| 82 | */ |
||
| 83 | do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Fires before the admin bar is rendered. |
||
| 87 | * |
||
| 88 | * @since 3.1.0 |
||
| 89 | */ |
||
| 90 | do_action( 'wp_before_admin_bar_render' ); |
||
| 91 | |||
| 92 | $wp_admin_bar->render(); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Fires after the admin bar is rendered. |
||
| 96 | * |
||
| 97 | * @since 3.1.0 |
||
| 98 | */ |
||
| 99 | do_action( 'wp_after_admin_bar_render' ); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Add the WordPress logo menu. |
||
| 104 | * |
||
| 105 | * @since 3.3.0 |
||
| 106 | * |
||
| 107 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 108 | */ |
||
| 109 | function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
||
| 110 | View Code Duplication | if ( current_user_can( 'read' ) ) { |
|
| 111 | $about_url = self_admin_url( 'about.php' ); |
||
| 112 | } elseif ( is_multisite() ) { |
||
| 113 | $about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); |
||
| 114 | } else { |
||
| 115 | $about_url = false; |
||
| 116 | } |
||
| 117 | |||
| 118 | $wp_logo_menu_args = array( |
||
| 119 | 'id' => 'wp-logo', |
||
| 120 | 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>', |
||
| 121 | 'href' => $about_url, |
||
| 122 | ); |
||
| 123 | |||
| 124 | // Set tabindex="0" to make sub menus accessible when no URL is available. |
||
| 125 | if ( ! $about_url ) { |
||
|
0 ignored issues
–
show
|
|||
| 126 | $wp_logo_menu_args['meta'] = array( |
||
| 127 | 'tabindex' => 0, |
||
| 128 | ); |
||
| 129 | } |
||
| 130 | |||
| 131 | $wp_admin_bar->add_menu( $wp_logo_menu_args ); |
||
| 132 | |||
| 133 | if ( $about_url ) { |
||
|
0 ignored issues
–
show
The expression
$about_url of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
| 134 | // Add "About WordPress" link |
||
| 135 | $wp_admin_bar->add_menu( array( |
||
| 136 | 'parent' => 'wp-logo', |
||
| 137 | 'id' => 'about', |
||
| 138 | 'title' => __('About WordPress'), |
||
| 139 | 'href' => $about_url, |
||
| 140 | ) ); |
||
| 141 | } |
||
| 142 | |||
| 143 | // Add WordPress.org link |
||
| 144 | $wp_admin_bar->add_menu( array( |
||
| 145 | 'parent' => 'wp-logo-external', |
||
| 146 | 'id' => 'wporg', |
||
| 147 | 'title' => __('WordPress.org'), |
||
| 148 | 'href' => __('https://wordpress.org/'), |
||
| 149 | ) ); |
||
| 150 | |||
| 151 | // Add codex link |
||
| 152 | $wp_admin_bar->add_menu( array( |
||
| 153 | 'parent' => 'wp-logo-external', |
||
| 154 | 'id' => 'documentation', |
||
| 155 | 'title' => __('Documentation'), |
||
| 156 | 'href' => __('https://codex.wordpress.org/'), |
||
| 157 | ) ); |
||
| 158 | |||
| 159 | // Add forums link |
||
| 160 | $wp_admin_bar->add_menu( array( |
||
| 161 | 'parent' => 'wp-logo-external', |
||
| 162 | 'id' => 'support-forums', |
||
| 163 | 'title' => __('Support Forums'), |
||
| 164 | 'href' => __('https://wordpress.org/support/'), |
||
| 165 | ) ); |
||
| 166 | |||
| 167 | // Add feedback link |
||
| 168 | $wp_admin_bar->add_menu( array( |
||
| 169 | 'parent' => 'wp-logo-external', |
||
| 170 | 'id' => 'feedback', |
||
| 171 | 'title' => __('Feedback'), |
||
| 172 | 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'), |
||
| 173 | ) ); |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Add the sidebar toggle button. |
||
| 178 | * |
||
| 179 | * @since 3.8.0 |
||
| 180 | * |
||
| 181 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 182 | */ |
||
| 183 | function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { |
||
| 184 | if ( is_admin() ) { |
||
| 185 | $wp_admin_bar->add_menu( array( |
||
| 186 | 'id' => 'menu-toggle', |
||
| 187 | 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>', |
||
| 188 | 'href' => '#', |
||
| 189 | ) ); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Add the "My Account" item. |
||
| 195 | * |
||
| 196 | * @since 3.3.0 |
||
| 197 | * |
||
| 198 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 199 | */ |
||
| 200 | function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
||
| 201 | $user_id = get_current_user_id(); |
||
| 202 | $current_user = wp_get_current_user(); |
||
| 203 | |||
| 204 | if ( ! $user_id ) |
||
| 205 | return; |
||
| 206 | |||
| 207 | View Code Duplication | if ( current_user_can( 'read' ) ) { |
|
| 208 | $profile_url = get_edit_profile_url( $user_id ); |
||
| 209 | } elseif ( is_multisite() ) { |
||
| 210 | $profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
||
| 211 | } else { |
||
| 212 | $profile_url = false; |
||
| 213 | } |
||
| 214 | |||
| 215 | $avatar = get_avatar( $user_id, 26 ); |
||
| 216 | /* translators: %s: current user's display name */ |
||
| 217 | $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); |
||
| 218 | $class = empty( $avatar ) ? '' : 'with-avatar'; |
||
| 219 | |||
| 220 | $wp_admin_bar->add_menu( array( |
||
| 221 | 'id' => 'my-account', |
||
| 222 | 'parent' => 'top-secondary', |
||
| 223 | 'title' => $howdy . $avatar, |
||
| 224 | 'href' => $profile_url, |
||
| 225 | 'meta' => array( |
||
| 226 | 'class' => $class, |
||
| 227 | ), |
||
| 228 | ) ); |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Add the "My Account" submenu items. |
||
| 233 | * |
||
| 234 | * @since 3.1.0 |
||
| 235 | * |
||
| 236 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 237 | */ |
||
| 238 | function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
||
| 239 | $user_id = get_current_user_id(); |
||
| 240 | $current_user = wp_get_current_user(); |
||
| 241 | |||
| 242 | if ( ! $user_id ) |
||
| 243 | return; |
||
| 244 | |||
| 245 | View Code Duplication | if ( current_user_can( 'read' ) ) { |
|
| 246 | $profile_url = get_edit_profile_url( $user_id ); |
||
| 247 | } elseif ( is_multisite() ) { |
||
| 248 | $profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
||
| 249 | } else { |
||
| 250 | $profile_url = false; |
||
| 251 | } |
||
| 252 | |||
| 253 | $wp_admin_bar->add_group( array( |
||
| 254 | 'parent' => 'my-account', |
||
| 255 | 'id' => 'user-actions', |
||
| 256 | ) ); |
||
| 257 | |||
| 258 | $user_info = get_avatar( $user_id, 64 ); |
||
| 259 | $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; |
||
| 260 | |||
| 261 | if ( $current_user->display_name !== $current_user->user_login ) |
||
| 262 | $user_info .= "<span class='username'>{$current_user->user_login}</span>"; |
||
| 263 | |||
| 264 | $wp_admin_bar->add_menu( array( |
||
| 265 | 'parent' => 'user-actions', |
||
| 266 | 'id' => 'user-info', |
||
| 267 | 'title' => $user_info, |
||
| 268 | 'href' => $profile_url, |
||
| 269 | 'meta' => array( |
||
| 270 | 'tabindex' => -1, |
||
| 271 | ), |
||
| 272 | ) ); |
||
| 273 | |||
| 274 | if ( false !== $profile_url ) { |
||
| 275 | $wp_admin_bar->add_menu( array( |
||
| 276 | 'parent' => 'user-actions', |
||
| 277 | 'id' => 'edit-profile', |
||
| 278 | 'title' => __( 'Edit My Profile' ), |
||
| 279 | 'href' => $profile_url, |
||
| 280 | ) ); |
||
| 281 | } |
||
| 282 | |||
| 283 | $wp_admin_bar->add_menu( array( |
||
| 284 | 'parent' => 'user-actions', |
||
| 285 | 'id' => 'logout', |
||
| 286 | 'title' => __( 'Log Out' ), |
||
| 287 | 'href' => wp_logout_url(), |
||
| 288 | ) ); |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Add the "Site Name" menu. |
||
| 293 | * |
||
| 294 | * @since 3.3.0 |
||
| 295 | * |
||
| 296 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 297 | */ |
||
| 298 | function wp_admin_bar_site_menu( $wp_admin_bar ) { |
||
| 299 | // Don't show for logged out users. |
||
| 300 | if ( ! is_user_logged_in() ) |
||
| 301 | return; |
||
| 302 | |||
| 303 | // Show only when the user is a member of this site, or they're a super admin. |
||
| 304 | if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) { |
||
| 305 | return; |
||
| 306 | } |
||
| 307 | |||
| 308 | $blogname = get_bloginfo('name'); |
||
| 309 | |||
| 310 | if ( ! $blogname ) { |
||
| 311 | $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
||
| 312 | } |
||
| 313 | |||
| 314 | View Code Duplication | if ( is_network_admin() ) { |
|
| 315 | /* translators: %s: site name */ |
||
| 316 | $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); |
||
| 317 | } elseif ( is_user_admin() ) { |
||
| 318 | /* translators: %s: site name */ |
||
| 319 | $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
||
| 320 | } |
||
| 321 | |||
| 322 | $title = wp_html_excerpt( $blogname, 40, '…' ); |
||
| 323 | |||
| 324 | $wp_admin_bar->add_menu( array( |
||
| 325 | 'id' => 'site-name', |
||
| 326 | 'title' => $title, |
||
| 327 | 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
||
| 328 | ) ); |
||
| 329 | |||
| 330 | // Create submenu items. |
||
| 331 | |||
| 332 | if ( is_admin() ) { |
||
| 333 | // Add an option to visit the site. |
||
| 334 | $wp_admin_bar->add_menu( array( |
||
| 335 | 'parent' => 'site-name', |
||
| 336 | 'id' => 'view-site', |
||
| 337 | 'title' => __( 'Visit Site' ), |
||
| 338 | 'href' => home_url( '/' ), |
||
| 339 | ) ); |
||
| 340 | |||
| 341 | if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
||
| 342 | $wp_admin_bar->add_menu( array( |
||
| 343 | 'parent' => 'site-name', |
||
| 344 | 'id' => 'edit-site', |
||
| 345 | 'title' => __( 'Edit Site' ), |
||
| 346 | 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), |
||
| 347 | ) ); |
||
| 348 | } |
||
| 349 | |||
| 350 | View Code Duplication | } else if ( current_user_can( 'read' ) ) { |
|
| 351 | // We're on the front end, link to the Dashboard. |
||
| 352 | $wp_admin_bar->add_menu( array( |
||
| 353 | 'parent' => 'site-name', |
||
| 354 | 'id' => 'dashboard', |
||
| 355 | 'title' => __( 'Dashboard' ), |
||
| 356 | 'href' => admin_url(), |
||
| 357 | ) ); |
||
| 358 | |||
| 359 | // Add the appearance submenu items. |
||
| 360 | wp_admin_bar_appearance_menu( $wp_admin_bar ); |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Adds the "Customize" link to the Toolbar. |
||
| 366 | * |
||
| 367 | * @since 4.3.0 |
||
| 368 | * |
||
| 369 | * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. |
||
| 370 | * @global WP_Customize_Manager $wp_customize |
||
| 371 | */ |
||
| 372 | function wp_admin_bar_customize_menu( $wp_admin_bar ) { |
||
| 373 | global $wp_customize; |
||
| 374 | |||
| 375 | // Don't show for users who can't access the customizer or when in the admin. |
||
| 376 | if ( ! current_user_can( 'customize' ) || is_admin() ) { |
||
| 377 | return; |
||
| 378 | } |
||
| 379 | |||
| 380 | // Don't show if the user cannot edit a given customize_changeset post currently being previewed. |
||
| 381 | if ( is_customize_preview() && $wp_customize->changeset_post_id() && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) { |
||
| 382 | return; |
||
| 383 | } |
||
| 384 | |||
| 385 | $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
||
| 386 | if ( is_customize_preview() && $wp_customize->changeset_uuid() ) { |
||
| 387 | $current_url = remove_query_arg( 'customize_changeset_uuid', $current_url ); |
||
| 388 | } |
||
| 389 | |||
| 390 | $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); |
||
| 391 | if ( is_customize_preview() ) { |
||
| 392 | $customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url ); |
||
| 393 | } |
||
| 394 | |||
| 395 | $wp_admin_bar->add_menu( array( |
||
| 396 | 'id' => 'customize', |
||
| 397 | 'title' => __( 'Customize' ), |
||
| 398 | 'href' => $customize_url, |
||
| 399 | 'meta' => array( |
||
| 400 | 'class' => 'hide-if-no-customize', |
||
| 401 | ), |
||
| 402 | ) ); |
||
| 403 | add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
||
| 404 | } |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Add the "My Sites/[Site Name]" menu and all submenus. |
||
| 408 | * |
||
| 409 | * @since 3.1.0 |
||
| 410 | * |
||
| 411 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 412 | */ |
||
| 413 | function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { |
||
| 414 | // Don't show for logged out users or single site mode. |
||
| 415 | if ( ! is_user_logged_in() || ! is_multisite() ) |
||
| 416 | return; |
||
| 417 | |||
| 418 | // Show only when the user has at least one site, or they're a super admin. |
||
| 419 | if ( count( $wp_admin_bar->user->blogs ) < 1 && ! current_user_can( 'manage_network' ) ) { |
||
| 420 | return; |
||
| 421 | } |
||
| 422 | |||
| 423 | if ( $wp_admin_bar->user->active_blog ) { |
||
| 424 | $my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' ); |
||
| 425 | } else { |
||
| 426 | $my_sites_url = admin_url( 'my-sites.php' ); |
||
| 427 | } |
||
| 428 | |||
| 429 | $wp_admin_bar->add_menu( array( |
||
| 430 | 'id' => 'my-sites', |
||
| 431 | 'title' => __( 'My Sites' ), |
||
| 432 | 'href' => $my_sites_url, |
||
| 433 | ) ); |
||
| 434 | |||
| 435 | if ( current_user_can( 'manage_network' ) ) { |
||
| 436 | $wp_admin_bar->add_group( array( |
||
| 437 | 'parent' => 'my-sites', |
||
| 438 | 'id' => 'my-sites-super-admin', |
||
| 439 | ) ); |
||
| 440 | |||
| 441 | $wp_admin_bar->add_menu( array( |
||
| 442 | 'parent' => 'my-sites-super-admin', |
||
| 443 | 'id' => 'network-admin', |
||
| 444 | 'title' => __('Network Admin'), |
||
| 445 | 'href' => network_admin_url(), |
||
| 446 | ) ); |
||
| 447 | |||
| 448 | $wp_admin_bar->add_menu( array( |
||
| 449 | 'parent' => 'network-admin', |
||
| 450 | 'id' => 'network-admin-d', |
||
| 451 | 'title' => __( 'Dashboard' ), |
||
| 452 | 'href' => network_admin_url(), |
||
| 453 | ) ); |
||
| 454 | |||
| 455 | View Code Duplication | if ( current_user_can( 'manage_sites' ) ) { |
|
| 456 | $wp_admin_bar->add_menu( array( |
||
| 457 | 'parent' => 'network-admin', |
||
| 458 | 'id' => 'network-admin-s', |
||
| 459 | 'title' => __( 'Sites' ), |
||
| 460 | 'href' => network_admin_url( 'sites.php' ), |
||
| 461 | ) ); |
||
| 462 | } |
||
| 463 | |||
| 464 | View Code Duplication | if ( current_user_can( 'manage_network_users' ) ) { |
|
| 465 | $wp_admin_bar->add_menu( array( |
||
| 466 | 'parent' => 'network-admin', |
||
| 467 | 'id' => 'network-admin-u', |
||
| 468 | 'title' => __( 'Users' ), |
||
| 469 | 'href' => network_admin_url( 'users.php' ), |
||
| 470 | ) ); |
||
| 471 | } |
||
| 472 | |||
| 473 | View Code Duplication | if ( current_user_can( 'manage_network_themes' ) ) { |
|
| 474 | $wp_admin_bar->add_menu( array( |
||
| 475 | 'parent' => 'network-admin', |
||
| 476 | 'id' => 'network-admin-t', |
||
| 477 | 'title' => __( 'Themes' ), |
||
| 478 | 'href' => network_admin_url( 'themes.php' ), |
||
| 479 | ) ); |
||
| 480 | } |
||
| 481 | |||
| 482 | View Code Duplication | if ( current_user_can( 'manage_network_plugins' ) ) { |
|
| 483 | $wp_admin_bar->add_menu( array( |
||
| 484 | 'parent' => 'network-admin', |
||
| 485 | 'id' => 'network-admin-p', |
||
| 486 | 'title' => __( 'Plugins' ), |
||
| 487 | 'href' => network_admin_url( 'plugins.php' ), |
||
| 488 | ) ); |
||
| 489 | } |
||
| 490 | |||
| 491 | View Code Duplication | if ( current_user_can( 'manage_network_options' ) ) { |
|
| 492 | $wp_admin_bar->add_menu( array( |
||
| 493 | 'parent' => 'network-admin', |
||
| 494 | 'id' => 'network-admin-o', |
||
| 495 | 'title' => __( 'Settings' ), |
||
| 496 | 'href' => network_admin_url( 'settings.php' ), |
||
| 497 | ) ); |
||
| 498 | } |
||
| 499 | } |
||
| 500 | |||
| 501 | // Add site links |
||
| 502 | $wp_admin_bar->add_group( array( |
||
| 503 | 'parent' => 'my-sites', |
||
| 504 | 'id' => 'my-sites-list', |
||
| 505 | 'meta' => array( |
||
| 506 | 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
||
| 507 | ), |
||
| 508 | ) ); |
||
| 509 | |||
| 510 | foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
||
| 511 | switch_to_blog( $blog->userblog_id ); |
||
| 512 | |||
| 513 | $blavatar = '<div class="blavatar"></div>'; |
||
| 514 | |||
| 515 | $blogname = $blog->blogname; |
||
| 516 | |||
| 517 | if ( ! $blogname ) { |
||
| 518 | $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
||
| 519 | } |
||
| 520 | |||
| 521 | $menu_id = 'blog-' . $blog->userblog_id; |
||
| 522 | |||
| 523 | $wp_admin_bar->add_menu( array( |
||
| 524 | 'parent' => 'my-sites-list', |
||
| 525 | 'id' => $menu_id, |
||
| 526 | 'title' => $blavatar . $blogname, |
||
| 527 | 'href' => admin_url(), |
||
| 528 | ) ); |
||
| 529 | |||
| 530 | $wp_admin_bar->add_menu( array( |
||
| 531 | 'parent' => $menu_id, |
||
| 532 | 'id' => $menu_id . '-d', |
||
| 533 | 'title' => __( 'Dashboard' ), |
||
| 534 | 'href' => admin_url(), |
||
| 535 | ) ); |
||
| 536 | |||
| 537 | View Code Duplication | if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
|
| 538 | $wp_admin_bar->add_menu( array( |
||
| 539 | 'parent' => $menu_id, |
||
| 540 | 'id' => $menu_id . '-n', |
||
| 541 | 'title' => __( 'New Post' ), |
||
| 542 | 'href' => admin_url( 'post-new.php' ), |
||
| 543 | ) ); |
||
| 544 | } |
||
| 545 | |||
| 546 | if ( current_user_can( 'edit_posts' ) ) { |
||
| 547 | $wp_admin_bar->add_menu( array( |
||
| 548 | 'parent' => $menu_id, |
||
| 549 | 'id' => $menu_id . '-c', |
||
| 550 | 'title' => __( 'Manage Comments' ), |
||
| 551 | 'href' => admin_url( 'edit-comments.php' ), |
||
| 552 | ) ); |
||
| 553 | } |
||
| 554 | |||
| 555 | $wp_admin_bar->add_menu( array( |
||
| 556 | 'parent' => $menu_id, |
||
| 557 | 'id' => $menu_id . '-v', |
||
| 558 | 'title' => __( 'Visit Site' ), |
||
| 559 | 'href' => home_url( '/' ), |
||
| 560 | ) ); |
||
| 561 | |||
| 562 | restore_current_blog(); |
||
| 563 | } |
||
| 564 | } |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Provide a shortlink. |
||
| 568 | * |
||
| 569 | * @since 3.1.0 |
||
| 570 | * |
||
| 571 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 572 | */ |
||
| 573 | function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
||
| 574 | $short = wp_get_shortlink( 0, 'query' ); |
||
| 575 | $id = 'get-shortlink'; |
||
| 576 | |||
| 577 | if ( empty( $short ) ) |
||
| 578 | return; |
||
| 579 | |||
| 580 | $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />'; |
||
| 581 | |||
| 582 | $wp_admin_bar->add_menu( array( |
||
| 583 | 'id' => $id, |
||
| 584 | 'title' => __( 'Shortlink' ), |
||
| 585 | 'href' => $short, |
||
| 586 | 'meta' => array( 'html' => $html ), |
||
| 587 | ) ); |
||
| 588 | } |
||
| 589 | |||
| 590 | /** |
||
| 591 | * Provide an edit link for posts and terms. |
||
| 592 | * |
||
| 593 | * @since 3.1.0 |
||
| 594 | * |
||
| 595 | * @global WP_Term $tag |
||
| 596 | * @global WP_Query $wp_the_query |
||
| 597 | * |
||
| 598 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 599 | */ |
||
| 600 | function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
||
| 601 | global $tag, $wp_the_query; |
||
| 602 | |||
| 603 | if ( is_admin() ) { |
||
| 604 | $current_screen = get_current_screen(); |
||
| 605 | $post = get_post(); |
||
| 606 | |||
| 607 | if ( 'post' == $current_screen->base |
||
| 608 | && 'add' != $current_screen->action |
||
| 609 | && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
||
| 610 | && current_user_can( 'read_post', $post->ID ) |
||
| 611 | && ( $post_type_object->public ) |
||
| 612 | && ( $post_type_object->show_in_admin_bar ) ) |
||
| 613 | { |
||
| 614 | if ( 'draft' == $post->post_status ) { |
||
| 615 | $preview_link = get_preview_post_link( $post ); |
||
| 616 | $wp_admin_bar->add_menu( array( |
||
| 617 | 'id' => 'preview', |
||
| 618 | 'title' => $post_type_object->labels->view_item, |
||
| 619 | 'href' => esc_url( $preview_link ), |
||
| 620 | 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
||
| 621 | ) ); |
||
| 622 | } else { |
||
| 623 | $wp_admin_bar->add_menu( array( |
||
| 624 | 'id' => 'view', |
||
| 625 | 'title' => $post_type_object->labels->view_item, |
||
| 626 | 'href' => get_permalink( $post->ID ) |
||
| 627 | ) ); |
||
| 628 | } |
||
| 629 | } elseif ( 'edit' == $current_screen->base |
||
| 630 | && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) |
||
| 631 | && ( $post_type_object->public ) |
||
| 632 | && ( $post_type_object->show_in_admin_bar ) |
||
| 633 | && ( get_post_type_archive_link( $post_type_object->name ) ) |
||
| 634 | && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) |
||
|
0 ignored issues
–
show
The variable
$post_type_object does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 635 | { |
||
| 636 | $wp_admin_bar->add_node( array( |
||
| 637 | 'id' => 'archive', |
||
| 638 | 'title' => $post_type_object->labels->view_items, |
||
| 639 | 'href' => get_post_type_archive_link( $current_screen->post_type ) |
||
| 640 | ) ); |
||
| 641 | } elseif ( 'term' == $current_screen->base |
||
| 642 | && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) |
||
| 643 | && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
||
| 644 | && $tax->public ) |
||
| 645 | { |
||
| 646 | $wp_admin_bar->add_menu( array( |
||
| 647 | 'id' => 'view', |
||
| 648 | 'title' => $tax->labels->view_item, |
||
| 649 | 'href' => get_term_link( $tag ) |
||
| 650 | ) ); |
||
| 651 | } |
||
| 652 | } else { |
||
| 653 | $current_object = $wp_the_query->get_queried_object(); |
||
| 654 | |||
| 655 | if ( empty( $current_object ) ) |
||
| 656 | return; |
||
| 657 | |||
| 658 | if ( ! empty( $current_object->post_type ) |
||
| 659 | && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
||
| 660 | && current_user_can( 'edit_post', $current_object->ID ) |
||
| 661 | && $post_type_object->show_in_admin_bar |
||
| 662 | && $edit_post_link = get_edit_post_link( $current_object->ID ) ) |
||
| 663 | { |
||
| 664 | $wp_admin_bar->add_menu( array( |
||
| 665 | 'id' => 'edit', |
||
| 666 | 'title' => $post_type_object->labels->edit_item, |
||
| 667 | 'href' => $edit_post_link |
||
| 668 | ) ); |
||
| 669 | } elseif ( ! empty( $current_object->taxonomy ) |
||
| 670 | && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
||
| 671 | && current_user_can( 'edit_term', $current_object->term_id ) |
||
| 672 | && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) |
||
| 673 | { |
||
| 674 | $wp_admin_bar->add_menu( array( |
||
| 675 | 'id' => 'edit', |
||
| 676 | 'title' => $tax->labels->edit_item, |
||
| 677 | 'href' => $edit_term_link |
||
| 678 | ) ); |
||
| 679 | } |
||
| 680 | } |
||
| 681 | } |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Add "Add New" menu. |
||
| 685 | * |
||
| 686 | * @since 3.1.0 |
||
| 687 | * |
||
| 688 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 689 | */ |
||
| 690 | function wp_admin_bar_new_content_menu( $wp_admin_bar ) { |
||
| 691 | $actions = array(); |
||
| 692 | |||
| 693 | $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); |
||
| 694 | |||
| 695 | View Code Duplication | if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) |
|
| 696 | $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); |
||
| 697 | |||
| 698 | View Code Duplication | if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) |
|
| 699 | $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); |
||
| 700 | |||
| 701 | if ( current_user_can( 'manage_links' ) ) |
||
| 702 | $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); |
||
| 703 | |||
| 704 | View Code Duplication | if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) |
|
| 705 | $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); |
||
| 706 | |||
| 707 | unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); |
||
| 708 | |||
| 709 | // Add any additional custom post types. |
||
| 710 | foreach ( $cpts as $cpt ) { |
||
| 711 | if ( ! current_user_can( $cpt->cap->create_posts ) ) |
||
| 712 | continue; |
||
| 713 | |||
| 714 | $key = 'post-new.php?post_type=' . $cpt->name; |
||
| 715 | $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); |
||
| 716 | } |
||
| 717 | // Avoid clash with parent node and a 'content' post type. |
||
| 718 | if ( isset( $actions['post-new.php?post_type=content'] ) ) |
||
| 719 | $actions['post-new.php?post_type=content'][1] = 'add-new-content'; |
||
| 720 | |||
| 721 | if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { |
||
| 722 | $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); |
||
| 723 | } |
||
| 724 | |||
| 725 | if ( ! $actions ) |
||
|
0 ignored issues
–
show
The expression
$actions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 726 | return; |
||
| 727 | |||
| 728 | $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
||
| 729 | |||
| 730 | $wp_admin_bar->add_menu( array( |
||
| 731 | 'id' => 'new-content', |
||
| 732 | 'title' => $title, |
||
| 733 | 'href' => admin_url( current( array_keys( $actions ) ) ), |
||
|
0 ignored issues
–
show
|
|||
| 734 | ) ); |
||
| 735 | |||
| 736 | foreach ( $actions as $link => $action ) { |
||
| 737 | list( $title, $id ) = $action; |
||
| 738 | |||
| 739 | $wp_admin_bar->add_menu( array( |
||
| 740 | 'parent' => 'new-content', |
||
| 741 | 'id' => $id, |
||
| 742 | 'title' => $title, |
||
| 743 | 'href' => admin_url( $link ) |
||
| 744 | ) ); |
||
| 745 | } |
||
| 746 | } |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Add edit comments link with awaiting moderation count bubble. |
||
| 750 | * |
||
| 751 | * @since 3.1.0 |
||
| 752 | * |
||
| 753 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 754 | */ |
||
| 755 | function wp_admin_bar_comments_menu( $wp_admin_bar ) { |
||
| 756 | if ( !current_user_can('edit_posts') ) |
||
| 757 | return; |
||
| 758 | |||
| 759 | $awaiting_mod = wp_count_comments(); |
||
| 760 | $awaiting_mod = $awaiting_mod->moderated; |
||
| 761 | $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); |
||
| 762 | |||
| 763 | $icon = '<span class="ab-icon"></span>'; |
||
| 764 | $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
||
| 765 | $title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>'; |
||
| 766 | |||
| 767 | $wp_admin_bar->add_menu( array( |
||
| 768 | 'id' => 'comments', |
||
| 769 | 'title' => $icon . $title, |
||
| 770 | 'href' => admin_url('edit-comments.php'), |
||
| 771 | ) ); |
||
| 772 | } |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Add appearance submenu items to the "Site Name" menu. |
||
| 776 | * |
||
| 777 | * @since 3.1.0 |
||
| 778 | * |
||
| 779 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 780 | */ |
||
| 781 | function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
||
| 782 | $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); |
||
| 783 | |||
| 784 | View Code Duplication | if ( current_user_can( 'switch_themes' ) ) { |
|
| 785 | $wp_admin_bar->add_menu( array( |
||
| 786 | 'parent' => 'appearance', |
||
| 787 | 'id' => 'themes', |
||
| 788 | 'title' => __( 'Themes' ), |
||
| 789 | 'href' => admin_url( 'themes.php' ), |
||
| 790 | ) ); |
||
| 791 | } |
||
| 792 | |||
| 793 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
||
| 794 | return; |
||
| 795 | } |
||
| 796 | |||
| 797 | View Code Duplication | if ( current_theme_supports( 'widgets' ) ) { |
|
| 798 | $wp_admin_bar->add_menu( array( |
||
| 799 | 'parent' => 'appearance', |
||
| 800 | 'id' => 'widgets', |
||
| 801 | 'title' => __( 'Widgets' ), |
||
| 802 | 'href' => admin_url( 'widgets.php' ), |
||
| 803 | ) ); |
||
| 804 | } |
||
| 805 | |||
| 806 | View Code Duplication | if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) |
|
| 807 | $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); |
||
| 808 | |||
| 809 | View Code Duplication | if ( current_theme_supports( 'custom-background' ) ) { |
|
| 810 | $wp_admin_bar->add_menu( array( |
||
| 811 | 'parent' => 'appearance', |
||
| 812 | 'id' => 'background', |
||
| 813 | 'title' => __( 'Background' ), |
||
| 814 | 'href' => admin_url( 'themes.php?page=custom-background' ), |
||
| 815 | 'meta' => array( |
||
| 816 | 'class' => 'hide-if-customize', |
||
| 817 | ), |
||
| 818 | ) ); |
||
| 819 | } |
||
| 820 | |||
| 821 | View Code Duplication | if ( current_theme_supports( 'custom-header' ) ) { |
|
| 822 | $wp_admin_bar->add_menu( array( |
||
| 823 | 'parent' => 'appearance', |
||
| 824 | 'id' => 'header', |
||
| 825 | 'title' => __( 'Header' ), |
||
| 826 | 'href' => admin_url( 'themes.php?page=custom-header' ), |
||
| 827 | 'meta' => array( |
||
| 828 | 'class' => 'hide-if-customize', |
||
| 829 | ), |
||
| 830 | ) ); |
||
| 831 | } |
||
| 832 | |||
| 833 | } |
||
| 834 | |||
| 835 | /** |
||
| 836 | * Provide an update link if theme/plugin/core updates are available. |
||
| 837 | * |
||
| 838 | * @since 3.1.0 |
||
| 839 | * |
||
| 840 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 841 | */ |
||
| 842 | function wp_admin_bar_updates_menu( $wp_admin_bar ) { |
||
| 843 | |||
| 844 | $update_data = wp_get_update_data(); |
||
| 845 | |||
| 846 | if ( !$update_data['counts']['total'] ) |
||
| 847 | return; |
||
| 848 | |||
| 849 | $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; |
||
| 850 | $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; |
||
| 851 | |||
| 852 | $wp_admin_bar->add_menu( array( |
||
| 853 | 'id' => 'updates', |
||
| 854 | 'title' => $title, |
||
| 855 | 'href' => network_admin_url( 'update-core.php' ), |
||
| 856 | 'meta' => array( |
||
| 857 | 'title' => $update_data['title'], |
||
| 858 | ), |
||
| 859 | ) ); |
||
| 860 | } |
||
| 861 | |||
| 862 | /** |
||
| 863 | * Add search form. |
||
| 864 | * |
||
| 865 | * @since 3.3.0 |
||
| 866 | * |
||
| 867 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 868 | */ |
||
| 869 | function wp_admin_bar_search_menu( $wp_admin_bar ) { |
||
| 870 | if ( is_admin() ) |
||
| 871 | return; |
||
| 872 | |||
| 873 | $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; |
||
| 874 | $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; |
||
| 875 | $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>'; |
||
| 876 | $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>'; |
||
| 877 | $form .= '</form>'; |
||
| 878 | |||
| 879 | $wp_admin_bar->add_menu( array( |
||
| 880 | 'parent' => 'top-secondary', |
||
| 881 | 'id' => 'search', |
||
| 882 | 'title' => $form, |
||
| 883 | 'meta' => array( |
||
| 884 | 'class' => 'admin-bar-search', |
||
| 885 | 'tabindex' => -1, |
||
| 886 | ) |
||
| 887 | ) ); |
||
| 888 | } |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Add secondary menus. |
||
| 892 | * |
||
| 893 | * @since 3.3.0 |
||
| 894 | * |
||
| 895 | * @param WP_Admin_Bar $wp_admin_bar |
||
| 896 | */ |
||
| 897 | function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
||
| 898 | $wp_admin_bar->add_group( array( |
||
| 899 | 'id' => 'top-secondary', |
||
| 900 | 'meta' => array( |
||
| 901 | 'class' => 'ab-top-secondary', |
||
| 902 | ), |
||
| 903 | ) ); |
||
| 904 | |||
| 905 | $wp_admin_bar->add_group( array( |
||
| 906 | 'parent' => 'wp-logo', |
||
| 907 | 'id' => 'wp-logo-external', |
||
| 908 | 'meta' => array( |
||
| 909 | 'class' => 'ab-sub-secondary', |
||
| 910 | ), |
||
| 911 | ) ); |
||
| 912 | } |
||
| 913 | |||
| 914 | /** |
||
| 915 | * Style and scripts for the admin bar. |
||
| 916 | * |
||
| 917 | * @since 3.1.0 |
||
| 918 | */ |
||
| 919 | function wp_admin_bar_header() { ?> |
||
| 920 | <style type="text/css" media="print">#wpadminbar { display:none; }</style> |
||
| 921 | <?php |
||
| 922 | } |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Default admin bar callback. |
||
| 926 | * |
||
| 927 | * @since 3.1.0 |
||
| 928 | */ |
||
| 929 | function _admin_bar_bump_cb() { ?> |
||
| 930 | <style type="text/css" media="screen"> |
||
| 931 | html { margin-top: 32px !important; } |
||
| 932 | * html body { margin-top: 32px !important; } |
||
| 933 | @media screen and ( max-width: 782px ) { |
||
| 934 | html { margin-top: 46px !important; } |
||
| 935 | * html body { margin-top: 46px !important; } |
||
| 936 | } |
||
| 937 | </style> |
||
| 938 | <?php |
||
| 939 | } |
||
| 940 | |||
| 941 | /** |
||
| 942 | * Sets the display status of the admin bar. |
||
| 943 | * |
||
| 944 | * This can be called immediately upon plugin load. It does not need to be called |
||
| 945 | * from a function hooked to the {@see 'init'} action. |
||
| 946 | * |
||
| 947 | * @since 3.1.0 |
||
| 948 | * |
||
| 949 | * @global bool $show_admin_bar |
||
| 950 | * |
||
| 951 | * @param bool $show Whether to allow the admin bar to show. |
||
| 952 | */ |
||
| 953 | function show_admin_bar( $show ) { |
||
| 954 | global $show_admin_bar; |
||
| 955 | $show_admin_bar = (bool) $show; |
||
| 956 | } |
||
| 957 | |||
| 958 | /** |
||
| 959 | * Determine whether the admin bar should be showing. |
||
| 960 | * |
||
| 961 | * @since 3.1.0 |
||
| 962 | * |
||
| 963 | * @global bool $show_admin_bar |
||
| 964 | * @global string $pagenow |
||
| 965 | * |
||
| 966 | * @return bool Whether the admin bar should be showing. |
||
| 967 | */ |
||
| 968 | function is_admin_bar_showing() { |
||
| 969 | global $show_admin_bar, $pagenow; |
||
| 970 | |||
| 971 | // For all these types of requests, we never want an admin bar. |
||
| 972 | if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') ) |
||
| 973 | return false; |
||
| 974 | |||
| 975 | if ( is_embed() ) { |
||
| 976 | return false; |
||
| 977 | } |
||
| 978 | |||
| 979 | // Integrated into the admin. |
||
| 980 | if ( is_admin() ) |
||
| 981 | return true; |
||
| 982 | |||
| 983 | if ( ! isset( $show_admin_bar ) ) { |
||
| 984 | if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) { |
||
| 985 | $show_admin_bar = false; |
||
| 986 | } else { |
||
| 987 | $show_admin_bar = _get_admin_bar_pref(); |
||
| 988 | } |
||
| 989 | } |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Filters whether to show the admin bar. |
||
| 993 | * |
||
| 994 | * Returning false to this hook is the recommended way to hide the admin bar. |
||
| 995 | * The user's display preference is used for logged in users. |
||
| 996 | * |
||
| 997 | * @since 3.1.0 |
||
| 998 | * |
||
| 999 | * @param bool $show_admin_bar Whether the admin bar should be shown. Default false. |
||
| 1000 | */ |
||
| 1001 | $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar ); |
||
| 1002 | |||
| 1003 | return $show_admin_bar; |
||
| 1004 | } |
||
| 1005 | |||
| 1006 | /** |
||
| 1007 | * Retrieve the admin bar display preference of a user. |
||
| 1008 | * |
||
| 1009 | * @since 3.1.0 |
||
| 1010 | * @access private |
||
| 1011 | * |
||
| 1012 | * @param string $context Context of this preference check. Defaults to 'front'. The 'admin' |
||
| 1013 | * preference is no longer used. |
||
| 1014 | * @param int $user Optional. ID of the user to check, defaults to 0 for current user. |
||
| 1015 | * @return bool Whether the admin bar should be showing for this user. |
||
| 1016 | */ |
||
| 1017 | function _get_admin_bar_pref( $context = 'front', $user = 0 ) { |
||
| 1018 | $pref = get_user_option( "show_admin_bar_{$context}", $user ); |
||
| 1019 | if ( false === $pref ) |
||
| 1020 | return true; |
||
| 1021 | |||
| 1022 | return 'true' === $pref; |
||
| 1023 | } |
||
| 1024 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: