WordPress.org

Make WordPress Core

Changeset 17032


Ignore:
Timestamp:
12/17/10 21:48:30 (3 years ago)
Author:
ryan
Message:

Admin bar visibility prefs. Props duck_. see #15829

Location:
trunk
Files:
5 edited

Legend:

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

    r16660 r17032  
    119119        $user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; 
    120120        $user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh'; 
     121        $user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false'; 
     122        $user->show_admin_bar_admin = isset( $_POST['admin_bar_admin'] ) ? 'true' : 'false'; 
    121123    } 
    122124 
  • trunk/wp-admin/user-edit.php

    r16767 r17032  
    212212<td><label for="comment_shortcuts"><input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php if ( !empty($profileuser->comment_shortcuts) ) checked('true', $profileuser->comment_shortcuts); ?> /> <?php _e('Enable keyboard shortcuts for comment moderation.'); ?></label> <?php _e('<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>'); ?></td> 
    213213</tr> 
    214 <?php 
    215 endif; 
    216 do_action('personal_options', $profileuser); 
    217 ?> 
     214<?php endif; ?> 
     215<tr> 
     216<th scope="row"><?php _e('Admin Bar')?></th> 
     217<td><fieldset><legend class="screen-reader-text"><span><?php _e('Admin Bar') ?></span></legend> 
     218<label for="admin_bar_front"> 
     219<input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1" <?php checked( _get_admin_bar_pref( 'front', $profileuser->ID ) ); ?> /> 
     220<?php _e( 'Display the admin bar on the front end' ); ?></label><br /> 
     221<label for="admin_bar_admin"> 
     222<input name="admin_bar_admin" type="checkbox" id="admin_bar_admin" value="1" <?php checked( _get_admin_bar_pref( 'admin', $profileuser->ID ) ); ?> /> 
     223<?php _e( 'Display the admin bar in the dashboard' ); ?></label> 
     224</td> 
     225</tr> 
     226<?php do_action('personal_options', $profileuser); ?> 
    218227</table> 
    219228<?php 
  • 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?> 
  • trunk/wp-includes/functions.php

    r17022 r17032  
    44724472} 
    44734473 
    4474 /** 
    4475  * Set the display status of the admin bar 
    4476  * 
    4477  * This can be called immediately upon plugin load.  It does not need to be called from a function hooked to the init action. 
    4478  * 
    4479  * @since 3.1.0 
    4480  * 
    4481  * @param bool $show Whether to allow the admin bar to show. 
    4482  * @return void 
    4483  */ 
    4484 function show_admin_bar( $show ) { 
    4485     global $show_admin_bar; 
    4486     $show_admin_bar = (bool) $show; 
    4487      
    4488     // Remove the object if we are not going to be showing 
    4489     // Otherwise you have to call this function prior to the init hook for it to work! 
    4490     if ( ! $show_admin_bar && isset( $GLOBALS['wp_admin_bar'] ) ) 
    4491         $GLOBALS['wp_admin_bar'] = null; 
    4492 } 
    4493  
    44944474?> 
  • trunk/wp-includes/user.php

    r17024 r17032  
    508508            $ids = implode( ',', wp_parse_id_list( $qv['include'] ) ); 
    509509            $this->query_where .= " AND $wpdb->users.ID IN ($ids)"; 
    510         } 
    511         elseif ( !empty($qv['exclude']) ) { 
     510        } elseif ( !empty($qv['exclude']) ) { 
    512511            $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); 
    513512            $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)"; 
     
    14471446    if ( empty($user_registered) ) 
    14481447        $user_registered = gmdate('Y-m-d H:i:s'); 
     1448         
     1449    if ( empty($show_admin_bar_front) ) 
     1450        $show_admin_bar_front = 'true'; 
     1451             
     1452    if ( empty($show_admin_bar_admin) ) 
     1453        $show_admin_bar_admin = is_multisite() ? 'true' : 'false'; 
    14491454 
    14501455    $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login)); 
     
    14711476    } 
    14721477 
    1473     update_user_meta( $user_id, 'first_name', $first_name); 
    1474     update_user_meta( $user_id, 'last_name', $last_name); 
     1478    update_user_meta( $user_id, 'first_name', $first_name ); 
     1479    update_user_meta( $user_id, 'last_name', $last_name ); 
    14751480    update_user_meta( $user_id, 'nickname', $nickname ); 
    14761481    update_user_meta( $user_id, 'description', $description ); 
    1477     update_user_meta( $user_id, 'rich_editing', $rich_editing); 
    1478     update_user_meta( $user_id, 'comment_shortcuts', $comment_shortcuts); 
    1479     update_user_meta( $user_id, 'admin_color', $admin_color); 
    1480     update_user_meta( $user_id, 'use_ssl', $use_ssl); 
     1482    update_user_meta( $user_id, 'rich_editing', $rich_editing ); 
     1483    update_user_meta( $user_id, 'comment_shortcuts', $comment_shortcuts ); 
     1484    update_user_meta( $user_id, 'admin_color', $admin_color ); 
     1485    update_user_meta( $user_id, 'use_ssl', $use_ssl ); 
     1486    update_user_meta( $user_id, 'show_admin_bar_front', $show_admin_bar_front ); 
     1487    update_user_meta( $user_id, 'show_admin_bar_admin', $show_admin_bar_admin ); 
    14811488 
    14821489    $user = new WP_User($user_id); 
Note: See TracChangeset for help on using the changeset viewer.