[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Administration Screen API. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** 10 * Get the column headers for a screen 11 * 12 * @since 2.7.0 13 * 14 * @param string|WP_Screen $screen The screen you want the headers for 15 * @return string[] The column header labels keyed by column ID. 16 */ 17 function get_column_headers( $screen ) { 18 static $column_headers = array(); 19 20 if ( is_string( $screen ) ) { 21 $screen = convert_to_screen( $screen ); 22 } 23 24 if ( ! isset( $column_headers[ $screen->id ] ) ) { 25 /** 26 * Filters the column headers for a list table on a specific screen. 27 * 28 * The dynamic portion of the hook name, `$screen->id`, refers to the 29 * ID of a specific screen. For example, the screen ID for the Posts 30 * list table is edit-post, so the filter for that screen would be 31 * manage_edit-post_columns. 32 * 33 * @since 3.0.0 34 * 35 * @param string[] $columns The column header labels keyed by column ID. 36 */ 37 $column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() ); 38 } 39 40 return $column_headers[ $screen->id ]; 41 } 42 43 /** 44 * Get a list of hidden columns. 45 * 46 * @since 2.7.0 47 * 48 * @param string|WP_Screen $screen The screen you want the hidden columns for 49 * @return string[] Array of IDs of hidden columns. 50 */ 51 function get_hidden_columns( $screen ) { 52 if ( is_string( $screen ) ) { 53 $screen = convert_to_screen( $screen ); 54 } 55 56 $hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' ); 57 58 $use_defaults = ! is_array( $hidden ); 59 60 if ( $use_defaults ) { 61 $hidden = array(); 62 63 /** 64 * Filters the default list of hidden columns. 65 * 66 * @since 4.4.0 67 * 68 * @param string[] $hidden Array of IDs 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 * Filters the list of hidden columns. 76 * 77 * @since 4.4.0 78 * @since 4.4.1 Added the `use_defaults` parameter. 79 * 80 * @param string[] $hidden Array of IDs of hidden columns. 81 * @param WP_Screen $screen WP_Screen object of the current screen. 82 * @param bool $use_defaults Whether to show the default columns. 83 */ 84 return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults ); 85 } 86 87 /** 88 * Prints the meta box preferences for screen meta. 89 * 90 * @since 2.7.0 91 * 92 * @global array $wp_meta_boxes Global meta box state. 93 * 94 * @param WP_Screen $screen 95 */ 96 function meta_box_prefs( $screen ) { 97 global $wp_meta_boxes; 98 99 if ( is_string( $screen ) ) { 100 $screen = convert_to_screen( $screen ); 101 } 102 103 if ( empty( $wp_meta_boxes[ $screen->id ] ) ) { 104 return; 105 } 106 107 $hidden = get_hidden_meta_boxes( $screen ); 108 109 foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) { 110 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { 111 if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) { 112 continue; 113 } 114 115 foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) { 116 if ( false === $box || ! $box['title'] ) { 117 continue; 118 } 119 120 // Submit box cannot be hidden. 121 if ( 'submitdiv' === $box['id'] || 'linksubmitdiv' === $box['id'] ) { 122 continue; 123 } 124 125 $widget_title = $box['title']; 126 127 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { 128 $widget_title = $box['args']['__widget_basename']; 129 } 130 131 $is_hidden = in_array( $box['id'], $hidden, true ); 132 133 printf( 134 '<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>', 135 esc_attr( $box['id'] ), 136 checked( $is_hidden, false, false ), 137 $widget_title 138 ); 139 } 140 } 141 } 142 } 143 144 /** 145 * Gets an array of IDs of hidden meta boxes. 146 * 147 * @since 2.7.0 148 * 149 * @param string|WP_Screen $screen Screen identifier 150 * @return string[] IDs of hidden meta boxes. 151 */ 152 function get_hidden_meta_boxes( $screen ) { 153 if ( is_string( $screen ) ) { 154 $screen = convert_to_screen( $screen ); 155 } 156 157 $hidden = get_user_option( "metaboxhidden_{$screen->id}" ); 158 159 $use_defaults = ! is_array( $hidden ); 160 161 // Hide slug boxes by default. 162 if ( $use_defaults ) { 163 $hidden = array(); 164 165 if ( 'post' === $screen->base ) { 166 if ( in_array( $screen->post_type, array( 'post', 'page', 'attachment' ), true ) ) { 167 $hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' ); 168 } else { 169 $hidden = array( 'slugdiv' ); 170 } 171 } 172 173 /** 174 * Filters the default list of hidden meta boxes. 175 * 176 * @since 3.1.0 177 * 178 * @param string[] $hidden An array of IDs of meta boxes hidden by default. 179 * @param WP_Screen $screen WP_Screen object of the current screen. 180 */ 181 $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen ); 182 } 183 184 /** 185 * Filters the list of hidden meta boxes. 186 * 187 * @since 3.3.0 188 * 189 * @param string[] $hidden An array of IDs of hidden meta boxes. 190 * @param WP_Screen $screen WP_Screen object of the current screen. 191 * @param bool $use_defaults Whether to show the default meta boxes. 192 * Default true. 193 */ 194 return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults ); 195 } 196 197 /** 198 * Register and configure an admin screen option 199 * 200 * @since 3.1.0 201 * 202 * @param string $option An option name. 203 * @param mixed $args Option-dependent arguments. 204 */ 205 function add_screen_option( $option, $args = array() ) { 206 $current_screen = get_current_screen(); 207 208 if ( ! $current_screen ) { 209 return; 210 } 211 212 $current_screen->add_option( $option, $args ); 213 } 214 215 /** 216 * Get the current screen object 217 * 218 * @since 3.1.0 219 * 220 * @global WP_Screen $current_screen WordPress current screen object. 221 * 222 * @return WP_Screen|null Current screen object or null when screen not defined. 223 */ 224 function get_current_screen() { 225 global $current_screen; 226 227 if ( ! isset( $current_screen ) ) { 228 return null; 229 } 230 231 return $current_screen; 232 } 233 234 /** 235 * Set the current screen object 236 * 237 * @since 3.0.0 238 * 239 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, 240 * or an existing screen object. 241 */ 242 function set_current_screen( $hook_name = '' ) { 243 WP_Screen::get( $hook_name )->set_current_screen(); 244 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |