130 |
133 |
131 $wp_admin_bar->add_menu( $wp_logo_menu_args ); |
134 $wp_admin_bar->add_menu( $wp_logo_menu_args ); |
132 |
135 |
133 if ( $about_url ) { |
136 if ( $about_url ) { |
134 // Add "About WordPress" link |
137 // Add "About WordPress" link |
135 $wp_admin_bar->add_menu( array( |
138 $wp_admin_bar->add_menu( |
136 'parent' => 'wp-logo', |
139 array( |
137 'id' => 'about', |
140 'parent' => 'wp-logo', |
138 'title' => __('About WordPress'), |
141 'id' => 'about', |
139 'href' => $about_url, |
142 'title' => __( 'About WordPress' ), |
140 ) ); |
143 'href' => $about_url, |
|
144 ) |
|
145 ); |
141 } |
146 } |
142 |
147 |
143 // Add WordPress.org link |
148 // Add WordPress.org link |
144 $wp_admin_bar->add_menu( array( |
149 $wp_admin_bar->add_menu( |
145 'parent' => 'wp-logo-external', |
150 array( |
146 'id' => 'wporg', |
151 'parent' => 'wp-logo-external', |
147 'title' => __('WordPress.org'), |
152 'id' => 'wporg', |
148 'href' => __('https://wordpress.org/'), |
153 'title' => __( 'WordPress.org' ), |
149 ) ); |
154 'href' => __( 'https://wordpress.org/' ), |
|
155 ) |
|
156 ); |
150 |
157 |
151 // Add codex link |
158 // Add codex link |
152 $wp_admin_bar->add_menu( array( |
159 $wp_admin_bar->add_menu( |
153 'parent' => 'wp-logo-external', |
160 array( |
154 'id' => 'documentation', |
161 'parent' => 'wp-logo-external', |
155 'title' => __('Documentation'), |
162 'id' => 'documentation', |
156 'href' => __('https://codex.wordpress.org/'), |
163 'title' => __( 'Documentation' ), |
157 ) ); |
164 'href' => __( 'https://codex.wordpress.org/' ), |
|
165 ) |
|
166 ); |
158 |
167 |
159 // Add forums link |
168 // Add forums link |
160 $wp_admin_bar->add_menu( array( |
169 $wp_admin_bar->add_menu( |
161 'parent' => 'wp-logo-external', |
170 array( |
162 'id' => 'support-forums', |
171 'parent' => 'wp-logo-external', |
163 'title' => __('Support Forums'), |
172 'id' => 'support-forums', |
164 'href' => __('https://wordpress.org/support/'), |
173 'title' => __( 'Support' ), |
165 ) ); |
174 'href' => __( 'https://wordpress.org/support/' ), |
|
175 ) |
|
176 ); |
166 |
177 |
167 // Add feedback link |
178 // Add feedback link |
168 $wp_admin_bar->add_menu( array( |
179 $wp_admin_bar->add_menu( |
169 'parent' => 'wp-logo-external', |
180 array( |
170 'id' => 'feedback', |
181 'parent' => 'wp-logo-external', |
171 'title' => __('Feedback'), |
182 'id' => 'feedback', |
172 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'), |
183 'title' => __( 'Feedback' ), |
173 ) ); |
184 'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), |
|
185 ) |
|
186 ); |
174 } |
187 } |
175 |
188 |
176 /** |
189 /** |
177 * Add the sidebar toggle button. |
190 * Add the sidebar toggle button. |
178 * |
191 * |
237 */ |
255 */ |
238 function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
256 function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
239 $user_id = get_current_user_id(); |
257 $user_id = get_current_user_id(); |
240 $current_user = wp_get_current_user(); |
258 $current_user = wp_get_current_user(); |
241 |
259 |
242 if ( ! $user_id ) |
260 if ( ! $user_id ) { |
243 return; |
261 return; |
|
262 } |
244 |
263 |
245 if ( current_user_can( 'read' ) ) { |
264 if ( current_user_can( 'read' ) ) { |
246 $profile_url = get_edit_profile_url( $user_id ); |
265 $profile_url = get_edit_profile_url( $user_id ); |
247 } elseif ( is_multisite() ) { |
266 } elseif ( is_multisite() ) { |
248 $profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
267 $profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
249 } else { |
268 } else { |
250 $profile_url = false; |
269 $profile_url = false; |
251 } |
270 } |
252 |
271 |
253 $wp_admin_bar->add_group( array( |
272 $wp_admin_bar->add_group( |
254 'parent' => 'my-account', |
273 array( |
255 'id' => 'user-actions', |
274 'parent' => 'my-account', |
256 ) ); |
275 'id' => 'user-actions', |
|
276 ) |
|
277 ); |
257 |
278 |
258 $user_info = get_avatar( $user_id, 64 ); |
279 $user_info = get_avatar( $user_id, 64 ); |
259 $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; |
280 $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; |
260 |
281 |
261 if ( $current_user->display_name !== $current_user->user_login ) |
282 if ( $current_user->display_name !== $current_user->user_login ) { |
262 $user_info .= "<span class='username'>{$current_user->user_login}</span>"; |
283 $user_info .= "<span class='username'>{$current_user->user_login}</span>"; |
263 |
284 } |
264 $wp_admin_bar->add_menu( array( |
285 |
265 'parent' => 'user-actions', |
286 $wp_admin_bar->add_menu( |
266 'id' => 'user-info', |
287 array( |
267 'title' => $user_info, |
288 'parent' => 'user-actions', |
268 'href' => $profile_url, |
289 'id' => 'user-info', |
269 'meta' => array( |
290 'title' => $user_info, |
270 'tabindex' => -1, |
291 'href' => $profile_url, |
271 ), |
292 'meta' => array( |
272 ) ); |
293 'tabindex' => -1, |
|
294 ), |
|
295 ) |
|
296 ); |
273 |
297 |
274 if ( false !== $profile_url ) { |
298 if ( false !== $profile_url ) { |
275 $wp_admin_bar->add_menu( array( |
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 ); |
|
307 } |
|
308 |
|
309 $wp_admin_bar->add_menu( |
|
310 array( |
276 'parent' => 'user-actions', |
311 'parent' => 'user-actions', |
277 'id' => 'edit-profile', |
312 'id' => 'logout', |
278 'title' => __( 'Edit My Profile' ), |
313 'title' => __( 'Log Out' ), |
279 'href' => $profile_url, |
314 'href' => wp_logout_url(), |
280 ) ); |
315 ) |
281 } |
316 ); |
282 |
|
283 $wp_admin_bar->add_menu( array( |
|
284 'parent' => 'user-actions', |
|
285 'id' => 'logout', |
|
286 'title' => __( 'Log Out' ), |
|
287 'href' => wp_logout_url(), |
|
288 ) ); |
|
289 } |
317 } |
290 |
318 |
291 /** |
319 /** |
292 * Add the "Site Name" menu. |
320 * Add the "Site Name" menu. |
293 * |
321 * |
319 $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
348 $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
320 } |
349 } |
321 |
350 |
322 $title = wp_html_excerpt( $blogname, 40, '…' ); |
351 $title = wp_html_excerpt( $blogname, 40, '…' ); |
323 |
352 |
324 $wp_admin_bar->add_menu( array( |
353 $wp_admin_bar->add_menu( |
325 'id' => 'site-name', |
354 array( |
326 'title' => $title, |
355 'id' => 'site-name', |
327 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
356 'title' => $title, |
328 ) ); |
357 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
|
358 ) |
|
359 ); |
329 |
360 |
330 // Create submenu items. |
361 // Create submenu items. |
331 |
362 |
332 if ( is_admin() ) { |
363 if ( is_admin() ) { |
333 // Add an option to visit the site. |
364 // Add an option to visit the site. |
334 $wp_admin_bar->add_menu( array( |
365 $wp_admin_bar->add_menu( |
335 'parent' => 'site-name', |
366 array( |
336 'id' => 'view-site', |
367 'parent' => 'site-name', |
337 'title' => __( 'Visit Site' ), |
368 'id' => 'view-site', |
338 'href' => home_url( '/' ), |
369 'title' => __( 'Visit Site' ), |
339 ) ); |
370 'href' => home_url( '/' ), |
|
371 ) |
|
372 ); |
340 |
373 |
341 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
374 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
342 $wp_admin_bar->add_menu( array( |
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 ); |
|
383 } |
|
384 } elseif ( current_user_can( 'read' ) ) { |
|
385 // We're on the front end, link to the Dashboard. |
|
386 $wp_admin_bar->add_menu( |
|
387 array( |
343 'parent' => 'site-name', |
388 'parent' => 'site-name', |
344 'id' => 'edit-site', |
389 'id' => 'dashboard', |
345 'title' => __( 'Edit Site' ), |
390 'title' => __( 'Dashboard' ), |
346 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), |
391 'href' => admin_url(), |
347 ) ); |
392 ) |
348 } |
393 ); |
349 |
|
350 } else if ( current_user_can( 'read' ) ) { |
|
351 // We're on the front end, link to the Dashboard. |
|
352 $wp_admin_bar->add_menu( array( |
|
353 'parent' => 'site-name', |
|
354 'id' => 'dashboard', |
|
355 'title' => __( 'Dashboard' ), |
|
356 'href' => admin_url(), |
|
357 ) ); |
|
358 |
394 |
359 // Add the appearance submenu items. |
395 // Add the appearance submenu items. |
360 wp_admin_bar_appearance_menu( $wp_admin_bar ); |
396 wp_admin_bar_appearance_menu( $wp_admin_bar ); |
361 } |
397 } |
362 } |
398 } |
424 $my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' ); |
463 $my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' ); |
425 } else { |
464 } else { |
426 $my_sites_url = admin_url( 'my-sites.php' ); |
465 $my_sites_url = admin_url( 'my-sites.php' ); |
427 } |
466 } |
428 |
467 |
429 $wp_admin_bar->add_menu( array( |
468 $wp_admin_bar->add_menu( |
430 'id' => 'my-sites', |
469 array( |
431 'title' => __( 'My Sites' ), |
470 'id' => 'my-sites', |
432 'href' => $my_sites_url, |
471 'title' => __( 'My Sites' ), |
433 ) ); |
472 'href' => $my_sites_url, |
|
473 ) |
|
474 ); |
434 |
475 |
435 if ( current_user_can( 'manage_network' ) ) { |
476 if ( current_user_can( 'manage_network' ) ) { |
436 $wp_admin_bar->add_group( array( |
477 $wp_admin_bar->add_group( |
|
478 array( |
|
479 'parent' => 'my-sites', |
|
480 'id' => 'my-sites-super-admin', |
|
481 ) |
|
482 ); |
|
483 |
|
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 ); |
|
492 |
|
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 ); |
|
501 |
|
502 if ( current_user_can( 'manage_sites' ) ) { |
|
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 ); |
|
511 } |
|
512 |
|
513 if ( current_user_can( 'manage_network_users' ) ) { |
|
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 ); |
|
522 } |
|
523 |
|
524 if ( current_user_can( 'manage_network_themes' ) ) { |
|
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 ); |
|
533 } |
|
534 |
|
535 if ( current_user_can( 'manage_network_plugins' ) ) { |
|
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 ); |
|
544 } |
|
545 |
|
546 if ( current_user_can( 'manage_network_options' ) ) { |
|
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 ); |
|
555 } |
|
556 } |
|
557 |
|
558 // Add site links |
|
559 $wp_admin_bar->add_group( |
|
560 array( |
437 'parent' => 'my-sites', |
561 'parent' => 'my-sites', |
438 'id' => 'my-sites-super-admin', |
562 'id' => 'my-sites-list', |
439 ) ); |
563 'meta' => array( |
440 |
564 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
441 $wp_admin_bar->add_menu( array( |
565 ), |
442 'parent' => 'my-sites-super-admin', |
566 ) |
443 'id' => 'network-admin', |
567 ); |
444 'title' => __('Network Admin'), |
|
445 'href' => network_admin_url(), |
|
446 ) ); |
|
447 |
|
448 $wp_admin_bar->add_menu( array( |
|
449 'parent' => 'network-admin', |
|
450 'id' => 'network-admin-d', |
|
451 'title' => __( 'Dashboard' ), |
|
452 'href' => network_admin_url(), |
|
453 ) ); |
|
454 |
|
455 if ( current_user_can( 'manage_sites' ) ) { |
|
456 $wp_admin_bar->add_menu( array( |
|
457 'parent' => 'network-admin', |
|
458 'id' => 'network-admin-s', |
|
459 'title' => __( 'Sites' ), |
|
460 'href' => network_admin_url( 'sites.php' ), |
|
461 ) ); |
|
462 } |
|
463 |
|
464 if ( current_user_can( 'manage_network_users' ) ) { |
|
465 $wp_admin_bar->add_menu( array( |
|
466 'parent' => 'network-admin', |
|
467 'id' => 'network-admin-u', |
|
468 'title' => __( 'Users' ), |
|
469 'href' => network_admin_url( 'users.php' ), |
|
470 ) ); |
|
471 } |
|
472 |
|
473 if ( current_user_can( 'manage_network_themes' ) ) { |
|
474 $wp_admin_bar->add_menu( array( |
|
475 'parent' => 'network-admin', |
|
476 'id' => 'network-admin-t', |
|
477 'title' => __( 'Themes' ), |
|
478 'href' => network_admin_url( 'themes.php' ), |
|
479 ) ); |
|
480 } |
|
481 |
|
482 if ( current_user_can( 'manage_network_plugins' ) ) { |
|
483 $wp_admin_bar->add_menu( array( |
|
484 'parent' => 'network-admin', |
|
485 'id' => 'network-admin-p', |
|
486 'title' => __( 'Plugins' ), |
|
487 'href' => network_admin_url( 'plugins.php' ), |
|
488 ) ); |
|
489 } |
|
490 |
|
491 if ( current_user_can( 'manage_network_options' ) ) { |
|
492 $wp_admin_bar->add_menu( array( |
|
493 'parent' => 'network-admin', |
|
494 'id' => 'network-admin-o', |
|
495 'title' => __( 'Settings' ), |
|
496 'href' => network_admin_url( 'settings.php' ), |
|
497 ) ); |
|
498 } |
|
499 } |
|
500 |
|
501 // Add site links |
|
502 $wp_admin_bar->add_group( array( |
|
503 'parent' => 'my-sites', |
|
504 'id' => 'my-sites-list', |
|
505 'meta' => array( |
|
506 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
|
507 ), |
|
508 ) ); |
|
509 |
568 |
510 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
569 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
511 switch_to_blog( $blog->userblog_id ); |
570 switch_to_blog( $blog->userblog_id ); |
512 |
571 |
513 $blavatar = '<div class="blavatar"></div>'; |
572 $blavatar = '<div class="blavatar"></div>'; |
516 |
575 |
517 if ( ! $blogname ) { |
576 if ( ! $blogname ) { |
518 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
577 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
519 } |
578 } |
520 |
579 |
521 $menu_id = 'blog-' . $blog->userblog_id; |
580 $menu_id = 'blog-' . $blog->userblog_id; |
522 |
581 |
523 if ( current_user_can( 'read' ) ) { |
582 if ( current_user_can( 'read' ) ) { |
524 $wp_admin_bar->add_menu( array( |
583 $wp_admin_bar->add_menu( |
525 'parent' => 'my-sites-list', |
584 array( |
526 'id' => $menu_id, |
585 'parent' => 'my-sites-list', |
527 'title' => $blavatar . $blogname, |
586 'id' => $menu_id, |
528 'href' => admin_url(), |
587 'title' => $blavatar . $blogname, |
529 ) ); |
588 'href' => admin_url(), |
530 |
589 ) |
531 $wp_admin_bar->add_menu( array( |
590 ); |
|
591 |
|
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 ); |
|
600 } else { |
|
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 ); |
|
609 } |
|
610 |
|
611 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
|
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 ); |
|
620 } |
|
621 |
|
622 if ( current_user_can( 'edit_posts' ) ) { |
|
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 ); |
|
631 } |
|
632 |
|
633 $wp_admin_bar->add_menu( |
|
634 array( |
532 'parent' => $menu_id, |
635 'parent' => $menu_id, |
533 'id' => $menu_id . '-d', |
636 'id' => $menu_id . '-v', |
534 'title' => __( 'Dashboard' ), |
637 'title' => __( 'Visit Site' ), |
535 'href' => admin_url(), |
638 'href' => home_url( '/' ), |
536 ) ); |
639 ) |
537 } else { |
640 ); |
538 $wp_admin_bar->add_menu( array( |
|
539 'parent' => 'my-sites-list', |
|
540 'id' => $menu_id, |
|
541 'title' => $blavatar . $blogname, |
|
542 'href' => home_url(), |
|
543 ) ); |
|
544 } |
|
545 |
|
546 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
|
547 $wp_admin_bar->add_menu( array( |
|
548 'parent' => $menu_id, |
|
549 'id' => $menu_id . '-n', |
|
550 'title' => __( 'New Post' ), |
|
551 'href' => admin_url( 'post-new.php' ), |
|
552 ) ); |
|
553 } |
|
554 |
|
555 if ( current_user_can( 'edit_posts' ) ) { |
|
556 $wp_admin_bar->add_menu( array( |
|
557 'parent' => $menu_id, |
|
558 'id' => $menu_id . '-c', |
|
559 'title' => __( 'Manage Comments' ), |
|
560 'href' => admin_url( 'edit-comments.php' ), |
|
561 ) ); |
|
562 } |
|
563 |
|
564 $wp_admin_bar->add_menu( array( |
|
565 'parent' => $menu_id, |
|
566 'id' => $menu_id . '-v', |
|
567 'title' => __( 'Visit Site' ), |
|
568 'href' => home_url( '/' ), |
|
569 ) ); |
|
570 |
641 |
571 restore_current_blog(); |
642 restore_current_blog(); |
572 } |
643 } |
573 } |
644 } |
574 |
645 |
579 * |
650 * |
580 * @param WP_Admin_Bar $wp_admin_bar |
651 * @param WP_Admin_Bar $wp_admin_bar |
581 */ |
652 */ |
582 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
653 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
583 $short = wp_get_shortlink( 0, 'query' ); |
654 $short = wp_get_shortlink( 0, 'query' ); |
584 $id = 'get-shortlink'; |
655 $id = 'get-shortlink'; |
585 |
656 |
586 if ( empty( $short ) ) |
657 if ( empty( $short ) ) { |
587 return; |
658 return; |
|
659 } |
588 |
660 |
589 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />'; |
661 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />'; |
590 |
662 |
591 $wp_admin_bar->add_menu( array( |
663 $wp_admin_bar->add_menu( |
592 'id' => $id, |
664 array( |
593 'title' => __( 'Shortlink' ), |
665 'id' => $id, |
594 'href' => $short, |
666 'title' => __( 'Shortlink' ), |
595 'meta' => array( 'html' => $html ), |
667 'href' => $short, |
596 ) ); |
668 'meta' => array( 'html' => $html ), |
|
669 ) |
|
670 ); |
597 } |
671 } |
598 |
672 |
599 /** |
673 /** |
600 * Provide an edit link for posts and terms. |
674 * Provide an edit link for posts and terms. |
601 * |
675 * |
602 * @since 3.1.0 |
676 * @since 3.1.0 |
603 * |
677 * |
604 * @global WP_Term $tag |
678 * @global WP_Term $tag |
605 * @global WP_Query $wp_the_query |
679 * @global WP_Query $wp_the_query |
|
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. |
606 * |
682 * |
607 * @param WP_Admin_Bar $wp_admin_bar |
683 * @param WP_Admin_Bar $wp_admin_bar |
608 */ |
684 */ |
609 function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
685 function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
610 global $tag, $wp_the_query, $user_id; |
686 global $tag, $wp_the_query, $user_id; |
611 |
687 |
612 if ( is_admin() ) { |
688 if ( is_admin() ) { |
613 $current_screen = get_current_screen(); |
689 $current_screen = get_current_screen(); |
614 $post = get_post(); |
690 $post = get_post(); |
615 |
691 |
616 if ( 'post' == $current_screen->base |
692 if ( 'post' == $current_screen->base |
617 && 'add' != $current_screen->action |
693 && 'add' != $current_screen->action |
618 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
694 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
619 && current_user_can( 'read_post', $post->ID ) |
695 && current_user_can( 'read_post', $post->ID ) |
620 && ( $post_type_object->public ) |
696 && ( $post_type_object->public ) |
621 && ( $post_type_object->show_in_admin_bar ) ) |
697 && ( $post_type_object->show_in_admin_bar ) ) { |
622 { |
|
623 if ( 'draft' == $post->post_status ) { |
698 if ( 'draft' == $post->post_status ) { |
624 $preview_link = get_preview_post_link( $post ); |
699 $preview_link = get_preview_post_link( $post ); |
625 $wp_admin_bar->add_menu( array( |
700 $wp_admin_bar->add_menu( |
626 'id' => 'preview', |
701 array( |
627 'title' => $post_type_object->labels->view_item, |
702 'id' => 'preview', |
628 'href' => esc_url( $preview_link ), |
703 'title' => $post_type_object->labels->view_item, |
629 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
704 'href' => esc_url( $preview_link ), |
630 ) ); |
705 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
|
706 ) |
|
707 ); |
631 } else { |
708 } else { |
632 $wp_admin_bar->add_menu( array( |
709 $wp_admin_bar->add_menu( |
633 'id' => 'view', |
710 array( |
634 'title' => $post_type_object->labels->view_item, |
711 'id' => 'view', |
635 'href' => get_permalink( $post->ID ) |
712 'title' => $post_type_object->labels->view_item, |
636 ) ); |
713 'href' => get_permalink( $post->ID ), |
|
714 ) |
|
715 ); |
637 } |
716 } |
638 } elseif ( 'edit' == $current_screen->base |
717 } elseif ( 'edit' == $current_screen->base |
639 && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) |
718 && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) |
640 && ( $post_type_object->public ) |
719 && ( $post_type_object->public ) |
641 && ( $post_type_object->show_in_admin_bar ) |
720 && ( $post_type_object->show_in_admin_bar ) |
642 && ( get_post_type_archive_link( $post_type_object->name ) ) |
721 && ( get_post_type_archive_link( $post_type_object->name ) ) |
643 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) |
722 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { |
644 { |
723 $wp_admin_bar->add_node( |
645 $wp_admin_bar->add_node( array( |
724 array( |
646 'id' => 'archive', |
725 'id' => 'archive', |
647 'title' => $post_type_object->labels->view_items, |
726 'title' => $post_type_object->labels->view_items, |
648 'href' => get_post_type_archive_link( $current_screen->post_type ) |
727 'href' => get_post_type_archive_link( $current_screen->post_type ), |
649 ) ); |
728 ) |
|
729 ); |
650 } elseif ( 'term' == $current_screen->base |
730 } elseif ( 'term' == $current_screen->base |
651 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) |
731 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) |
652 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
732 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
653 && $tax->public ) |
733 && is_taxonomy_viewable( $tax ) ) { |
654 { |
734 $wp_admin_bar->add_menu( |
655 $wp_admin_bar->add_menu( array( |
735 array( |
656 'id' => 'view', |
736 'id' => 'view', |
657 'title' => $tax->labels->view_item, |
737 'title' => $tax->labels->view_item, |
658 'href' => get_term_link( $tag ) |
738 'href' => get_term_link( $tag ), |
659 ) ); |
739 ) |
|
740 ); |
660 } elseif ( 'user-edit' == $current_screen->base |
741 } elseif ( 'user-edit' == $current_screen->base |
661 && isset( $user_id ) |
742 && isset( $user_id ) |
662 && ( $user_object = get_userdata( $user_id ) ) |
743 && ( $user_object = get_userdata( $user_id ) ) |
663 && $user_object->exists() |
744 && $user_object->exists() |
664 && $view_link = get_author_posts_url( $user_object->ID ) ) |
745 && $view_link = get_author_posts_url( $user_object->ID ) ) { |
665 { |
746 $wp_admin_bar->add_menu( |
666 $wp_admin_bar->add_menu( array( |
747 array( |
667 'id' => 'view', |
748 'id' => 'view', |
668 'title' => __( 'View User' ), |
749 'title' => __( 'View User' ), |
669 'href' => $view_link, |
750 'href' => $view_link, |
670 ) ); |
751 ) |
|
752 ); |
671 } |
753 } |
672 } else { |
754 } else { |
673 $current_object = $wp_the_query->get_queried_object(); |
755 $current_object = $wp_the_query->get_queried_object(); |
674 |
756 |
675 if ( empty( $current_object ) ) |
757 if ( empty( $current_object ) ) { |
676 return; |
758 return; |
|
759 } |
677 |
760 |
678 if ( ! empty( $current_object->post_type ) |
761 if ( ! empty( $current_object->post_type ) |
679 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
762 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
680 && current_user_can( 'edit_post', $current_object->ID ) |
763 && current_user_can( 'edit_post', $current_object->ID ) |
681 && $post_type_object->show_in_admin_bar |
764 && $post_type_object->show_in_admin_bar |
682 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) |
765 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) { |
683 { |
766 $wp_admin_bar->add_menu( |
684 $wp_admin_bar->add_menu( array( |
767 array( |
685 'id' => 'edit', |
768 'id' => 'edit', |
686 'title' => $post_type_object->labels->edit_item, |
769 'title' => $post_type_object->labels->edit_item, |
687 'href' => $edit_post_link |
770 'href' => $edit_post_link, |
688 ) ); |
771 ) |
|
772 ); |
689 } elseif ( ! empty( $current_object->taxonomy ) |
773 } elseif ( ! empty( $current_object->taxonomy ) |
690 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
774 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
691 && current_user_can( 'edit_term', $current_object->term_id ) |
775 && current_user_can( 'edit_term', $current_object->term_id ) |
692 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) |
776 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) { |
693 { |
777 $wp_admin_bar->add_menu( |
694 $wp_admin_bar->add_menu( array( |
778 array( |
695 'id' => 'edit', |
779 'id' => 'edit', |
696 'title' => $tax->labels->edit_item, |
780 'title' => $tax->labels->edit_item, |
697 'href' => $edit_term_link |
781 'href' => $edit_term_link, |
698 ) ); |
782 ) |
|
783 ); |
699 } elseif ( is_a( $current_object, 'WP_User' ) |
784 } elseif ( is_a( $current_object, 'WP_User' ) |
700 && current_user_can( 'edit_user', $current_object->ID ) |
785 && current_user_can( 'edit_user', $current_object->ID ) |
701 && $edit_user_link = get_edit_user_link( $current_object->ID ) ) |
786 && $edit_user_link = get_edit_user_link( $current_object->ID ) ) { |
702 { |
787 $wp_admin_bar->add_menu( |
703 $wp_admin_bar->add_menu( array( |
788 array( |
704 'id' => 'edit', |
789 'id' => 'edit', |
705 'title' => __( 'Edit User' ), |
790 'title' => __( 'Edit User' ), |
706 'href' => $edit_user_link, |
791 'href' => $edit_user_link, |
707 ) ); |
792 ) |
|
793 ); |
708 } |
794 } |
709 } |
795 } |
710 } |
796 } |
711 |
797 |
712 /** |
798 /** |
719 function wp_admin_bar_new_content_menu( $wp_admin_bar ) { |
805 function wp_admin_bar_new_content_menu( $wp_admin_bar ) { |
720 $actions = array(); |
806 $actions = array(); |
721 |
807 |
722 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); |
808 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); |
723 |
809 |
724 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) |
810 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) { |
725 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); |
811 $actions['post-new.php'] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); |
726 |
812 } |
727 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) |
813 |
728 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); |
814 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) { |
729 |
815 $actions['media-new.php'] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); |
730 if ( current_user_can( 'manage_links' ) ) |
816 } |
731 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); |
817 |
732 |
818 if ( current_user_can( 'manage_links' ) ) { |
733 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) |
819 $actions['link-add.php'] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); |
734 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); |
820 } |
|
821 |
|
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 } |
735 |
825 |
736 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); |
826 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); |
737 |
827 |
738 // Add any additional custom post types. |
828 // Add any additional custom post types. |
739 foreach ( $cpts as $cpt ) { |
829 foreach ( $cpts as $cpt ) { |
740 if ( ! current_user_can( $cpt->cap->create_posts ) ) |
830 if ( ! current_user_can( $cpt->cap->create_posts ) ) { |
741 continue; |
831 continue; |
742 |
832 } |
743 $key = 'post-new.php?post_type=' . $cpt->name; |
833 |
|
834 $key = 'post-new.php?post_type=' . $cpt->name; |
744 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); |
835 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); |
745 } |
836 } |
746 // Avoid clash with parent node and a 'content' post type. |
837 // Avoid clash with parent node and a 'content' post type. |
747 if ( isset( $actions['post-new.php?post_type=content'] ) ) |
838 if ( isset( $actions['post-new.php?post_type=content'] ) ) { |
748 $actions['post-new.php?post_type=content'][1] = 'add-new-content'; |
839 $actions['post-new.php?post_type=content'][1] = 'add-new-content'; |
|
840 } |
749 |
841 |
750 if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { |
842 if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { |
751 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); |
843 $actions['user-new.php'] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); |
752 } |
844 } |
753 |
845 |
754 if ( ! $actions ) |
846 if ( ! $actions ) { |
755 return; |
847 return; |
|
848 } |
756 |
849 |
757 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
850 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
758 |
851 |
759 $wp_admin_bar->add_menu( array( |
852 $wp_admin_bar->add_menu( |
760 'id' => 'new-content', |
853 array( |
761 'title' => $title, |
854 'id' => 'new-content', |
762 'href' => admin_url( current( array_keys( $actions ) ) ), |
855 'title' => $title, |
763 ) ); |
856 'href' => admin_url( current( array_keys( $actions ) ) ), |
|
857 ) |
|
858 ); |
764 |
859 |
765 foreach ( $actions as $link => $action ) { |
860 foreach ( $actions as $link => $action ) { |
766 list( $title, $id ) = $action; |
861 list( $title, $id ) = $action; |
767 |
862 |
768 $wp_admin_bar->add_menu( array( |
863 $wp_admin_bar->add_menu( |
769 'parent' => 'new-content', |
864 array( |
770 'id' => $id, |
865 'parent' => 'new-content', |
771 'title' => $title, |
866 'id' => $id, |
772 'href' => admin_url( $link ) |
867 'title' => $title, |
773 ) ); |
868 'href' => admin_url( $link ), |
|
869 ) |
|
870 ); |
774 } |
871 } |
775 } |
872 } |
776 |
873 |
777 /** |
874 /** |
778 * Add edit comments link with awaiting moderation count bubble. |
875 * Add edit comments link with awaiting moderation count bubble. |
780 * @since 3.1.0 |
877 * @since 3.1.0 |
781 * |
878 * |
782 * @param WP_Admin_Bar $wp_admin_bar |
879 * @param WP_Admin_Bar $wp_admin_bar |
783 */ |
880 */ |
784 function wp_admin_bar_comments_menu( $wp_admin_bar ) { |
881 function wp_admin_bar_comments_menu( $wp_admin_bar ) { |
785 if ( !current_user_can('edit_posts') ) |
882 if ( ! current_user_can( 'edit_posts' ) ) { |
786 return; |
883 return; |
787 |
884 } |
788 $awaiting_mod = wp_count_comments(); |
885 |
789 $awaiting_mod = $awaiting_mod->moderated; |
886 $awaiting_mod = wp_count_comments(); |
790 $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); |
887 $awaiting_mod = $awaiting_mod->moderated; |
791 |
888 $awaiting_text = sprintf( |
792 $icon = '<span class="ab-icon"></span>'; |
889 /* translators: %s: number of comments in moderation */ |
793 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
890 _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), |
794 $title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>'; |
891 number_format_i18n( $awaiting_mod ) |
795 |
892 ); |
796 $wp_admin_bar->add_menu( array( |
893 |
797 'id' => 'comments', |
894 $icon = '<span class="ab-icon"></span>'; |
798 'title' => $icon . $title, |
895 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
799 'href' => admin_url('edit-comments.php'), |
896 $title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>'; |
800 ) ); |
897 |
|
898 $wp_admin_bar->add_menu( |
|
899 array( |
|
900 'id' => 'comments', |
|
901 'title' => $icon . $title, |
|
902 'href' => admin_url( 'edit-comments.php' ), |
|
903 ) |
|
904 ); |
801 } |
905 } |
802 |
906 |
803 /** |
907 /** |
804 * Add appearance submenu items to the "Site Name" menu. |
908 * Add appearance submenu items to the "Site Name" menu. |
805 * |
909 * |
806 * @since 3.1.0 |
910 * @since 3.1.0 |
807 * |
911 * |
808 * @param WP_Admin_Bar $wp_admin_bar |
912 * @param WP_Admin_Bar $wp_admin_bar |
809 */ |
913 */ |
810 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
914 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
811 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); |
915 $wp_admin_bar->add_group( |
|
916 array( |
|
917 'parent' => 'site-name', |
|
918 'id' => 'appearance', |
|
919 ) |
|
920 ); |
812 |
921 |
813 if ( current_user_can( 'switch_themes' ) ) { |
922 if ( current_user_can( 'switch_themes' ) ) { |
814 $wp_admin_bar->add_menu( array( |
923 $wp_admin_bar->add_menu( |
815 'parent' => 'appearance', |
924 array( |
816 'id' => 'themes', |
925 'parent' => 'appearance', |
817 'title' => __( 'Themes' ), |
926 'id' => 'themes', |
818 'href' => admin_url( 'themes.php' ), |
927 'title' => __( 'Themes' ), |
819 ) ); |
928 'href' => admin_url( 'themes.php' ), |
|
929 ) |
|
930 ); |
820 } |
931 } |
821 |
932 |
822 if ( ! current_user_can( 'edit_theme_options' ) ) { |
933 if ( ! current_user_can( 'edit_theme_options' ) ) { |
823 return; |
934 return; |
824 } |
935 } |
825 |
936 |
826 if ( current_theme_supports( 'widgets' ) ) { |
937 if ( current_theme_supports( 'widgets' ) ) { |
827 $wp_admin_bar->add_menu( array( |
938 $wp_admin_bar->add_menu( |
828 'parent' => 'appearance', |
939 array( |
829 'id' => 'widgets', |
940 'parent' => 'appearance', |
830 'title' => __( 'Widgets' ), |
941 'id' => 'widgets', |
831 'href' => admin_url( 'widgets.php' ), |
942 'title' => __( 'Widgets' ), |
832 ) ); |
943 'href' => admin_url( 'widgets.php' ), |
833 } |
944 ) |
834 |
945 ); |
835 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) |
946 } |
836 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); |
947 |
|
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 } |
837 |
958 |
838 if ( current_theme_supports( 'custom-background' ) ) { |
959 if ( current_theme_supports( 'custom-background' ) ) { |
839 $wp_admin_bar->add_menu( array( |
960 $wp_admin_bar->add_menu( |
840 'parent' => 'appearance', |
961 array( |
841 'id' => 'background', |
962 'parent' => 'appearance', |
842 'title' => __( 'Background' ), |
963 'id' => 'background', |
843 'href' => admin_url( 'themes.php?page=custom-background' ), |
964 'title' => __( 'Background' ), |
844 'meta' => array( |
965 'href' => admin_url( 'themes.php?page=custom-background' ), |
845 'class' => 'hide-if-customize', |
966 'meta' => array( |
|
967 'class' => 'hide-if-customize', |
|
968 ), |
|
969 ) |
|
970 ); |
|
971 } |
|
972 |
|
973 if ( current_theme_supports( 'custom-header' ) ) { |
|
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 ); |
|
985 } |
|
986 |
|
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 |
|
1000 if ( ! $update_data['counts']['total'] ) { |
|
1001 return; |
|
1002 } |
|
1003 |
|
1004 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; |
|
1005 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; |
|
1006 |
|
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'], |
846 ), |
1014 ), |
847 ) ); |
1015 ) |
848 } |
1016 ); |
849 |
|
850 if ( current_theme_supports( 'custom-header' ) ) { |
|
851 $wp_admin_bar->add_menu( array( |
|
852 'parent' => 'appearance', |
|
853 'id' => 'header', |
|
854 'title' => __( 'Header' ), |
|
855 'href' => admin_url( 'themes.php?page=custom-header' ), |
|
856 'meta' => array( |
|
857 'class' => 'hide-if-customize', |
|
858 ), |
|
859 ) ); |
|
860 } |
|
861 |
|
862 } |
|
863 |
|
864 /** |
|
865 * Provide an update link if theme/plugin/core updates are available. |
|
866 * |
|
867 * @since 3.1.0 |
|
868 * |
|
869 * @param WP_Admin_Bar $wp_admin_bar |
|
870 */ |
|
871 function wp_admin_bar_updates_menu( $wp_admin_bar ) { |
|
872 |
|
873 $update_data = wp_get_update_data(); |
|
874 |
|
875 if ( !$update_data['counts']['total'] ) |
|
876 return; |
|
877 |
|
878 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; |
|
879 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; |
|
880 |
|
881 $wp_admin_bar->add_menu( array( |
|
882 'id' => 'updates', |
|
883 'title' => $title, |
|
884 'href' => network_admin_url( 'update-core.php' ), |
|
885 'meta' => array( |
|
886 'title' => $update_data['title'], |
|
887 ), |
|
888 ) ); |
|
889 } |
1017 } |
890 |
1018 |
891 /** |
1019 /** |
892 * Add search form. |
1020 * Add search form. |
893 * |
1021 * |
894 * @since 3.3.0 |
1022 * @since 3.3.0 |
895 * |
1023 * |
896 * @param WP_Admin_Bar $wp_admin_bar |
1024 * @param WP_Admin_Bar $wp_admin_bar |
897 */ |
1025 */ |
898 function wp_admin_bar_search_menu( $wp_admin_bar ) { |
1026 function wp_admin_bar_search_menu( $wp_admin_bar ) { |
899 if ( is_admin() ) |
1027 if ( is_admin() ) { |
900 return; |
1028 return; |
|
1029 } |
901 |
1030 |
902 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; |
1031 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; |
903 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; |
1032 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; |
904 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>'; |
1033 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>'; |
905 $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>'; |
1034 $form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '"/>'; |
906 $form .= '</form>'; |
1035 $form .= '</form>'; |
907 |
1036 |
908 $wp_admin_bar->add_menu( array( |
1037 $wp_admin_bar->add_menu( |
909 'parent' => 'top-secondary', |
1038 array( |
910 'id' => 'search', |
1039 'parent' => 'top-secondary', |
911 'title' => $form, |
1040 'id' => 'search', |
912 'meta' => array( |
1041 'title' => $form, |
913 'class' => 'admin-bar-search', |
1042 'meta' => array( |
914 'tabindex' => -1, |
1043 'class' => 'admin-bar-search', |
915 ) |
1044 'tabindex' => -1, |
916 ) ); |
1045 ), |
|
1046 ) |
|
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 ); |
917 } |
1074 } |
918 |
1075 |
919 /** |
1076 /** |
920 * Add secondary menus. |
1077 * Add secondary menus. |
921 * |
1078 * |
922 * @since 3.3.0 |
1079 * @since 3.3.0 |
923 * |
1080 * |
924 * @param WP_Admin_Bar $wp_admin_bar |
1081 * @param WP_Admin_Bar $wp_admin_bar |
925 */ |
1082 */ |
926 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
1083 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
927 $wp_admin_bar->add_group( array( |
1084 $wp_admin_bar->add_group( |
928 'id' => 'top-secondary', |
1085 array( |
929 'meta' => array( |
1086 'id' => 'top-secondary', |
930 'class' => 'ab-top-secondary', |
1087 'meta' => array( |
931 ), |
1088 'class' => 'ab-top-secondary', |
932 ) ); |
1089 ), |
933 |
1090 ) |
934 $wp_admin_bar->add_group( array( |
1091 ); |
935 'parent' => 'wp-logo', |
1092 |
936 'id' => 'wp-logo-external', |
1093 $wp_admin_bar->add_group( |
937 'meta' => array( |
1094 array( |
938 'class' => 'ab-sub-secondary', |
1095 'parent' => 'wp-logo', |
939 ), |
1096 'id' => 'wp-logo-external', |
940 ) ); |
1097 'meta' => array( |
|
1098 'class' => 'ab-sub-secondary', |
|
1099 ), |
|
1100 ) |
|
1101 ); |
941 } |
1102 } |
942 |
1103 |
943 /** |
1104 /** |
944 * Style and scripts for the admin bar. |
1105 * Style and scripts for the admin bar. |
945 * |
1106 * |
946 * @since 3.1.0 |
1107 * @since 3.1.0 |
947 */ |
1108 */ |
948 function wp_admin_bar_header() { ?> |
1109 function wp_admin_bar_header() { |
|
1110 ?> |
949 <style type="text/css" media="print">#wpadminbar { display:none; }</style> |
1111 <style type="text/css" media="print">#wpadminbar { display:none; }</style> |
950 <?php |
1112 <?php |
951 } |
1113 } |
952 |
1114 |
953 /** |
1115 /** |
954 * Default admin bar callback. |
1116 * Default admin bar callback. |
955 * |
1117 * |
956 * @since 3.1.0 |
1118 * @since 3.1.0 |
957 */ |
1119 */ |
958 function _admin_bar_bump_cb() { ?> |
1120 function _admin_bar_bump_cb() { |
|
1121 |
|
1122 ?> |
959 <style type="text/css" media="screen"> |
1123 <style type="text/css" media="screen"> |
960 html { margin-top: 32px !important; } |
1124 html { margin-top: 32px !important; } |
961 * html body { margin-top: 32px !important; } |
1125 * html body { margin-top: 32px !important; } |
962 @media screen and ( max-width: 782px ) { |
1126 @media screen and ( max-width: 782px ) { |
963 html { margin-top: 46px !important; } |
1127 html { margin-top: 46px !important; } |
964 * html body { margin-top: 46px !important; } |
1128 * html body { margin-top: 46px !important; } |
965 } |
1129 } |
966 </style> |
1130 </style> |
967 <?php |
1131 <?php |
968 } |
1132 } |
969 |
1133 |
970 /** |
1134 /** |
971 * Sets the display status of the admin bar. |
1135 * Sets the display status of the admin bar. |
972 * |
1136 * |