author | ymh <ymh.work@gmail.com> |
Tue, 15 Oct 2019 15:48:13 +0200 | |
changeset 13 | d255fe9cd479 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @staticvar array $column_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
0 | 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 ) { |
|
9 | 20 |
if ( is_string( $screen ) ) { |
0 | 21 |
$screen = convert_to_screen( $screen ); |
9 | 22 |
} |
0 | 23 |
|
24 |
static $column_headers = array(); |
|
25 |
||
5 | 26 |
if ( ! isset( $column_headers[ $screen->id ] ) ) { |
27 |
||
28 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
* Filters the column headers for a list table on a specific screen. |
5 | 30 |
* |
31 |
* The dynamic portion of the hook name, `$screen->id`, refers to the |
|
32 |
* ID of a specific screen. For example, the screen ID for the Posts |
|
33 |
* list table is edit-post, so the filter for that screen would be |
|
34 |
* manage_edit-post_columns. |
|
35 |
* |
|
36 |
* @since 3.0.0 |
|
37 |
* |
|
38 |
* @param array $columns An array of column headers. Default empty. |
|
39 |
*/ |
|
40 |
$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() ); |
|
41 |
} |
|
0 | 42 |
|
43 |
return $column_headers[ $screen->id ]; |
|
44 |
} |
|
45 |
||
46 |
/** |
|
47 |
* Get a list of hidden columns. |
|
48 |
* |
|
49 |
* @since 2.7.0 |
|
50 |
* |
|
51 |
* @param string|WP_Screen $screen The screen you want the hidden columns for |
|
52 |
* @return array |
|
53 |
*/ |
|
54 |
function get_hidden_columns( $screen ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
if ( is_string( $screen ) ) { |
0 | 56 |
$screen = convert_to_screen( $screen ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
} |
0 | 58 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
$hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
$use_defaults = ! is_array( $hidden ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
if ( $use_defaults ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
$hidden = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* Filters the default list of hidden columns. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* @param array $hidden An array of columns hidden by default. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
$hidden = apply_filters( 'default_hidden_columns', $hidden, $screen ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
* Filters the list of hidden columns. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* @since 4.4.1 Added the `use_defaults` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* @param array $hidden An array of hidden columns. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* @param bool $use_defaults Whether to show the default columns. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults ); |
0 | 88 |
} |
89 |
||
90 |
/** |
|
91 |
* Prints the meta box preferences for screen meta. |
|
92 |
* |
|
93 |
* @since 2.7.0 |
|
94 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
* @global array $wp_meta_boxes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
* |
5 | 97 |
* @param WP_Screen $screen |
0 | 98 |
*/ |
99 |
function meta_box_prefs( $screen ) { |
|
100 |
global $wp_meta_boxes; |
|
101 |
||
9 | 102 |
if ( is_string( $screen ) ) { |
0 | 103 |
$screen = convert_to_screen( $screen ); |
9 | 104 |
} |
0 | 105 |
|
9 | 106 |
if ( empty( $wp_meta_boxes[ $screen->id ] ) ) { |
0 | 107 |
return; |
9 | 108 |
} |
0 | 109 |
|
9 | 110 |
$hidden = get_hidden_meta_boxes( $screen ); |
0 | 111 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) { |
9 | 118 |
if ( false == $box || ! $box['title'] ) { |
0 | 119 |
continue; |
9 | 120 |
} |
0 | 121 |
// Submit box cannot be hidden |
9 | 122 |
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) { |
0 | 123 |
continue; |
9 | 124 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
$widget_title = $box['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
$widget_title = $box['args']['__widget_basename']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
'<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>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
esc_attr( $box['id'] ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
checked( in_array( $box['id'], $hidden ), false, false ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
$widget_title |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
); |
0 | 138 |
} |
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Get Hidden Meta Boxes |
|
145 |
* |
|
146 |
* @since 2.7.0 |
|
147 |
* |
|
148 |
* @param string|WP_Screen $screen Screen identifier |
|
149 |
* @return array Hidden Meta Boxes |
|
150 |
*/ |
|
151 |
function get_hidden_meta_boxes( $screen ) { |
|
9 | 152 |
if ( is_string( $screen ) ) { |
0 | 153 |
$screen = convert_to_screen( $screen ); |
9 | 154 |
} |
0 | 155 |
|
156 |
$hidden = get_user_option( "metaboxhidden_{$screen->id}" ); |
|
157 |
||
158 |
$use_defaults = ! is_array( $hidden ); |
|
159 |
||
160 |
// Hide slug boxes by default |
|
161 |
if ( $use_defaults ) { |
|
162 |
$hidden = array(); |
|
163 |
if ( 'post' == $screen->base ) { |
|
9 | 164 |
if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) { |
165 |
$hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' ); |
|
166 |
} else { |
|
0 | 167 |
$hidden = array( 'slugdiv' ); |
9 | 168 |
} |
0 | 169 |
} |
5 | 170 |
|
171 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
* Filters the default list of hidden meta boxes. |
5 | 173 |
* |
174 |
* @since 3.1.0 |
|
175 |
* |
|
176 |
* @param array $hidden An array of meta boxes hidden by default. |
|
177 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
|
178 |
*/ |
|
0 | 179 |
$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen ); |
180 |
} |
|
181 |
||
5 | 182 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* Filters the list of hidden meta boxes. |
5 | 184 |
* |
185 |
* @since 3.3.0 |
|
186 |
* |
|
187 |
* @param array $hidden An array of hidden meta boxes. |
|
188 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
|
189 |
* @param bool $use_defaults Whether to show the default meta boxes. |
|
190 |
* Default true. |
|
191 |
*/ |
|
0 | 192 |
return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults ); |
193 |
} |
|
194 |
||
195 |
/** |
|
196 |
* Register and configure an admin screen option |
|
197 |
* |
|
198 |
* @since 3.1.0 |
|
199 |
* |
|
200 |
* @param string $option An option name. |
|
201 |
* @param mixed $args Option-dependent arguments. |
|
202 |
*/ |
|
203 |
function add_screen_option( $option, $args = array() ) { |
|
204 |
$current_screen = get_current_screen(); |
|
205 |
||
9 | 206 |
if ( ! $current_screen ) { |
0 | 207 |
return; |
9 | 208 |
} |
0 | 209 |
|
210 |
$current_screen->add_option( $option, $args ); |
|
211 |
} |
|
212 |
||
213 |
/** |
|
214 |
* Get the current screen object |
|
215 |
* |
|
216 |
* @since 3.1.0 |
|
217 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
* @global WP_Screen $current_screen |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
* @return WP_Screen|null Current screen object or null when screen not defined. |
0 | 221 |
*/ |
222 |
function get_current_screen() { |
|
223 |
global $current_screen; |
|
224 |
||
9 | 225 |
if ( ! isset( $current_screen ) ) { |
0 | 226 |
return null; |
9 | 227 |
} |
0 | 228 |
|
229 |
return $current_screen; |
|
230 |
} |
|
231 |
||
232 |
/** |
|
233 |
* Set the current screen object |
|
234 |
* |
|
235 |
* @since 3.0.0 |
|
236 |
* |
|
237 |
* @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, |
|
9 | 238 |
* or an existing screen object. |
0 | 239 |
*/ |
240 |
function set_current_screen( $hook_name = '' ) { |
|
241 |
WP_Screen::get( $hook_name )->set_current_screen(); |
|
242 |
} |