Make WordPress Core


Ignore:
Timestamp:
12/17/2010 09:48:30 PM (13 years ago)
Author:
ryan
Message:

Admin bar visibility prefs. Props duck_. see #15829

File:
1 edited

Legend:

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

    r17019 r17032  
    301301
    302302/**
     303 * Set the display status of the admin bar
     304 *
     305 * This can be called immediately upon plugin load.  It does not need to be called from a function hooked to the init action.
     306 *
     307 * @since 3.1.0
     308 *
     309 * @param bool $show Whether to allow the admin bar to show.
     310 * @return void
     311 */
     312function show_admin_bar( $show ) {
     313    global $show_admin_bar;
     314    $show_admin_bar = (bool) $show;
     315   
     316    // Remove the object if we are not going to be showing
     317    // Otherwise you have to call this function prior to the init hook for it to work!
     318    if ( ! $show_admin_bar && isset( $GLOBALS['wp_admin_bar'] ) )
     319        $GLOBALS['wp_admin_bar'] = null;
     320}
     321
     322/**
    303323 * Determine whether the admin bar should be showing.
    304324 *
     
    315335
    316336    if ( ! isset( $show_admin_bar ) ) {
    317         if ( ! is_user_logged_in() || ( is_admin() && ! is_multisite() ) ) {
     337        if ( ! is_user_logged_in() ) {
    318338            $show_admin_bar = false;
    319339        } else {
    320             $show_admin_bar = true;
     340            $context = is_admin() ? 'admin' : 'front';
     341            $show_admin_bar = _get_admin_bar_pref( $context );
    321342        }
    322343    }
     
    326347    return $show_admin_bar;
    327348}
     349
     350/**
     351 * Retrieve the admin bar display preference of a user based on context.
     352 *
     353 * @since 3.1.0
     354 * @access private
     355 *
     356 * @param string $context Context of this preference check, either 'admin' or 'front'
     357 * @param int $user Optional. ID of the user to check, defaults to 0 for current user
     358 * @return bool Whether the admin bar should be showing for this user
     359 */
     360function _get_admin_bar_pref( $context, $user = 0 ) {
     361    $pref = get_user_option( "show_admin_bar_{$context}", $user );
     362    if ( false === $pref )
     363        return 'admin' != $context || is_multisite();
     364   
     365    return 'true' === $pref;
     366}
    328367?>
Note: See TracChangeset for help on using the changeset viewer.