WordPress.org

Make WordPress Core

Changeset 19051


Ignore:
Timestamp:
10/24/11 06:40:15 (2 years ago)
Author:
nacin
Message:

screen.php tidying. Doc fixes and improvements. Improve logic in ::show_screen_options(). Remove regex in ::set_parentage(). Better variable names. Streamline get_screen_icon(). Whitespace. see #18785.

File:
1 edited

Legend:

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

    r19050 r19051  
    1212 * @since 2.7.0 
    1313 * 
    14  * @param string|object $screen The screen you want the headers for 
     14 * @param string|WP_Screen $screen The screen you want the headers for 
    1515 * @return array Containing the headers in the format id => UI String 
    1616 */ 
     
    3232 * @since 2.7.0 
    3333 * 
    34  * @param string|object $screen The screen you want the hidden columns for 
     34 * @param string|WP_Screen $screen The screen you want the hidden columns for 
    3535 * @return array 
    3636 */ 
     
    4343 
    4444/** 
    45  * {@internal Missing Short Description}} 
     45 * Prints the meta box preferences for screen meta. 
    4646 * 
    4747 * @since 2.7.0 
    4848 * 
    49  * @param unknown_type $screen 
     49 * @param string|WP_Screen $screen 
    5050 */ 
    5151function meta_box_prefs( $screen ) { 
    5252    global $wp_meta_boxes; 
    5353 
    54     if ( is_string($screen) ) 
    55         $screen = convert_to_screen($screen); 
     54    if ( is_string( $screen ) ) 
     55        $screen = convert_to_screen( $screen ); 
    5656 
    5757    if ( empty($wp_meta_boxes[$screen->id]) ) 
     
    8282 * @since 2.7.0 
    8383 * 
    84  * @param string|object $screen Screen identifier 
     84 * @param string|WP_Screen $screen Screen identifier 
    8585 * @return array Hidden Meta Boxes 
    8686 */ 
     
    113113 * @since 3.0.0 
    114114 * 
    115  * @param string $screen The name of the screen 
     115 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. 
    116116 * @return object An object containing the safe screen name and id 
    117117 */ 
    118 function convert_to_screen( $screen ) { 
    119     $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen); 
     118function convert_to_screen( $hook_suffix ) { 
     119    $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $hook_suffix); 
    120120 
    121121    if ( is_network_admin() ) 
     
    145145        $screen = convert_to_screen( $screen ); 
    146146 
    147     WP_Screen::add_old_compat_help( $screen->id, $help ); 
     147    WP_Screen::add_old_compat_help( $screen, $help ); 
    148148} 
    149149 
     
    166166} 
    167167 
     168/** 
     169 * Displays a screen icon. 
     170 * 
     171 * @uses get_screen_icon() 
     172 * @since 2.7.0 
     173 * 
     174 * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object) 
     175 *  which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID. 
     176 */ 
    168177function screen_icon( $screen = '' ) { 
    169178    echo get_screen_icon( $screen ); 
    170179} 
    171180 
     181/** 
     182 * Gets a screen icon. 
     183 * 
     184 * @since 3.2.0 
     185 * 
     186 * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object) 
     187 *  which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID. 
     188 * @return string HTML for the screen icon. 
     189 */ 
    172190function get_screen_icon( $screen = '' ) { 
    173     global $current_screen, $typenow; 
    174  
    175     if ( empty($screen) ) 
    176         $screen = $current_screen; 
    177     elseif ( is_string($screen) ) 
    178         $name = $screen; 
     191    if ( empty( $screen ) ) 
     192        $screen = get_current_screen(); 
     193    elseif ( is_string( $screen ) ) 
     194        $icon_id = $screen; 
    179195 
    180196    $class = 'icon32'; 
    181197 
    182     if ( empty($name) ) { 
    183         if ( !empty($screen->parent_base) ) 
    184             $name = $screen->parent_base; 
     198    if ( empty( $icon_id ) ) { 
     199        if ( ! empty( $screen->parent_base ) ) 
     200            $icon_id = $screen->parent_base; 
    185201        else 
    186             $name = $screen->base; 
    187  
    188         if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type ) 
    189             $name = 'edit-pages'; 
    190  
    191         $post_type = ''; 
    192         if ( isset( $screen->post_type ) ) 
    193             $post_type = $screen->post_type; 
    194         elseif ( $current_screen == $screen ) 
    195             $post_type = $typenow; 
    196         if ( $post_type ) 
    197             $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type ); 
    198     } 
    199  
    200     return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>'; 
    201 } 
    202  
    203 /** 
    204  *  Get the current screen object 
    205  * 
    206  *  @since 3.1.0 
     202            $icon_id = $screen->base; 
     203 
     204        if ( ! empty( $screen->post_type ) && 'page' == $screen->post_type ) 
     205            $icon_id = 'edit-pages'; 
     206 
     207        if ( ! empty( $screen->post_type ) ) 
     208            $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type ); 
     209    } 
     210 
     211    return '<div id="icon-' . esc_attr( $icon_id ) . '" class="' . $class . '"><br /></div>'; 
     212} 
     213 
     214/** 
     215 * Get the current screen object 
     216 * 
     217 * @since 3.1.0 
    207218 * 
    208219 * @return object Current screen object 
     
    211222    global $current_screen; 
    212223 
    213     if ( !isset($current_screen) ) 
     224    if ( ! isset( $current_screen ) ) 
    214225        return null; 
    215226 
     
    221232 * 
    222233 * @since 3.0.0 
    223  * 
    224234 * @uses $current_screen 
    225235 * 
    226  * @param string $id Screen id, optional. 
    227  */ 
    228 function set_current_screen( $id =  '' ) { 
     236 * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. 
     237 */ 
     238function set_current_screen( $hook_name =  '' ) { 
    229239    global $current_screen; 
    230240 
    231     $current_screen = new WP_Screen( $id ); 
     241    $current_screen = new WP_Screen( $hook_name ); 
    232242 
    233243    $current_screen = apply_filters('current_screen', $current_screen); 
     
    235245 
    236246/** 
    237  * A class representing the current admin screen. 
     247 * A class representing the admin screen. 
    238248 * 
    239249 * @since 3.3.0 
     
    242252final class WP_Screen { 
    243253    /** 
    244      * Any action associated with the screen.  'add' for *-add.php and *-new.php screens.  Empty otherwise. 
     254     * Any action associated with the screen. 'add' for *-add.php and *-new.php screens.  Empty otherwise. 
    245255     * 
    246256     * @since 3.3.0 
     
    454464    } 
    455465 
     466    /** 
     467     * Sets the old string-based contextual help for the screen. 
     468     * 
     469     * For backwards compatibility. 
     470     * 
     471     * @since 3.3.0 
     472     * 
     473     * @param WP_Screen $screen A screen object. 
     474     * @param string $help Help text. 
     475     */ 
    456476    static function add_old_compat_help( $screen, $help ) { 
    457         self::$_old_compat_help[ $screen ] = $help;  
     477        self::$_old_compat_help[ $screen->id ] = $help;  
    458478    } 
    459479 
     
    468488    function set_parentage( $parent_file ) { 
    469489        $this->parent_file = $parent_file; 
    470         $this->parent_base = preg_replace('/\?.*$/', '', $parent_file); 
    471         $this->parent_base = str_replace('.php', '', $this->parent_base); 
     490        list( $this->parent_base ) = explode( '?', $parent_file ); 
     491        $this->parent_base = str_replace( '.php', '', $this->parent_base ); 
    472492    } 
    473493 
     
    490510     * @since 3.3.0 
    491511     * 
    492      * @param string  
     512     * @param string 
    493513     */ 
    494514    public function get_option( $option, $key = false ) { 
     
    641661 
    642662    public function show_screen_options() { 
    643         global $wp_meta_boxes, $wp_list_table; 
     663        global $wp_meta_boxes; 
    644664 
    645665        if ( is_bool( $this->_show_screen_options ) ) 
     
    648668        $columns = get_column_headers( $this ); 
    649669 
    650         $show_screen = false; 
    651         if ( ! empty( $wp_meta_boxes[ $this->id ] ) || ! empty( $columns ) ) 
    652             $show_screen = true; 
    653  
    654         // Check if there are per-page options. 
    655         $show_screen = $show_screen || $this->get_option('per_page'); 
     670        $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' ); 
    656671 
    657672        $this->_screen_settings = apply_filters( 'screen_settings', '', $this ); 
     
    660675            case 'widgets': 
    661676                $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n"; 
    662                 $show_screen = true; 
    663677                break; 
    664678        } 
    665679 
    666         if ( ! empty( $this->_screen_settings ) ) 
    667             $show_screen = true; 
    668  
    669         if ( ! empty( self::$_options[ $this->id ] ) ) 
     680        if ( $this->_screen_settings || self::$_options[ $this->id ] ) 
    670681            $show_screen = true; 
    671682 
Note: See TracChangeset for help on using the changeset viewer.