Changeset 34169 for trunk/src/wp-admin/includes/class-wp-screen.php
- Timestamp:
- 09/15/2015 04:07:14 AM (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-screen.php
r34167 r34169 1 1 <?php 2 2 /** 3 * WordPress Administration Screen API.3 * Screen API: WP_Screen class 4 4 * 5 5 * @package WordPress 6 6 * @subpackage Administration 7 * @since 4.4.0 7 8 */ 8 9 /**10 * Get the column headers for a screen11 *12 * @since 2.7.013 *14 * @staticvar array $column_headers15 *16 * @param string|WP_Screen $screen The screen you want the headers for17 * @return array Containing the headers in the format id => UI String18 */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 the31 * ID of a specific screen. For example, the screen ID for the Posts32 * list table is edit-post, so the filter for that screen would be33 * manage_edit-post_columns.34 *35 * @since 3.0.036 *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.049 *50 * @param string|WP_Screen $screen The screen you want the hidden columns for51 * @return array52 */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.067 *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.078 *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.089 *90 * @global array $wp_meta_boxes91 *92 * @param WP_Screen $screen93 */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 hidden114 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 Boxes127 *128 * @since 2.7.0129 *130 * @param string|WP_Screen $screen Screen identifier131 * @return array Hidden Meta Boxes132 */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 default142 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 else148 $hidden = array( 'slugdiv' );149 }150 151 /**152 * Filter the default list of hidden meta boxes.153 *154 * @since 3.1.0155 *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.0166 *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 option177 *178 * @since 3.1.0179 *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 object194 *195 * @since 3.1.0196 *197 * @global WP_Screen $current_screen198 *199 * @return WP_Screen Current screen object200 */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 object212 *213 * @since 3.0.0214 *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 }221 9 222 10 /**
Note: See TracChangeset
for help on using the changeset viewer.