WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/15/2015 04:07:14 AM (6 years ago)
Author:
wonderboymusic
Message:

Move WP_Screen to its own file.

See #33413.

File:
1 copied

Legend:

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

    r34167 r34169  
    11<?php
    22/**
    3  * WordPress Administration Screen API.
     3 * Screen API: WP_Screen class
    44 *
    55 * @package WordPress
    66 * @subpackage Administration
     7 * @since 4.4.0
    78 */
    8 
    9 /**
    10  * Get the column headers for a screen
    11  *
    12  * @since 2.7.0
    13  *
    14  * @staticvar array $column_headers
    15  *
    16  * @param string|WP_Screen $screen The screen you want the headers for
    17  * @return array Containing the headers in the format id => UI String
    18  */
    19 function get_column_headers( $screen ) {
    20     if ( is_string( $screen ) )
    21         $screen = convert_to_screen( $screen );
    22 
    23     static $column_headers = array();
    24 
    25     if ( ! isset( $column_headers[ $screen->id ] ) ) {
    26 
    27         /**
    28          * Filter the column headers for a list table on a specific screen.
    29          *
    30          * The dynamic portion of the hook name, `$screen->id`, refers to the
    31          * ID of a specific screen. For example, the screen ID for the Posts
    32          * list table is edit-post, so the filter for that screen would be
    33          * manage_edit-post_columns.
    34          *
    35          * @since 3.0.0
    36          *
    37          * @param array $columns An array of column headers. Default empty.
    38          */
    39         $column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
    40     }
    41 
    42     return $column_headers[ $screen->id ];
    43 }
    44 
    45 /**
    46  * Get a list of hidden columns.
    47  *
    48  * @since 2.7.0
    49  *
    50  * @param string|WP_Screen $screen The screen you want the hidden columns for
    51  * @return array
    52  */
    53 function get_hidden_columns( $screen ) {
    54     if ( is_string( $screen ) ) {
    55         $screen = convert_to_screen( $screen );
    56     }
    57 
    58     $hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
    59 
    60     if ( ! $hidden ) {
    61         $hidden = array();
    62 
    63         /**
    64          * Filter the default list of hidden columns.
    65          *
    66          * @since 4.4.0
    67          *
    68          * @param array     $hidden An array of columns hidden by default.
    69          * @param WP_Screen $screen WP_Screen object of the current screen.
    70          */
    71         $hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
    72     }
    73 
    74     /**
    75      * Filter the list of hidden columns.
    76      *
    77      * @since 4.4.0
    78      *
    79      * @param array     $hidden An array of hidden columns.
    80      * @param WP_Screen $screen WP_Screen object of the current screen.
    81      */
    82     return apply_filters( 'hidden_columns', $hidden, $screen );
    83 }
    84 
    85 /**
    86  * Prints the meta box preferences for screen meta.
    87  *
    88  * @since 2.7.0
    89  *
    90  * @global array $wp_meta_boxes
    91  *
    92  * @param WP_Screen $screen
    93  */
    94 function meta_box_prefs( $screen ) {
    95     global $wp_meta_boxes;
    96 
    97     if ( is_string( $screen ) )
    98         $screen = convert_to_screen( $screen );
    99 
    100     if ( empty($wp_meta_boxes[$screen->id]) )
    101         return;
    102 
    103     $hidden = get_hidden_meta_boxes($screen);
    104 
    105     foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
    106         foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
    107             if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
    108                 continue;
    109             }
    110             foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
    111                 if ( false == $box || ! $box['title'] )
    112                     continue;
    113                 // Submit box cannot be hidden
    114                 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
    115                     continue;
    116                 $box_id = $box['id'];
    117                 echo '<label for="' . $box_id . '-hide">';
    118                 echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
    119                 echo "{$box['title']}</label>\n";
    120             }
    121         }
    122     }
    123 }
    124 
    125 /**
    126  * Get Hidden Meta Boxes
    127  *
    128  * @since 2.7.0
    129  *
    130  * @param string|WP_Screen $screen Screen identifier
    131  * @return array Hidden Meta Boxes
    132  */
    133 function get_hidden_meta_boxes( $screen ) {
    134     if ( is_string( $screen ) )
    135         $screen = convert_to_screen( $screen );
    136 
    137     $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
    138 
    139     $use_defaults = ! is_array( $hidden );
    140 
    141     // Hide slug boxes by default
    142     if ( $use_defaults ) {
    143         $hidden = array();
    144         if ( 'post' == $screen->base ) {
    145             if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
    146                 $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
    147             else
    148                 $hidden = array( 'slugdiv' );
    149         }
    150 
    151         /**
    152          * Filter the default list of hidden meta boxes.
    153          *
    154          * @since 3.1.0
    155          *
    156          * @param array     $hidden An array of meta boxes hidden by default.
    157          * @param WP_Screen $screen WP_Screen object of the current screen.
    158          */
    159         $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
    160     }
    161 
    162     /**
    163      * Filter the list of hidden meta boxes.
    164      *
    165      * @since 3.3.0
    166      *
    167      * @param array     $hidden       An array of hidden meta boxes.
    168      * @param WP_Screen $screen       WP_Screen object of the current screen.
    169      * @param bool      $use_defaults Whether to show the default meta boxes.
    170      *                                Default true.
    171      */
    172     return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
    173 }
    174 
    175 /**
    176  * Register and configure an admin screen option
    177  *
    178  * @since 3.1.0
    179  *
    180  * @param string $option An option name.
    181  * @param mixed $args Option-dependent arguments.
    182  */
    183 function add_screen_option( $option, $args = array() ) {
    184     $current_screen = get_current_screen();
    185 
    186     if ( ! $current_screen )
    187         return;
    188 
    189     $current_screen->add_option( $option, $args );
    190 }
    191 
    192 /**
    193  * Get the current screen object
    194  *
    195  * @since 3.1.0
    196  *
    197  * @global WP_Screen $current_screen
    198  *
    199  * @return WP_Screen Current screen object
    200  */
    201 function get_current_screen() {
    202     global $current_screen;
    203 
    204     if ( ! isset( $current_screen ) )
    205         return null;
    206 
    207     return $current_screen;
    208 }
    209 
    210 /**
    211  * Set the current screen object
    212  *
    213  * @since 3.0.0
    214  *
    215  * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
    216  *                         or an existing screen object.
    217  */
    218 function set_current_screen( $hook_name = '' ) {
    219     WP_Screen::get( $hook_name )->set_current_screen();
    220 }
    2219
    22210/**
Note: See TracChangeset for help on using the changeset viewer.