author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Toolbar API: Top-level Toolbar functionality |
0 | 4 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Toolbar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.1.0 |
0 | 8 |
*/ |
9 |
||
10 |
/** |
|
11 |
* Instantiate the admin bar object and set it up as a global for access elsewhere. |
|
12 |
* |
|
13 |
* UNHOOKING THIS FUNCTION WILL NOT PROPERLY REMOVE THE ADMIN BAR. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* For that, use show_admin_bar(false) or the {@see 'show_admin_bar'} filter. |
0 | 15 |
* |
16 |
* @since 3.1.0 |
|
17 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @global WP_Admin_Bar $wp_admin_bar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
0 | 21 |
* @return bool Whether the admin bar was successfully initialized. |
22 |
*/ |
|
23 |
function _wp_admin_bar_init() { |
|
24 |
global $wp_admin_bar; |
|
25 |
||
9 | 26 |
if ( ! is_admin_bar_showing() ) { |
0 | 27 |
return false; |
9 | 28 |
} |
0 | 29 |
|
30 |
/* Load the admin bar class code ready for instantiation */ |
|
16 | 31 |
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; |
0 | 32 |
|
33 |
/* Instantiate the admin bar */ |
|
5 | 34 |
|
35 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* Filters the admin bar class to instantiate. |
5 | 37 |
* |
38 |
* @since 3.1.0 |
|
39 |
* |
|
40 |
* @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'. |
|
41 |
*/ |
|
0 | 42 |
$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); |
9 | 43 |
if ( class_exists( $admin_bar_class ) ) { |
0 | 44 |
$wp_admin_bar = new $admin_bar_class; |
9 | 45 |
} else { |
0 | 46 |
return false; |
9 | 47 |
} |
0 | 48 |
|
49 |
$wp_admin_bar->initialize(); |
|
50 |
$wp_admin_bar->add_menus(); |
|
51 |
||
52 |
return true; |
|
53 |
} |
|
54 |
||
55 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* Renders the admin bar to the page based on the $wp_admin_bar->menu member var. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* |
16 | 58 |
* This is called very early on the {@see 'wp_body_open'} action so that it will render |
59 |
* before anything else being added to the page body. |
|
60 |
* |
|
61 |
* For backward compatibility with themes not using the 'wp_body_open' action, |
|
62 |
* the function is also called late on {@see 'wp_footer'}. |
|
0 | 63 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* It includes the {@see 'admin_bar_menu'} action which should be used to hook in and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* add new menus to the admin bar. That way you can be sure that you are adding at most |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* optimal point, right before the admin bar is rendered. This also gives you access to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* the `$post` global, among others. |
0 | 68 |
* |
69 |
* @since 3.1.0 |
|
16 | 70 |
* @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* @global WP_Admin_Bar $wp_admin_bar |
0 | 73 |
*/ |
74 |
function wp_admin_bar_render() { |
|
75 |
global $wp_admin_bar; |
|
16 | 76 |
static $rendered = false; |
77 |
||
78 |
if ( $rendered ) { |
|
79 |
return; |
|
80 |
} |
|
0 | 81 |
|
9 | 82 |
if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
return; |
9 | 84 |
} |
0 | 85 |
|
5 | 86 |
/** |
87 |
* Load all necessary admin bar items. |
|
88 |
* |
|
89 |
* This is the hook used to add, remove, or manipulate admin bar items. |
|
90 |
* |
|
91 |
* @since 3.1.0 |
|
92 |
* |
|
93 |
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference |
|
94 |
*/ |
|
0 | 95 |
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); |
96 |
||
5 | 97 |
/** |
98 |
* Fires before the admin bar is rendered. |
|
99 |
* |
|
100 |
* @since 3.1.0 |
|
101 |
*/ |
|
0 | 102 |
do_action( 'wp_before_admin_bar_render' ); |
103 |
||
104 |
$wp_admin_bar->render(); |
|
105 |
||
5 | 106 |
/** |
107 |
* Fires after the admin bar is rendered. |
|
108 |
* |
|
109 |
* @since 3.1.0 |
|
110 |
*/ |
|
0 | 111 |
do_action( 'wp_after_admin_bar_render' ); |
16 | 112 |
|
113 |
$rendered = true; |
|
0 | 114 |
} |
115 |
||
116 |
/** |
|
117 |
* Add the WordPress logo menu. |
|
118 |
* |
|
119 |
* @since 3.3.0 |
|
120 |
* |
|
121 |
* @param WP_Admin_Bar $wp_admin_bar |
|
122 |
*/ |
|
123 |
function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
if ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
$about_url = self_admin_url( 'about.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
} elseif ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
$about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
$about_url = false; |
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 |
$wp_logo_menu_args = array( |
0 | 133 |
'id' => 'wp-logo', |
18 | 134 |
'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
'href' => $about_url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
); |
0 | 137 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
// Set tabindex="0" to make sub menus accessible when no URL is available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
if ( ! $about_url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
$wp_logo_menu_args['meta'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
'tabindex' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
|
16 | 145 |
$wp_admin_bar->add_node( $wp_logo_menu_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
if ( $about_url ) { |
16 | 148 |
// Add "About WordPress" link. |
149 |
$wp_admin_bar->add_node( |
|
9 | 150 |
array( |
151 |
'parent' => 'wp-logo', |
|
152 |
'id' => 'about', |
|
153 |
'title' => __( 'About WordPress' ), |
|
154 |
'href' => $about_url, |
|
155 |
) |
|
156 |
); |
|
0 | 157 |
} |
158 |
||
16 | 159 |
// Add WordPress.org link. |
160 |
$wp_admin_bar->add_node( |
|
9 | 161 |
array( |
162 |
'parent' => 'wp-logo-external', |
|
163 |
'id' => 'wporg', |
|
164 |
'title' => __( 'WordPress.org' ), |
|
165 |
'href' => __( 'https://wordpress.org/' ), |
|
166 |
) |
|
167 |
); |
|
0 | 168 |
|
18 | 169 |
// Add documentation link. |
16 | 170 |
$wp_admin_bar->add_node( |
9 | 171 |
array( |
172 |
'parent' => 'wp-logo-external', |
|
173 |
'id' => 'documentation', |
|
174 |
'title' => __( 'Documentation' ), |
|
18 | 175 |
'href' => __( 'https://wordpress.org/support/' ), |
9 | 176 |
) |
177 |
); |
|
0 | 178 |
|
16 | 179 |
// Add forums link. |
180 |
$wp_admin_bar->add_node( |
|
9 | 181 |
array( |
182 |
'parent' => 'wp-logo-external', |
|
183 |
'id' => 'support-forums', |
|
184 |
'title' => __( 'Support' ), |
|
18 | 185 |
'href' => __( 'https://wordpress.org/support/forums/' ), |
9 | 186 |
) |
187 |
); |
|
0 | 188 |
|
16 | 189 |
// Add feedback link. |
190 |
$wp_admin_bar->add_node( |
|
9 | 191 |
array( |
192 |
'parent' => 'wp-logo-external', |
|
193 |
'id' => 'feedback', |
|
194 |
'title' => __( 'Feedback' ), |
|
195 |
'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), |
|
196 |
) |
|
197 |
); |
|
0 | 198 |
} |
199 |
||
200 |
/** |
|
5 | 201 |
* Add the sidebar toggle button. |
202 |
* |
|
203 |
* @since 3.8.0 |
|
204 |
* |
|
205 |
* @param WP_Admin_Bar $wp_admin_bar |
|
206 |
*/ |
|
207 |
function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { |
|
208 |
if ( is_admin() ) { |
|
16 | 209 |
$wp_admin_bar->add_node( |
9 | 210 |
array( |
211 |
'id' => 'menu-toggle', |
|
18 | 212 |
'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>', |
9 | 213 |
'href' => '#', |
214 |
) |
|
215 |
); |
|
5 | 216 |
} |
217 |
} |
|
218 |
||
219 |
/** |
|
0 | 220 |
* Add the "My Account" item. |
221 |
* |
|
222 |
* @since 3.3.0 |
|
223 |
* |
|
224 |
* @param WP_Admin_Bar $wp_admin_bar |
|
225 |
*/ |
|
226 |
function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
|
227 |
$user_id = get_current_user_id(); |
|
228 |
$current_user = wp_get_current_user(); |
|
229 |
||
9 | 230 |
if ( ! $user_id ) { |
0 | 231 |
return; |
9 | 232 |
} |
0 | 233 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
if ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
$profile_url = get_edit_profile_url( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
} elseif ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
$profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
$profile_url = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
|
5 | 242 |
$avatar = get_avatar( $user_id, 26 ); |
16 | 243 |
/* translators: %s: Current user's display name. */ |
9 | 244 |
$howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); |
245 |
$class = empty( $avatar ) ? '' : 'with-avatar'; |
|
0 | 246 |
|
16 | 247 |
$wp_admin_bar->add_node( |
9 | 248 |
array( |
249 |
'id' => 'my-account', |
|
250 |
'parent' => 'top-secondary', |
|
251 |
'title' => $howdy . $avatar, |
|
252 |
'href' => $profile_url, |
|
253 |
'meta' => array( |
|
254 |
'class' => $class, |
|
255 |
), |
|
256 |
) |
|
257 |
); |
|
0 | 258 |
} |
259 |
||
260 |
/** |
|
261 |
* Add the "My Account" submenu items. |
|
262 |
* |
|
263 |
* @since 3.1.0 |
|
264 |
* |
|
265 |
* @param WP_Admin_Bar $wp_admin_bar |
|
266 |
*/ |
|
267 |
function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
|
268 |
$user_id = get_current_user_id(); |
|
269 |
$current_user = wp_get_current_user(); |
|
270 |
||
9 | 271 |
if ( ! $user_id ) { |
0 | 272 |
return; |
9 | 273 |
} |
0 | 274 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
if ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
$profile_url = get_edit_profile_url( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
} elseif ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
$profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
$profile_url = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
|
9 | 283 |
$wp_admin_bar->add_group( |
284 |
array( |
|
285 |
'parent' => 'my-account', |
|
286 |
'id' => 'user-actions', |
|
287 |
) |
|
288 |
); |
|
0 | 289 |
|
290 |
$user_info = get_avatar( $user_id, 64 ); |
|
291 |
$user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; |
|
292 |
||
9 | 293 |
if ( $current_user->display_name !== $current_user->user_login ) { |
0 | 294 |
$user_info .= "<span class='username'>{$current_user->user_login}</span>"; |
9 | 295 |
} |
0 | 296 |
|
16 | 297 |
$wp_admin_bar->add_node( |
9 | 298 |
array( |
299 |
'parent' => 'user-actions', |
|
300 |
'id' => 'user-info', |
|
301 |
'title' => $user_info, |
|
302 |
'href' => $profile_url, |
|
303 |
'meta' => array( |
|
304 |
'tabindex' => -1, |
|
305 |
), |
|
306 |
) |
|
307 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
if ( false !== $profile_url ) { |
16 | 310 |
$wp_admin_bar->add_node( |
9 | 311 |
array( |
312 |
'parent' => 'user-actions', |
|
313 |
'id' => 'edit-profile', |
|
16 | 314 |
'title' => __( 'Edit Profile' ), |
9 | 315 |
'href' => $profile_url, |
316 |
) |
|
317 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
|
16 | 320 |
$wp_admin_bar->add_node( |
9 | 321 |
array( |
322 |
'parent' => 'user-actions', |
|
323 |
'id' => 'logout', |
|
324 |
'title' => __( 'Log Out' ), |
|
325 |
'href' => wp_logout_url(), |
|
326 |
) |
|
327 |
); |
|
0 | 328 |
} |
329 |
||
330 |
/** |
|
331 |
* Add the "Site Name" menu. |
|
332 |
* |
|
333 |
* @since 3.3.0 |
|
334 |
* |
|
335 |
* @param WP_Admin_Bar $wp_admin_bar |
|
336 |
*/ |
|
337 |
function wp_admin_bar_site_menu( $wp_admin_bar ) { |
|
338 |
// Don't show for logged out users. |
|
9 | 339 |
if ( ! is_user_logged_in() ) { |
0 | 340 |
return; |
9 | 341 |
} |
0 | 342 |
|
343 |
// Show only when the user is a member of this site, or they're a super admin. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) { |
0 | 345 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
} |
0 | 347 |
|
9 | 348 |
$blogname = get_bloginfo( 'name' ); |
0 | 349 |
|
5 | 350 |
if ( ! $blogname ) { |
0 | 351 |
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
5 | 352 |
} |
0 | 353 |
|
354 |
if ( is_network_admin() ) { |
|
16 | 355 |
/* translators: %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
$blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); |
0 | 357 |
} elseif ( is_user_admin() ) { |
16 | 358 |
/* translators: %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
$blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
0 | 360 |
} |
361 |
||
362 |
$title = wp_html_excerpt( $blogname, 40, '…' ); |
|
363 |
||
16 | 364 |
$wp_admin_bar->add_node( |
9 | 365 |
array( |
366 |
'id' => 'site-name', |
|
367 |
'title' => $title, |
|
368 |
'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
|
369 |
) |
|
370 |
); |
|
0 | 371 |
|
372 |
// Create submenu items. |
|
373 |
||
374 |
if ( is_admin() ) { |
|
375 |
// Add an option to visit the site. |
|
16 | 376 |
$wp_admin_bar->add_node( |
9 | 377 |
array( |
378 |
'parent' => 'site-name', |
|
379 |
'id' => 'view-site', |
|
380 |
'title' => __( 'Visit Site' ), |
|
381 |
'href' => home_url( '/' ), |
|
382 |
) |
|
383 |
); |
|
0 | 384 |
|
385 |
if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
|
16 | 386 |
$wp_admin_bar->add_node( |
9 | 387 |
array( |
388 |
'parent' => 'site-name', |
|
389 |
'id' => 'edit-site', |
|
390 |
'title' => __( 'Edit Site' ), |
|
391 |
'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), |
|
392 |
) |
|
393 |
); |
|
0 | 394 |
} |
9 | 395 |
} elseif ( current_user_can( 'read' ) ) { |
0 | 396 |
// We're on the front end, link to the Dashboard. |
16 | 397 |
$wp_admin_bar->add_node( |
9 | 398 |
array( |
399 |
'parent' => 'site-name', |
|
400 |
'id' => 'dashboard', |
|
401 |
'title' => __( 'Dashboard' ), |
|
402 |
'href' => admin_url(), |
|
403 |
) |
|
404 |
); |
|
0 | 405 |
|
406 |
// Add the appearance submenu items. |
|
407 |
wp_admin_bar_appearance_menu( $wp_admin_bar ); |
|
408 |
} |
|
409 |
} |
|
410 |
||
411 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
* Adds the "Customize" link to the Toolbar. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
* @global WP_Customize_Manager $wp_customize |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
function wp_admin_bar_customize_menu( $wp_admin_bar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
global $wp_customize; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
// Don't show for users who can't access the customizer or when in the admin. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
if ( ! current_user_can( 'customize' ) || is_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
// Don't show if the user cannot edit a given customize_changeset post currently being previewed. |
16 | 428 |
if ( is_customize_preview() && $wp_customize->changeset_post_id() |
429 |
&& ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) |
|
430 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
if ( is_customize_preview() && $wp_customize->changeset_uuid() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
$current_url = remove_query_arg( 'customize_changeset_uuid', $current_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
$customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
if ( is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
$customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
|
16 | 444 |
$wp_admin_bar->add_node( |
9 | 445 |
array( |
446 |
'id' => 'customize', |
|
447 |
'title' => __( 'Customize' ), |
|
448 |
'href' => $customize_url, |
|
449 |
'meta' => array( |
|
450 |
'class' => 'hide-if-no-customize', |
|
451 |
), |
|
452 |
) |
|
453 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
/** |
0 | 458 |
* Add the "My Sites/[Site Name]" menu and all submenus. |
459 |
* |
|
460 |
* @since 3.1.0 |
|
461 |
* |
|
462 |
* @param WP_Admin_Bar $wp_admin_bar |
|
463 |
*/ |
|
464 |
function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { |
|
465 |
// Don't show for logged out users or single site mode. |
|
9 | 466 |
if ( ! is_user_logged_in() || ! is_multisite() ) { |
0 | 467 |
return; |
9 | 468 |
} |
0 | 469 |
|
470 |
// Show only when the user has at least one site, or they're a super admin. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
if ( count( $wp_admin_bar->user->blogs ) < 1 && ! current_user_can( 'manage_network' ) ) { |
0 | 472 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
} |
0 | 474 |
|
5 | 475 |
if ( $wp_admin_bar->user->active_blog ) { |
476 |
$my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' ); |
|
477 |
} else { |
|
478 |
$my_sites_url = admin_url( 'my-sites.php' ); |
|
479 |
} |
|
480 |
||
16 | 481 |
$wp_admin_bar->add_node( |
9 | 482 |
array( |
483 |
'id' => 'my-sites', |
|
484 |
'title' => __( 'My Sites' ), |
|
485 |
'href' => $my_sites_url, |
|
486 |
) |
|
487 |
); |
|
0 | 488 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
if ( current_user_can( 'manage_network' ) ) { |
9 | 490 |
$wp_admin_bar->add_group( |
491 |
array( |
|
492 |
'parent' => 'my-sites', |
|
493 |
'id' => 'my-sites-super-admin', |
|
494 |
) |
|
495 |
); |
|
0 | 496 |
|
16 | 497 |
$wp_admin_bar->add_node( |
9 | 498 |
array( |
499 |
'parent' => 'my-sites-super-admin', |
|
500 |
'id' => 'network-admin', |
|
501 |
'title' => __( 'Network Admin' ), |
|
502 |
'href' => network_admin_url(), |
|
503 |
) |
|
504 |
); |
|
0 | 505 |
|
16 | 506 |
$wp_admin_bar->add_node( |
9 | 507 |
array( |
508 |
'parent' => 'network-admin', |
|
509 |
'id' => 'network-admin-d', |
|
510 |
'title' => __( 'Dashboard' ), |
|
511 |
'href' => network_admin_url(), |
|
512 |
) |
|
513 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
if ( current_user_can( 'manage_sites' ) ) { |
16 | 516 |
$wp_admin_bar->add_node( |
9 | 517 |
array( |
518 |
'parent' => 'network-admin', |
|
519 |
'id' => 'network-admin-s', |
|
520 |
'title' => __( 'Sites' ), |
|
521 |
'href' => network_admin_url( 'sites.php' ), |
|
522 |
) |
|
523 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
if ( current_user_can( 'manage_network_users' ) ) { |
16 | 527 |
$wp_admin_bar->add_node( |
9 | 528 |
array( |
529 |
'parent' => 'network-admin', |
|
530 |
'id' => 'network-admin-u', |
|
531 |
'title' => __( 'Users' ), |
|
532 |
'href' => network_admin_url( 'users.php' ), |
|
533 |
) |
|
534 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
if ( current_user_can( 'manage_network_themes' ) ) { |
16 | 538 |
$wp_admin_bar->add_node( |
9 | 539 |
array( |
540 |
'parent' => 'network-admin', |
|
541 |
'id' => 'network-admin-t', |
|
542 |
'title' => __( 'Themes' ), |
|
543 |
'href' => network_admin_url( 'themes.php' ), |
|
544 |
) |
|
545 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
if ( current_user_can( 'manage_network_plugins' ) ) { |
16 | 549 |
$wp_admin_bar->add_node( |
9 | 550 |
array( |
551 |
'parent' => 'network-admin', |
|
552 |
'id' => 'network-admin-p', |
|
553 |
'title' => __( 'Plugins' ), |
|
554 |
'href' => network_admin_url( 'plugins.php' ), |
|
555 |
) |
|
556 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
if ( current_user_can( 'manage_network_options' ) ) { |
16 | 560 |
$wp_admin_bar->add_node( |
9 | 561 |
array( |
562 |
'parent' => 'network-admin', |
|
563 |
'id' => 'network-admin-o', |
|
564 |
'title' => __( 'Settings' ), |
|
565 |
'href' => network_admin_url( 'settings.php' ), |
|
566 |
) |
|
567 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
} |
0 | 569 |
} |
570 |
||
16 | 571 |
// Add site links. |
9 | 572 |
$wp_admin_bar->add_group( |
573 |
array( |
|
574 |
'parent' => 'my-sites', |
|
575 |
'id' => 'my-sites-list', |
|
576 |
'meta' => array( |
|
577 |
'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
|
578 |
), |
|
579 |
) |
|
580 |
); |
|
0 | 581 |
|
582 |
foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
|
583 |
switch_to_blog( $blog->userblog_id ); |
|
584 |
||
18 | 585 |
if ( has_site_icon() ) { |
586 |
$blavatar = sprintf( |
|
587 |
'<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16" />', |
|
588 |
esc_url( get_site_icon_url( 16 ) ), |
|
589 |
esc_url( get_site_icon_url( 32 ) ) |
|
590 |
); |
|
591 |
} else { |
|
592 |
$blavatar = '<div class="blavatar"></div>'; |
|
593 |
} |
|
0 | 594 |
|
5 | 595 |
$blogname = $blog->blogname; |
596 |
||
597 |
if ( ! $blogname ) { |
|
598 |
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
|
599 |
} |
|
600 |
||
9 | 601 |
$menu_id = 'blog-' . $blog->userblog_id; |
0 | 602 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
if ( current_user_can( 'read' ) ) { |
16 | 604 |
$wp_admin_bar->add_node( |
9 | 605 |
array( |
606 |
'parent' => 'my-sites-list', |
|
607 |
'id' => $menu_id, |
|
608 |
'title' => $blavatar . $blogname, |
|
609 |
'href' => admin_url(), |
|
610 |
) |
|
611 |
); |
|
0 | 612 |
|
16 | 613 |
$wp_admin_bar->add_node( |
9 | 614 |
array( |
615 |
'parent' => $menu_id, |
|
616 |
'id' => $menu_id . '-d', |
|
617 |
'title' => __( 'Dashboard' ), |
|
618 |
'href' => admin_url(), |
|
619 |
) |
|
620 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
} else { |
16 | 622 |
$wp_admin_bar->add_node( |
9 | 623 |
array( |
624 |
'parent' => 'my-sites-list', |
|
625 |
'id' => $menu_id, |
|
626 |
'title' => $blavatar . $blogname, |
|
627 |
'href' => home_url(), |
|
628 |
) |
|
629 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
} |
0 | 631 |
|
632 |
if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
|
16 | 633 |
$wp_admin_bar->add_node( |
9 | 634 |
array( |
635 |
'parent' => $menu_id, |
|
636 |
'id' => $menu_id . '-n', |
|
637 |
'title' => get_post_type_object( 'post' )->labels->new_item, |
|
638 |
'href' => admin_url( 'post-new.php' ), |
|
639 |
) |
|
640 |
); |
|
0 | 641 |
} |
642 |
||
643 |
if ( current_user_can( 'edit_posts' ) ) { |
|
16 | 644 |
$wp_admin_bar->add_node( |
9 | 645 |
array( |
646 |
'parent' => $menu_id, |
|
647 |
'id' => $menu_id . '-c', |
|
648 |
'title' => __( 'Manage Comments' ), |
|
649 |
'href' => admin_url( 'edit-comments.php' ), |
|
650 |
) |
|
651 |
); |
|
0 | 652 |
} |
653 |
||
16 | 654 |
$wp_admin_bar->add_node( |
9 | 655 |
array( |
656 |
'parent' => $menu_id, |
|
657 |
'id' => $menu_id . '-v', |
|
658 |
'title' => __( 'Visit Site' ), |
|
659 |
'href' => home_url( '/' ), |
|
660 |
) |
|
661 |
); |
|
0 | 662 |
|
663 |
restore_current_blog(); |
|
664 |
} |
|
665 |
} |
|
666 |
||
667 |
/** |
|
668 |
* Provide a shortlink. |
|
669 |
* |
|
670 |
* @since 3.1.0 |
|
671 |
* |
|
672 |
* @param WP_Admin_Bar $wp_admin_bar |
|
673 |
*/ |
|
674 |
function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
|
675 |
$short = wp_get_shortlink( 0, 'query' ); |
|
9 | 676 |
$id = 'get-shortlink'; |
0 | 677 |
|
9 | 678 |
if ( empty( $short ) ) { |
0 | 679 |
return; |
9 | 680 |
} |
0 | 681 |
|
682 |
$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />'; |
|
683 |
||
16 | 684 |
$wp_admin_bar->add_node( |
9 | 685 |
array( |
686 |
'id' => $id, |
|
687 |
'title' => __( 'Shortlink' ), |
|
688 |
'href' => $short, |
|
689 |
'meta' => array( 'html' => $html ), |
|
690 |
) |
|
691 |
); |
|
0 | 692 |
} |
693 |
||
694 |
/** |
|
695 |
* Provide an edit link for posts and terms. |
|
696 |
* |
|
697 |
* @since 3.1.0 |
|
18 | 698 |
* @since 5.5.0 Added a "View Post" link on Comments screen for a single post. |
0 | 699 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* @global WP_Term $tag |
16 | 701 |
* @global WP_Query $wp_the_query WordPress Query object. |
9 | 702 |
* @global int $user_id The ID of the user being edited. Not to be confused with the |
703 |
* global $user_ID, which contains the ID of the current user. |
|
16 | 704 |
* @global int $post_id The ID of the post when editing comments for a single post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
* |
0 | 706 |
* @param WP_Admin_Bar $wp_admin_bar |
707 |
*/ |
|
708 |
function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
|
16 | 709 |
global $tag, $wp_the_query, $user_id, $post_id; |
0 | 710 |
|
711 |
if ( is_admin() ) { |
|
16 | 712 |
$current_screen = get_current_screen(); |
713 |
$post = get_post(); |
|
714 |
$post_type_object = null; |
|
0 | 715 |
|
16 | 716 |
if ( 'post' === $current_screen->base ) { |
717 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
718 |
} elseif ( 'edit' === $current_screen->base ) { |
|
719 |
$post_type_object = get_post_type_object( $current_screen->post_type ); |
|
720 |
} elseif ( 'edit-comments' === $current_screen->base && $post_id ) { |
|
721 |
$post = get_post( $post_id ); |
|
722 |
if ( $post ) { |
|
723 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
if ( ( 'post' === $current_screen->base || 'edit-comments' === $current_screen->base ) |
|
728 |
&& 'add' !== $current_screen->action |
|
729 |
&& ( $post_type_object ) |
|
0 | 730 |
&& current_user_can( 'read_post', $post->ID ) |
731 |
&& ( $post_type_object->public ) |
|
9 | 732 |
&& ( $post_type_object->show_in_admin_bar ) ) { |
16 | 733 |
if ( 'draft' === $post->post_status ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
$preview_link = get_preview_post_link( $post ); |
16 | 735 |
$wp_admin_bar->add_node( |
9 | 736 |
array( |
737 |
'id' => 'preview', |
|
738 |
'title' => $post_type_object->labels->view_item, |
|
739 |
'href' => esc_url( $preview_link ), |
|
740 |
'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
|
741 |
) |
|
742 |
); |
|
5 | 743 |
} else { |
16 | 744 |
$wp_admin_bar->add_node( |
9 | 745 |
array( |
746 |
'id' => 'view', |
|
747 |
'title' => $post_type_object->labels->view_item, |
|
748 |
'href' => get_permalink( $post->ID ), |
|
749 |
) |
|
750 |
); |
|
5 | 751 |
} |
16 | 752 |
} elseif ( 'edit' === $current_screen->base |
753 |
&& ( $post_type_object ) |
|
9 | 754 |
&& ( $post_type_object->public ) |
755 |
&& ( $post_type_object->show_in_admin_bar ) |
|
756 |
&& ( get_post_type_archive_link( $post_type_object->name ) ) |
|
757 |
&& ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { |
|
758 |
$wp_admin_bar->add_node( |
|
759 |
array( |
|
760 |
'id' => 'archive', |
|
761 |
'title' => $post_type_object->labels->view_items, |
|
762 |
'href' => get_post_type_archive_link( $current_screen->post_type ), |
|
763 |
) |
|
764 |
); |
|
16 | 765 |
} elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) { |
766 |
$tax = get_taxonomy( $tag->taxonomy ); |
|
767 |
if ( is_taxonomy_viewable( $tax ) ) { |
|
768 |
$wp_admin_bar->add_node( |
|
769 |
array( |
|
770 |
'id' => 'view', |
|
771 |
'title' => $tax->labels->view_item, |
|
772 |
'href' => get_term_link( $tag ), |
|
773 |
) |
|
774 |
); |
|
775 |
} |
|
776 |
} elseif ( 'user-edit' === $current_screen->base && isset( $user_id ) ) { |
|
777 |
$user_object = get_userdata( $user_id ); |
|
778 |
$view_link = get_author_posts_url( $user_object->ID ); |
|
779 |
if ( $user_object->exists() && $view_link ) { |
|
780 |
$wp_admin_bar->add_node( |
|
781 |
array( |
|
782 |
'id' => 'view', |
|
783 |
'title' => __( 'View User' ), |
|
784 |
'href' => $view_link, |
|
785 |
) |
|
786 |
); |
|
787 |
} |
|
0 | 788 |
} |
789 |
} else { |
|
790 |
$current_object = $wp_the_query->get_queried_object(); |
|
791 |
||
9 | 792 |
if ( empty( $current_object ) ) { |
0 | 793 |
return; |
9 | 794 |
} |
0 | 795 |
|
16 | 796 |
if ( ! empty( $current_object->post_type ) ) { |
797 |
$post_type_object = get_post_type_object( $current_object->post_type ); |
|
798 |
$edit_post_link = get_edit_post_link( $current_object->ID ); |
|
799 |
if ( $post_type_object |
|
800 |
&& $edit_post_link |
|
801 |
&& current_user_can( 'edit_post', $current_object->ID ) |
|
802 |
&& $post_type_object->show_in_admin_bar ) { |
|
803 |
$wp_admin_bar->add_node( |
|
804 |
array( |
|
805 |
'id' => 'edit', |
|
806 |
'title' => $post_type_object->labels->edit_item, |
|
807 |
'href' => $edit_post_link, |
|
808 |
) |
|
809 |
); |
|
810 |
} |
|
811 |
} elseif ( ! empty( $current_object->taxonomy ) ) { |
|
812 |
$tax = get_taxonomy( $current_object->taxonomy ); |
|
813 |
$edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ); |
|
814 |
if ( $tax && $edit_term_link && current_user_can( 'edit_term', $current_object->term_id ) ) { |
|
815 |
$wp_admin_bar->add_node( |
|
816 |
array( |
|
817 |
'id' => 'edit', |
|
818 |
'title' => $tax->labels->edit_item, |
|
819 |
'href' => $edit_term_link, |
|
820 |
) |
|
821 |
); |
|
822 |
} |
|
823 |
} elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) ) { |
|
824 |
$edit_user_link = get_edit_user_link( $current_object->ID ); |
|
825 |
if ( $edit_user_link ) { |
|
826 |
$wp_admin_bar->add_node( |
|
827 |
array( |
|
828 |
'id' => 'edit', |
|
829 |
'title' => __( 'Edit User' ), |
|
830 |
'href' => $edit_user_link, |
|
831 |
) |
|
832 |
); |
|
833 |
} |
|
0 | 834 |
} |
835 |
} |
|
836 |
} |
|
837 |
||
838 |
/** |
|
839 |
* Add "Add New" menu. |
|
840 |
* |
|
841 |
* @since 3.1.0 |
|
842 |
* |
|
843 |
* @param WP_Admin_Bar $wp_admin_bar |
|
844 |
*/ |
|
845 |
function wp_admin_bar_new_content_menu( $wp_admin_bar ) { |
|
846 |
$actions = array(); |
|
847 |
||
848 |
$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); |
|
849 |
||
9 | 850 |
if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) { |
851 |
$actions['post-new.php'] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); |
|
852 |
} |
|
0 | 853 |
|
9 | 854 |
if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) { |
855 |
$actions['media-new.php'] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); |
|
856 |
} |
|
0 | 857 |
|
9 | 858 |
if ( current_user_can( 'manage_links' ) ) { |
859 |
$actions['link-add.php'] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); |
|
860 |
} |
|
0 | 861 |
|
9 | 862 |
if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) { |
863 |
$actions['post-new.php?post_type=page'] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); |
|
864 |
} |
|
0 | 865 |
|
866 |
unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); |
|
867 |
||
868 |
// Add any additional custom post types. |
|
869 |
foreach ( $cpts as $cpt ) { |
|
9 | 870 |
if ( ! current_user_can( $cpt->cap->create_posts ) ) { |
0 | 871 |
continue; |
9 | 872 |
} |
0 | 873 |
|
9 | 874 |
$key = 'post-new.php?post_type=' . $cpt->name; |
0 | 875 |
$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); |
876 |
} |
|
877 |
// Avoid clash with parent node and a 'content' post type. |
|
9 | 878 |
if ( isset( $actions['post-new.php?post_type=content'] ) ) { |
0 | 879 |
$actions['post-new.php?post_type=content'][1] = 'add-new-content'; |
9 | 880 |
} |
0 | 881 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { |
9 | 883 |
$actions['user-new.php'] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
} |
0 | 885 |
|
9 | 886 |
if ( ! $actions ) { |
0 | 887 |
return; |
9 | 888 |
} |
0 | 889 |
|
18 | 890 |
$title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
0 | 891 |
|
16 | 892 |
$wp_admin_bar->add_node( |
9 | 893 |
array( |
894 |
'id' => 'new-content', |
|
895 |
'title' => $title, |
|
896 |
'href' => admin_url( current( array_keys( $actions ) ) ), |
|
897 |
) |
|
898 |
); |
|
0 | 899 |
|
900 |
foreach ( $actions as $link => $action ) { |
|
901 |
list( $title, $id ) = $action; |
|
902 |
||
16 | 903 |
$wp_admin_bar->add_node( |
9 | 904 |
array( |
905 |
'parent' => 'new-content', |
|
906 |
'id' => $id, |
|
907 |
'title' => $title, |
|
908 |
'href' => admin_url( $link ), |
|
909 |
) |
|
910 |
); |
|
0 | 911 |
} |
912 |
} |
|
913 |
||
914 |
/** |
|
915 |
* Add edit comments link with awaiting moderation count bubble. |
|
916 |
* |
|
917 |
* @since 3.1.0 |
|
918 |
* |
|
919 |
* @param WP_Admin_Bar $wp_admin_bar |
|
920 |
*/ |
|
921 |
function wp_admin_bar_comments_menu( $wp_admin_bar ) { |
|
9 | 922 |
if ( ! current_user_can( 'edit_posts' ) ) { |
0 | 923 |
return; |
9 | 924 |
} |
0 | 925 |
|
9 | 926 |
$awaiting_mod = wp_count_comments(); |
927 |
$awaiting_mod = $awaiting_mod->moderated; |
|
928 |
$awaiting_text = sprintf( |
|
16 | 929 |
/* translators: %s: Number of comments. */ |
9 | 930 |
_n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), |
931 |
number_format_i18n( $awaiting_mod ) |
|
932 |
); |
|
0 | 933 |
|
18 | 934 |
$icon = '<span class="ab-icon" aria-hidden="true"></span>'; |
9 | 935 |
$title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
936 |
$title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>'; |
|
0 | 937 |
|
16 | 938 |
$wp_admin_bar->add_node( |
9 | 939 |
array( |
940 |
'id' => 'comments', |
|
941 |
'title' => $icon . $title, |
|
942 |
'href' => admin_url( 'edit-comments.php' ), |
|
943 |
) |
|
944 |
); |
|
0 | 945 |
} |
946 |
||
947 |
/** |
|
948 |
* Add appearance submenu items to the "Site Name" menu. |
|
949 |
* |
|
950 |
* @since 3.1.0 |
|
951 |
* |
|
952 |
* @param WP_Admin_Bar $wp_admin_bar |
|
953 |
*/ |
|
954 |
function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
|
9 | 955 |
$wp_admin_bar->add_group( |
956 |
array( |
|
957 |
'parent' => 'site-name', |
|
958 |
'id' => 'appearance', |
|
959 |
) |
|
960 |
); |
|
0 | 961 |
|
5 | 962 |
if ( current_user_can( 'switch_themes' ) ) { |
16 | 963 |
$wp_admin_bar->add_node( |
9 | 964 |
array( |
965 |
'parent' => 'appearance', |
|
966 |
'id' => 'themes', |
|
967 |
'title' => __( 'Themes' ), |
|
968 |
'href' => admin_url( 'themes.php' ), |
|
969 |
) |
|
970 |
); |
|
5 | 971 |
} |
972 |
||
973 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
974 |
return; |
|
975 |
} |
|
0 | 976 |
|
9 | 977 |
if ( current_theme_supports( 'widgets' ) ) { |
16 | 978 |
$wp_admin_bar->add_node( |
9 | 979 |
array( |
980 |
'parent' => 'appearance', |
|
981 |
'id' => 'widgets', |
|
982 |
'title' => __( 'Widgets' ), |
|
983 |
'href' => admin_url( 'widgets.php' ), |
|
984 |
) |
|
985 |
); |
|
5 | 986 |
} |
987 |
||
9 | 988 |
if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { |
16 | 989 |
$wp_admin_bar->add_node( |
9 | 990 |
array( |
991 |
'parent' => 'appearance', |
|
992 |
'id' => 'menus', |
|
993 |
'title' => __( 'Menus' ), |
|
994 |
'href' => admin_url( 'nav-menus.php' ), |
|
995 |
) |
|
996 |
); |
|
997 |
} |
|
0 | 998 |
|
5 | 999 |
if ( current_theme_supports( 'custom-background' ) ) { |
16 | 1000 |
$wp_admin_bar->add_node( |
9 | 1001 |
array( |
1002 |
'parent' => 'appearance', |
|
1003 |
'id' => 'background', |
|
1004 |
'title' => __( 'Background' ), |
|
1005 |
'href' => admin_url( 'themes.php?page=custom-background' ), |
|
1006 |
'meta' => array( |
|
1007 |
'class' => 'hide-if-customize', |
|
1008 |
), |
|
1009 |
) |
|
1010 |
); |
|
5 | 1011 |
} |
0 | 1012 |
|
5 | 1013 |
if ( current_theme_supports( 'custom-header' ) ) { |
16 | 1014 |
$wp_admin_bar->add_node( |
9 | 1015 |
array( |
1016 |
'parent' => 'appearance', |
|
1017 |
'id' => 'header', |
|
1018 |
'title' => __( 'Header' ), |
|
1019 |
'href' => admin_url( 'themes.php?page=custom-header' ), |
|
1020 |
'meta' => array( |
|
1021 |
'class' => 'hide-if-customize', |
|
1022 |
), |
|
1023 |
) |
|
1024 |
); |
|
5 | 1025 |
} |
1026 |
||
0 | 1027 |
} |
1028 |
||
1029 |
/** |
|
1030 |
* Provide an update link if theme/plugin/core updates are available. |
|
1031 |
* |
|
1032 |
* @since 3.1.0 |
|
1033 |
* |
|
1034 |
* @param WP_Admin_Bar $wp_admin_bar |
|
1035 |
*/ |
|
1036 |
function wp_admin_bar_updates_menu( $wp_admin_bar ) { |
|
1037 |
||
1038 |
$update_data = wp_get_update_data(); |
|
1039 |
||
9 | 1040 |
if ( ! $update_data['counts']['total'] ) { |
0 | 1041 |
return; |
9 | 1042 |
} |
0 | 1043 |
|
18 | 1044 |
$updates_text = sprintf( |
1045 |
/* translators: %s: Total number of updates available. */ |
|
1046 |
_n( '%s update available', '%s updates available', $update_data['counts']['total'] ), |
|
1047 |
number_format_i18n( $update_data['counts']['total'] ) |
|
1048 |
); |
|
1049 |
||
1050 |
$icon = '<span class="ab-icon" aria-hidden="true"></span>'; |
|
1051 |
$title = '<span class="ab-label" aria-hidden="true">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; |
|
1052 |
$title .= '<span class="screen-reader-text updates-available-text">' . $updates_text . '</span>'; |
|
0 | 1053 |
|
16 | 1054 |
$wp_admin_bar->add_node( |
9 | 1055 |
array( |
1056 |
'id' => 'updates', |
|
18 | 1057 |
'title' => $icon . $title, |
9 | 1058 |
'href' => network_admin_url( 'update-core.php' ), |
1059 |
) |
|
1060 |
); |
|
0 | 1061 |
} |
1062 |
||
1063 |
/** |
|
1064 |
* Add search form. |
|
1065 |
* |
|
1066 |
* @since 3.3.0 |
|
1067 |
* |
|
1068 |
* @param WP_Admin_Bar $wp_admin_bar |
|
1069 |
*/ |
|
1070 |
function wp_admin_bar_search_menu( $wp_admin_bar ) { |
|
9 | 1071 |
if ( is_admin() ) { |
0 | 1072 |
return; |
9 | 1073 |
} |
0 | 1074 |
|
1075 |
$form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; |
|
1076 |
$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; |
|
5 | 1077 |
$form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>'; |
18 | 1078 |
$form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '" />'; |
0 | 1079 |
$form .= '</form>'; |
1080 |
||
16 | 1081 |
$wp_admin_bar->add_node( |
9 | 1082 |
array( |
1083 |
'parent' => 'top-secondary', |
|
1084 |
'id' => 'search', |
|
1085 |
'title' => $form, |
|
1086 |
'meta' => array( |
|
1087 |
'class' => 'admin-bar-search', |
|
1088 |
'tabindex' => -1, |
|
1089 |
), |
|
0 | 1090 |
) |
9 | 1091 |
); |
1092 |
} |
|
1093 |
||
1094 |
/** |
|
1095 |
* Add a link to exit recovery mode when Recovery Mode is active. |
|
1096 |
* |
|
1097 |
* @since 5.2.0 |
|
1098 |
* |
|
1099 |
* @param WP_Admin_Bar $wp_admin_bar |
|
1100 |
*/ |
|
1101 |
function wp_admin_bar_recovery_mode_menu( $wp_admin_bar ) { |
|
1102 |
if ( ! wp_is_recovery_mode() ) { |
|
1103 |
return; |
|
1104 |
} |
|
1105 |
||
1106 |
$url = wp_login_url(); |
|
1107 |
$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url ); |
|
1108 |
$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION ); |
|
1109 |
||
16 | 1110 |
$wp_admin_bar->add_node( |
9 | 1111 |
array( |
1112 |
'parent' => 'top-secondary', |
|
1113 |
'id' => 'recovery-mode', |
|
1114 |
'title' => __( 'Exit Recovery Mode' ), |
|
1115 |
'href' => $url, |
|
1116 |
) |
|
1117 |
); |
|
0 | 1118 |
} |
1119 |
||
1120 |
/** |
|
1121 |
* Add secondary menus. |
|
1122 |
* |
|
1123 |
* @since 3.3.0 |
|
1124 |
* |
|
1125 |
* @param WP_Admin_Bar $wp_admin_bar |
|
1126 |
*/ |
|
1127 |
function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
|
9 | 1128 |
$wp_admin_bar->add_group( |
1129 |
array( |
|
1130 |
'id' => 'top-secondary', |
|
1131 |
'meta' => array( |
|
1132 |
'class' => 'ab-top-secondary', |
|
1133 |
), |
|
1134 |
) |
|
1135 |
); |
|
0 | 1136 |
|
9 | 1137 |
$wp_admin_bar->add_group( |
1138 |
array( |
|
1139 |
'parent' => 'wp-logo', |
|
1140 |
'id' => 'wp-logo-external', |
|
1141 |
'meta' => array( |
|
1142 |
'class' => 'ab-sub-secondary', |
|
1143 |
), |
|
1144 |
) |
|
1145 |
); |
|
0 | 1146 |
} |
1147 |
||
1148 |
/** |
|
1149 |
* Style and scripts for the admin bar. |
|
1150 |
* |
|
1151 |
* @since 3.1.0 |
|
1152 |
*/ |
|
9 | 1153 |
function wp_admin_bar_header() { |
16 | 1154 |
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
9 | 1155 |
?> |
16 | 1156 |
<style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style> |
9 | 1157 |
<?php |
0 | 1158 |
} |
1159 |
||
1160 |
/** |
|
1161 |
* Default admin bar callback. |
|
1162 |
* |
|
1163 |
* @since 3.1.0 |
|
1164 |
*/ |
|
9 | 1165 |
function _admin_bar_bump_cb() { |
16 | 1166 |
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
9 | 1167 |
?> |
16 | 1168 |
<style<?php echo $type_attr; ?> media="screen"> |
5 | 1169 |
html { margin-top: 32px !important; } |
1170 |
* html body { margin-top: 32px !important; } |
|
1171 |
@media screen and ( max-width: 782px ) { |
|
1172 |
html { margin-top: 46px !important; } |
|
1173 |
* html body { margin-top: 46px !important; } |
|
1174 |
} |
|
0 | 1175 |
</style> |
9 | 1176 |
<?php |
0 | 1177 |
} |
1178 |
||
1179 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
* Sets the display status of the admin bar. |
0 | 1181 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
* This can be called immediately upon plugin load. It does not need to be called |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
* from a function hooked to the {@see 'init'} action. |
0 | 1184 |
* |
1185 |
* @since 3.1.0 |
|
1186 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
* @global bool $show_admin_bar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
* |
0 | 1189 |
* @param bool $show Whether to allow the admin bar to show. |
1190 |
*/ |
|
1191 |
function show_admin_bar( $show ) { |
|
1192 |
global $show_admin_bar; |
|
1193 |
$show_admin_bar = (bool) $show; |
|
1194 |
} |
|
1195 |
||
1196 |
/** |
|
9 | 1197 |
* Determines whether the admin bar should be showing. |
1198 |
* |
|
1199 |
* For more information on this and similar theme functions, check out |
|
1200 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1201 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 1202 |
* |
1203 |
* @since 3.1.0 |
|
1204 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* @global bool $show_admin_bar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
* @global string $pagenow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
* |
0 | 1208 |
* @return bool Whether the admin bar should be showing. |
1209 |
*/ |
|
1210 |
function is_admin_bar_showing() { |
|
1211 |
global $show_admin_bar, $pagenow; |
|
1212 |
||
1213 |
// For all these types of requests, we never want an admin bar. |
|
9 | 1214 |
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'DOING_AJAX' ) || defined( 'IFRAME_REQUEST' ) || wp_is_json_request() ) { |
0 | 1215 |
return false; |
9 | 1216 |
} |
0 | 1217 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
if ( is_embed() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
|
0 | 1222 |
// Integrated into the admin. |
9 | 1223 |
if ( is_admin() ) { |
0 | 1224 |
return true; |
9 | 1225 |
} |
0 | 1226 |
|
1227 |
if ( ! isset( $show_admin_bar ) ) { |
|
16 | 1228 |
if ( ! is_user_logged_in() || 'wp-login.php' === $pagenow ) { |
0 | 1229 |
$show_admin_bar = false; |
1230 |
} else { |
|
1231 |
$show_admin_bar = _get_admin_bar_pref(); |
|
1232 |
} |
|
1233 |
} |
|
1234 |
||
5 | 1235 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* Filters whether to show the admin bar. |
5 | 1237 |
* |
1238 |
* Returning false to this hook is the recommended way to hide the admin bar. |
|
1239 |
* The user's display preference is used for logged in users. |
|
1240 |
* |
|
1241 |
* @since 3.1.0 |
|
1242 |
* |
|
1243 |
* @param bool $show_admin_bar Whether the admin bar should be shown. Default false. |
|
1244 |
*/ |
|
0 | 1245 |
$show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar ); |
1246 |
||
1247 |
return $show_admin_bar; |
|
1248 |
} |
|
1249 |
||
1250 |
/** |
|
1251 |
* Retrieve the admin bar display preference of a user. |
|
1252 |
* |
|
1253 |
* @since 3.1.0 |
|
1254 |
* @access private |
|
1255 |
* |
|
1256 |
* @param string $context Context of this preference check. Defaults to 'front'. The 'admin' |
|
16 | 1257 |
* preference is no longer used. |
1258 |
* @param int $user Optional. ID of the user to check, defaults to 0 for current user. |
|
0 | 1259 |
* @return bool Whether the admin bar should be showing for this user. |
1260 |
*/ |
|
1261 |
function _get_admin_bar_pref( $context = 'front', $user = 0 ) { |
|
1262 |
$pref = get_user_option( "show_admin_bar_{$context}", $user ); |
|
9 | 1263 |
if ( false === $pref ) { |
0 | 1264 |
return true; |
9 | 1265 |
} |
0 | 1266 |
|
1267 |
return 'true' === $pref; |
|
1268 |
} |