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