diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/admin-bar.php --- a/wp/wp-includes/admin-bar.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/admin-bar.php Mon Oct 14 18:28:13 2019 +0200 @@ -23,8 +23,9 @@ function _wp_admin_bar_init() { global $wp_admin_bar; - if ( ! is_admin_bar_showing() ) + if ( ! is_admin_bar_showing() ) { return false; + } /* Load the admin bar class code ready for instantiation */ require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' ); @@ -39,10 +40,11 @@ * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'. */ $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); - if ( class_exists( $admin_bar_class ) ) + if ( class_exists( $admin_bar_class ) ) { $wp_admin_bar = new $admin_bar_class; - else + } else { return false; + } $wp_admin_bar->initialize(); $wp_admin_bar->add_menus(); @@ -68,8 +70,9 @@ function wp_admin_bar_render() { global $wp_admin_bar; - if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) + if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { return; + } /** * Load all necessary admin bar items. @@ -132,45 +135,55 @@ if ( $about_url ) { // Add "About WordPress" link - $wp_admin_bar->add_menu( array( - 'parent' => 'wp-logo', - 'id' => 'about', - 'title' => __('About WordPress'), - 'href' => $about_url, - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'wp-logo', + 'id' => 'about', + 'title' => __( 'About WordPress' ), + 'href' => $about_url, + ) + ); } // Add WordPress.org link - $wp_admin_bar->add_menu( array( - 'parent' => 'wp-logo-external', - 'id' => 'wporg', - 'title' => __('WordPress.org'), - 'href' => __('https://wordpress.org/'), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'wp-logo-external', + 'id' => 'wporg', + 'title' => __( 'WordPress.org' ), + 'href' => __( 'https://wordpress.org/' ), + ) + ); // Add codex link - $wp_admin_bar->add_menu( array( - 'parent' => 'wp-logo-external', - 'id' => 'documentation', - 'title' => __('Documentation'), - 'href' => __('https://codex.wordpress.org/'), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'wp-logo-external', + 'id' => 'documentation', + 'title' => __( 'Documentation' ), + 'href' => __( 'https://codex.wordpress.org/' ), + ) + ); // Add forums link - $wp_admin_bar->add_menu( array( - 'parent' => 'wp-logo-external', - 'id' => 'support-forums', - 'title' => __('Support Forums'), - 'href' => __('https://wordpress.org/support/'), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'wp-logo-external', + 'id' => 'support-forums', + 'title' => __( 'Support' ), + 'href' => __( 'https://wordpress.org/support/' ), + ) + ); // Add feedback link - $wp_admin_bar->add_menu( array( - 'parent' => 'wp-logo-external', - 'id' => 'feedback', - 'title' => __('Feedback'), - 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'wp-logo-external', + 'id' => 'feedback', + 'title' => __( 'Feedback' ), + 'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), + ) + ); } /** @@ -182,11 +195,13 @@ */ function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { if ( is_admin() ) { - $wp_admin_bar->add_menu( array( - 'id' => 'menu-toggle', - 'title' => '' . __( 'Menu' ) . '', - 'href' => '#', - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'menu-toggle', + 'title' => '' . __( 'Menu' ) . '', + 'href' => '#', + ) + ); } } @@ -201,8 +216,9 @@ $user_id = get_current_user_id(); $current_user = wp_get_current_user(); - if ( ! $user_id ) + if ( ! $user_id ) { return; + } if ( current_user_can( 'read' ) ) { $profile_url = get_edit_profile_url( $user_id ); @@ -214,18 +230,20 @@ $avatar = get_avatar( $user_id, 26 ); /* translators: %s: current user's display name */ - $howdy = sprintf( __( 'Howdy, %s' ), '' . $current_user->display_name . '' ); - $class = empty( $avatar ) ? '' : 'with-avatar'; + $howdy = sprintf( __( 'Howdy, %s' ), '' . $current_user->display_name . '' ); + $class = empty( $avatar ) ? '' : 'with-avatar'; - $wp_admin_bar->add_menu( array( - 'id' => 'my-account', - 'parent' => 'top-secondary', - 'title' => $howdy . $avatar, - 'href' => $profile_url, - 'meta' => array( - 'class' => $class, - ), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'my-account', + 'parent' => 'top-secondary', + 'title' => $howdy . $avatar, + 'href' => $profile_url, + 'meta' => array( + 'class' => $class, + ), + ) + ); } /** @@ -239,8 +257,9 @@ $user_id = get_current_user_id(); $current_user = wp_get_current_user(); - if ( ! $user_id ) + if ( ! $user_id ) { return; + } if ( current_user_can( 'read' ) ) { $profile_url = get_edit_profile_url( $user_id ); @@ -250,42 +269,51 @@ $profile_url = false; } - $wp_admin_bar->add_group( array( - 'parent' => 'my-account', - 'id' => 'user-actions', - ) ); + $wp_admin_bar->add_group( + array( + 'parent' => 'my-account', + 'id' => 'user-actions', + ) + ); $user_info = get_avatar( $user_id, 64 ); $user_info .= "{$current_user->display_name}"; - if ( $current_user->display_name !== $current_user->user_login ) + if ( $current_user->display_name !== $current_user->user_login ) { $user_info .= "{$current_user->user_login}"; + } - $wp_admin_bar->add_menu( array( - 'parent' => 'user-actions', - 'id' => 'user-info', - 'title' => $user_info, - 'href' => $profile_url, - 'meta' => array( - 'tabindex' => -1, - ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'user-actions', + 'id' => 'user-info', + 'title' => $user_info, + 'href' => $profile_url, + 'meta' => array( + 'tabindex' => -1, + ), + ) + ); if ( false !== $profile_url ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'user-actions', - 'id' => 'edit-profile', - 'title' => __( 'Edit My Profile' ), - 'href' => $profile_url, - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'user-actions', + 'id' => 'edit-profile', + 'title' => __( 'Edit My Profile' ), + 'href' => $profile_url, + ) + ); } - $wp_admin_bar->add_menu( array( - 'parent' => 'user-actions', - 'id' => 'logout', - 'title' => __( 'Log Out' ), - 'href' => wp_logout_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'user-actions', + 'id' => 'logout', + 'title' => __( 'Log Out' ), + 'href' => wp_logout_url(), + ) + ); } /** @@ -297,15 +325,16 @@ */ function wp_admin_bar_site_menu( $wp_admin_bar ) { // Don't show for logged out users. - if ( ! is_user_logged_in() ) + if ( ! is_user_logged_in() ) { return; + } // Show only when the user is a member of this site, or they're a super admin. if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) { return; } - $blogname = get_bloginfo('name'); + $blogname = get_bloginfo( 'name' ); if ( ! $blogname ) { $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); @@ -321,40 +350,47 @@ $title = wp_html_excerpt( $blogname, 40, '…' ); - $wp_admin_bar->add_menu( array( - 'id' => 'site-name', - 'title' => $title, - 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'site-name', + 'title' => $title, + 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), + ) + ); // Create submenu items. if ( is_admin() ) { // Add an option to visit the site. - $wp_admin_bar->add_menu( array( - 'parent' => 'site-name', - 'id' => 'view-site', - 'title' => __( 'Visit Site' ), - 'href' => home_url( '/' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'site-name', + 'id' => 'view-site', + 'title' => __( 'Visit Site' ), + 'href' => home_url( '/' ), + ) + ); if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'site-name', - 'id' => 'edit-site', - 'title' => __( 'Edit Site' ), - 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'site-name', + 'id' => 'edit-site', + 'title' => __( 'Edit Site' ), + 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), + ) + ); } - - } else if ( current_user_can( 'read' ) ) { + } elseif ( current_user_can( 'read' ) ) { // We're on the front end, link to the Dashboard. - $wp_admin_bar->add_menu( array( - 'parent' => 'site-name', - 'id' => 'dashboard', - 'title' => __( 'Dashboard' ), - 'href' => admin_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'site-name', + 'id' => 'dashboard', + 'title' => __( 'Dashboard' ), + 'href' => admin_url(), + ) + ); // Add the appearance submenu items. wp_admin_bar_appearance_menu( $wp_admin_bar ); @@ -392,14 +428,16 @@ $customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url ); } - $wp_admin_bar->add_menu( array( - 'id' => 'customize', - 'title' => __( 'Customize' ), - 'href' => $customize_url, - 'meta' => array( - 'class' => 'hide-if-no-customize', - ), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'customize', + 'title' => __( 'Customize' ), + 'href' => $customize_url, + 'meta' => array( + 'class' => 'hide-if-no-customize', + ), + ) + ); add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); } @@ -412,8 +450,9 @@ */ function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { // Don't show for logged out users or single site mode. - if ( ! is_user_logged_in() || ! is_multisite() ) + if ( ! is_user_logged_in() || ! is_multisite() ) { return; + } // Show only when the user has at least one site, or they're a super admin. if ( count( $wp_admin_bar->user->blogs ) < 1 && ! current_user_can( 'manage_network' ) ) { @@ -426,86 +465,106 @@ $my_sites_url = admin_url( 'my-sites.php' ); } - $wp_admin_bar->add_menu( array( - 'id' => 'my-sites', - 'title' => __( 'My Sites' ), - 'href' => $my_sites_url, - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'my-sites', + 'title' => __( 'My Sites' ), + 'href' => $my_sites_url, + ) + ); if ( current_user_can( 'manage_network' ) ) { - $wp_admin_bar->add_group( array( - 'parent' => 'my-sites', - 'id' => 'my-sites-super-admin', - ) ); + $wp_admin_bar->add_group( + array( + 'parent' => 'my-sites', + 'id' => 'my-sites-super-admin', + ) + ); - $wp_admin_bar->add_menu( array( - 'parent' => 'my-sites-super-admin', - 'id' => 'network-admin', - 'title' => __('Network Admin'), - 'href' => network_admin_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'my-sites-super-admin', + 'id' => 'network-admin', + 'title' => __( 'Network Admin' ), + 'href' => network_admin_url(), + ) + ); - $wp_admin_bar->add_menu( array( - 'parent' => 'network-admin', - 'id' => 'network-admin-d', - 'title' => __( 'Dashboard' ), - 'href' => network_admin_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'network-admin', + 'id' => 'network-admin-d', + 'title' => __( 'Dashboard' ), + 'href' => network_admin_url(), + ) + ); if ( current_user_can( 'manage_sites' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'network-admin', - 'id' => 'network-admin-s', - 'title' => __( 'Sites' ), - 'href' => network_admin_url( 'sites.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'network-admin', + 'id' => 'network-admin-s', + 'title' => __( 'Sites' ), + 'href' => network_admin_url( 'sites.php' ), + ) + ); } if ( current_user_can( 'manage_network_users' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'network-admin', - 'id' => 'network-admin-u', - 'title' => __( 'Users' ), - 'href' => network_admin_url( 'users.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'network-admin', + 'id' => 'network-admin-u', + 'title' => __( 'Users' ), + 'href' => network_admin_url( 'users.php' ), + ) + ); } if ( current_user_can( 'manage_network_themes' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'network-admin', - 'id' => 'network-admin-t', - 'title' => __( 'Themes' ), - 'href' => network_admin_url( 'themes.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'network-admin', + 'id' => 'network-admin-t', + 'title' => __( 'Themes' ), + 'href' => network_admin_url( 'themes.php' ), + ) + ); } if ( current_user_can( 'manage_network_plugins' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'network-admin', - 'id' => 'network-admin-p', - 'title' => __( 'Plugins' ), - 'href' => network_admin_url( 'plugins.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'network-admin', + 'id' => 'network-admin-p', + 'title' => __( 'Plugins' ), + 'href' => network_admin_url( 'plugins.php' ), + ) + ); } if ( current_user_can( 'manage_network_options' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'network-admin', - 'id' => 'network-admin-o', - 'title' => __( 'Settings' ), - 'href' => network_admin_url( 'settings.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'network-admin', + 'id' => 'network-admin-o', + 'title' => __( 'Settings' ), + 'href' => network_admin_url( 'settings.php' ), + ) + ); } } // Add site links - $wp_admin_bar->add_group( array( - 'parent' => 'my-sites', - 'id' => 'my-sites-list', - 'meta' => array( - 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', - ), - ) ); + $wp_admin_bar->add_group( + array( + 'parent' => 'my-sites', + 'id' => 'my-sites-list', + 'meta' => array( + 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', + ), + ) + ); foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { switch_to_blog( $blog->userblog_id ); @@ -518,55 +577,67 @@ $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); } - $menu_id = 'blog-' . $blog->userblog_id; + $menu_id = 'blog-' . $blog->userblog_id; if ( current_user_can( 'read' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'my-sites-list', - 'id' => $menu_id, - 'title' => $blavatar . $blogname, - 'href' => admin_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'my-sites-list', + 'id' => $menu_id, + 'title' => $blavatar . $blogname, + 'href' => admin_url(), + ) + ); - $wp_admin_bar->add_menu( array( - 'parent' => $menu_id, - 'id' => $menu_id . '-d', - 'title' => __( 'Dashboard' ), - 'href' => admin_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => $menu_id, + 'id' => $menu_id . '-d', + 'title' => __( 'Dashboard' ), + 'href' => admin_url(), + ) + ); } else { - $wp_admin_bar->add_menu( array( - 'parent' => 'my-sites-list', - 'id' => $menu_id, - 'title' => $blavatar . $blogname, - 'href' => home_url(), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'my-sites-list', + 'id' => $menu_id, + 'title' => $blavatar . $blogname, + 'href' => home_url(), + ) + ); } if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => $menu_id, - 'id' => $menu_id . '-n', - 'title' => __( 'New Post' ), - 'href' => admin_url( 'post-new.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => $menu_id, + 'id' => $menu_id . '-n', + 'title' => get_post_type_object( 'post' )->labels->new_item, + 'href' => admin_url( 'post-new.php' ), + ) + ); } if ( current_user_can( 'edit_posts' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => $menu_id, - 'id' => $menu_id . '-c', - 'title' => __( 'Manage Comments' ), - 'href' => admin_url( 'edit-comments.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => $menu_id, + 'id' => $menu_id . '-c', + 'title' => __( 'Manage Comments' ), + 'href' => admin_url( 'edit-comments.php' ), + ) + ); } - $wp_admin_bar->add_menu( array( - 'parent' => $menu_id, - 'id' => $menu_id . '-v', - 'title' => __( 'Visit Site' ), - 'href' => home_url( '/' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => $menu_id, + 'id' => $menu_id . '-v', + 'title' => __( 'Visit Site' ), + 'href' => home_url( '/' ), + ) + ); restore_current_blog(); } @@ -581,19 +652,22 @@ */ function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { $short = wp_get_shortlink( 0, 'query' ); - $id = 'get-shortlink'; + $id = 'get-shortlink'; - if ( empty( $short ) ) + if ( empty( $short ) ) { return; + } $html = ''; - $wp_admin_bar->add_menu( array( - 'id' => $id, - 'title' => __( 'Shortlink' ), - 'href' => $short, - 'meta' => array( 'html' => $html ), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => $id, + 'title' => __( 'Shortlink' ), + 'href' => $short, + 'meta' => array( 'html' => $html ), + ) + ); } /** @@ -603,6 +677,8 @@ * * @global WP_Term $tag * @global WP_Query $wp_the_query + * @global int $user_id The ID of the user being edited. Not to be confused with the + * global $user_ID, which contains the ID of the current user. * * @param WP_Admin_Bar $wp_admin_bar */ @@ -611,100 +687,110 @@ if ( is_admin() ) { $current_screen = get_current_screen(); - $post = get_post(); + $post = get_post(); if ( 'post' == $current_screen->base && 'add' != $current_screen->action && ( $post_type_object = get_post_type_object( $post->post_type ) ) && current_user_can( 'read_post', $post->ID ) && ( $post_type_object->public ) - && ( $post_type_object->show_in_admin_bar ) ) - { + && ( $post_type_object->show_in_admin_bar ) ) { if ( 'draft' == $post->post_status ) { $preview_link = get_preview_post_link( $post ); - $wp_admin_bar->add_menu( array( - 'id' => 'preview', - 'title' => $post_type_object->labels->view_item, - 'href' => esc_url( $preview_link ), - 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'preview', + 'title' => $post_type_object->labels->view_item, + 'href' => esc_url( $preview_link ), + 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), + ) + ); } else { - $wp_admin_bar->add_menu( array( - 'id' => 'view', - 'title' => $post_type_object->labels->view_item, - 'href' => get_permalink( $post->ID ) - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'view', + 'title' => $post_type_object->labels->view_item, + 'href' => get_permalink( $post->ID ), + ) + ); } } elseif ( 'edit' == $current_screen->base - && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) - && ( $post_type_object->public ) - && ( $post_type_object->show_in_admin_bar ) - && ( get_post_type_archive_link( $post_type_object->name ) ) - && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) - { - $wp_admin_bar->add_node( array( - 'id' => 'archive', - 'title' => $post_type_object->labels->view_items, - 'href' => get_post_type_archive_link( $current_screen->post_type ) - ) ); + && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) + && ( $post_type_object->public ) + && ( $post_type_object->show_in_admin_bar ) + && ( get_post_type_archive_link( $post_type_object->name ) ) + && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { + $wp_admin_bar->add_node( + array( + 'id' => 'archive', + 'title' => $post_type_object->labels->view_items, + 'href' => get_post_type_archive_link( $current_screen->post_type ), + ) + ); } elseif ( 'term' == $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) && ( $tax = get_taxonomy( $tag->taxonomy ) ) - && $tax->public ) - { - $wp_admin_bar->add_menu( array( - 'id' => 'view', - 'title' => $tax->labels->view_item, - 'href' => get_term_link( $tag ) - ) ); + && is_taxonomy_viewable( $tax ) ) { + $wp_admin_bar->add_menu( + array( + 'id' => 'view', + 'title' => $tax->labels->view_item, + 'href' => get_term_link( $tag ), + ) + ); } elseif ( 'user-edit' == $current_screen->base && isset( $user_id ) && ( $user_object = get_userdata( $user_id ) ) && $user_object->exists() - && $view_link = get_author_posts_url( $user_object->ID ) ) - { - $wp_admin_bar->add_menu( array( - 'id' => 'view', - 'title' => __( 'View User' ), - 'href' => $view_link, - ) ); + && $view_link = get_author_posts_url( $user_object->ID ) ) { + $wp_admin_bar->add_menu( + array( + 'id' => 'view', + 'title' => __( 'View User' ), + 'href' => $view_link, + ) + ); } } else { $current_object = $wp_the_query->get_queried_object(); - if ( empty( $current_object ) ) + if ( empty( $current_object ) ) { return; + } if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && current_user_can( 'edit_post', $current_object->ID ) && $post_type_object->show_in_admin_bar - && $edit_post_link = get_edit_post_link( $current_object->ID ) ) - { - $wp_admin_bar->add_menu( array( - 'id' => 'edit', - 'title' => $post_type_object->labels->edit_item, - 'href' => $edit_post_link - ) ); + && $edit_post_link = get_edit_post_link( $current_object->ID ) ) { + $wp_admin_bar->add_menu( + array( + 'id' => 'edit', + 'title' => $post_type_object->labels->edit_item, + 'href' => $edit_post_link, + ) + ); } elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( 'edit_term', $current_object->term_id ) - && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) - { - $wp_admin_bar->add_menu( array( - 'id' => 'edit', - 'title' => $tax->labels->edit_item, - 'href' => $edit_term_link - ) ); + && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) { + $wp_admin_bar->add_menu( + array( + 'id' => 'edit', + 'title' => $tax->labels->edit_item, + 'href' => $edit_term_link, + ) + ); } elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) - && $edit_user_link = get_edit_user_link( $current_object->ID ) ) - { - $wp_admin_bar->add_menu( array( - 'id' => 'edit', - 'title' => __( 'Edit User' ), - 'href' => $edit_user_link, - ) ); + && $edit_user_link = get_edit_user_link( $current_object->ID ) ) { + $wp_admin_bar->add_menu( + array( + 'id' => 'edit', + 'title' => __( 'Edit User' ), + 'href' => $edit_user_link, + ) + ); } } } @@ -721,56 +807,67 @@ $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); - if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) - $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); + if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) { + $actions['post-new.php'] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); + } - if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) - $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); + if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) { + $actions['media-new.php'] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); + } - if ( current_user_can( 'manage_links' ) ) - $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); + if ( current_user_can( 'manage_links' ) ) { + $actions['link-add.php'] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); + } - if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) - $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); + if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) { + $actions['post-new.php?post_type=page'] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); + } unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); // Add any additional custom post types. foreach ( $cpts as $cpt ) { - if ( ! current_user_can( $cpt->cap->create_posts ) ) + if ( ! current_user_can( $cpt->cap->create_posts ) ) { continue; + } - $key = 'post-new.php?post_type=' . $cpt->name; + $key = 'post-new.php?post_type=' . $cpt->name; $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); } // Avoid clash with parent node and a 'content' post type. - if ( isset( $actions['post-new.php?post_type=content'] ) ) + if ( isset( $actions['post-new.php?post_type=content'] ) ) { $actions['post-new.php?post_type=content'][1] = 'add-new-content'; + } if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { - $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); + $actions['user-new.php'] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); } - if ( ! $actions ) + if ( ! $actions ) { return; + } $title = '' . _x( 'New', 'admin bar menu group label' ) . ''; - $wp_admin_bar->add_menu( array( - 'id' => 'new-content', - 'title' => $title, - 'href' => admin_url( current( array_keys( $actions ) ) ), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'new-content', + 'title' => $title, + 'href' => admin_url( current( array_keys( $actions ) ) ), + ) + ); foreach ( $actions as $link => $action ) { list( $title, $id ) = $action; - $wp_admin_bar->add_menu( array( - 'parent' => 'new-content', - 'id' => $id, - 'title' => $title, - 'href' => admin_url( $link ) - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'new-content', + 'id' => $id, + 'title' => $title, + 'href' => admin_url( $link ), + ) + ); } } @@ -782,22 +879,29 @@ * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_comments_menu( $wp_admin_bar ) { - if ( !current_user_can('edit_posts') ) + if ( ! current_user_can( 'edit_posts' ) ) { return; + } - $awaiting_mod = wp_count_comments(); - $awaiting_mod = $awaiting_mod->moderated; - $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); + $awaiting_mod = wp_count_comments(); + $awaiting_mod = $awaiting_mod->moderated; + $awaiting_text = sprintf( + /* translators: %s: number of comments in moderation */ + _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), + number_format_i18n( $awaiting_mod ) + ); - $icon = ''; - $title = ''; - $title .= '' . $awaiting_text . ''; + $icon = ''; + $title = ''; + $title .= '' . $awaiting_text . ''; - $wp_admin_bar->add_menu( array( - 'id' => 'comments', - 'title' => $icon . $title, - 'href' => admin_url('edit-comments.php'), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'comments', + 'title' => $icon . $title, + 'href' => admin_url( 'edit-comments.php' ), + ) + ); } /** @@ -808,55 +912,76 @@ * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_appearance_menu( $wp_admin_bar ) { - $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); + $wp_admin_bar->add_group( + array( + 'parent' => 'site-name', + 'id' => 'appearance', + ) + ); if ( current_user_can( 'switch_themes' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'appearance', - 'id' => 'themes', - 'title' => __( 'Themes' ), - 'href' => admin_url( 'themes.php' ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'appearance', + 'id' => 'themes', + 'title' => __( 'Themes' ), + 'href' => admin_url( 'themes.php' ), + ) + ); } if ( ! current_user_can( 'edit_theme_options' ) ) { return; } - if ( current_theme_supports( 'widgets' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'appearance', - 'id' => 'widgets', - 'title' => __( 'Widgets' ), - 'href' => admin_url( 'widgets.php' ), - ) ); + if ( current_theme_supports( 'widgets' ) ) { + $wp_admin_bar->add_menu( + array( + 'parent' => 'appearance', + 'id' => 'widgets', + 'title' => __( 'Widgets' ), + 'href' => admin_url( 'widgets.php' ), + ) + ); } - if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) - $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); + if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { + $wp_admin_bar->add_menu( + array( + 'parent' => 'appearance', + 'id' => 'menus', + 'title' => __( 'Menus' ), + 'href' => admin_url( 'nav-menus.php' ), + ) + ); + } if ( current_theme_supports( 'custom-background' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'appearance', - 'id' => 'background', - 'title' => __( 'Background' ), - 'href' => admin_url( 'themes.php?page=custom-background' ), - 'meta' => array( - 'class' => 'hide-if-customize', - ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'appearance', + 'id' => 'background', + 'title' => __( 'Background' ), + 'href' => admin_url( 'themes.php?page=custom-background' ), + 'meta' => array( + 'class' => 'hide-if-customize', + ), + ) + ); } if ( current_theme_supports( 'custom-header' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => 'appearance', - 'id' => 'header', - 'title' => __( 'Header' ), - 'href' => admin_url( 'themes.php?page=custom-header' ), - 'meta' => array( - 'class' => 'hide-if-customize', - ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'appearance', + 'id' => 'header', + 'title' => __( 'Header' ), + 'href' => admin_url( 'themes.php?page=custom-header' ), + 'meta' => array( + 'class' => 'hide-if-customize', + ), + ) + ); } } @@ -872,20 +997,23 @@ $update_data = wp_get_update_data(); - if ( !$update_data['counts']['total'] ) + if ( ! $update_data['counts']['total'] ) { return; + } - $title = '' . number_format_i18n( $update_data['counts']['total'] ) . ''; + $title = '' . number_format_i18n( $update_data['counts']['total'] ) . ''; $title .= '' . $update_data['title'] . ''; - $wp_admin_bar->add_menu( array( - 'id' => 'updates', - 'title' => $title, - 'href' => network_admin_url( 'update-core.php' ), - 'meta' => array( - 'title' => $update_data['title'], - ), - ) ); + $wp_admin_bar->add_menu( + array( + 'id' => 'updates', + 'title' => $title, + 'href' => network_admin_url( 'update-core.php' ), + 'meta' => array( + 'title' => $update_data['title'], + ), + ) + ); } /** @@ -896,24 +1024,53 @@ * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_search_menu( $wp_admin_bar ) { - if ( is_admin() ) + if ( is_admin() ) { return; + } $form = '
'; $form .= ''; $form .= ''; - $form .= ''; + $form .= ''; $form .= '
'; - $wp_admin_bar->add_menu( array( - 'parent' => 'top-secondary', - 'id' => 'search', - 'title' => $form, - 'meta' => array( - 'class' => 'admin-bar-search', - 'tabindex' => -1, + $wp_admin_bar->add_menu( + array( + 'parent' => 'top-secondary', + 'id' => 'search', + 'title' => $form, + 'meta' => array( + 'class' => 'admin-bar-search', + 'tabindex' => -1, + ), ) - ) ); + ); +} + +/** + * Add a link to exit recovery mode when Recovery Mode is active. + * + * @since 5.2.0 + * + * @param WP_Admin_Bar $wp_admin_bar + */ +function wp_admin_bar_recovery_mode_menu( $wp_admin_bar ) { + if ( ! wp_is_recovery_mode() ) { + return; + } + + $url = wp_login_url(); + $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url ); + $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION ); + + $wp_admin_bar->add_menu( + array( + 'parent' => 'top-secondary', + 'id' => 'recovery-mode', + 'title' => __( 'Exit Recovery Mode' ), + 'href' => $url, + ) + ); } /** @@ -924,20 +1081,24 @@ * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { - $wp_admin_bar->add_group( array( - 'id' => 'top-secondary', - 'meta' => array( - 'class' => 'ab-top-secondary', - ), - ) ); + $wp_admin_bar->add_group( + array( + 'id' => 'top-secondary', + 'meta' => array( + 'class' => 'ab-top-secondary', + ), + ) + ); - $wp_admin_bar->add_group( array( - 'parent' => 'wp-logo', - 'id' => 'wp-logo-external', - 'meta' => array( - 'class' => 'ab-sub-secondary', - ), - ) ); + $wp_admin_bar->add_group( + array( + 'parent' => 'wp-logo', + 'id' => 'wp-logo-external', + 'meta' => array( + 'class' => 'ab-sub-secondary', + ), + ) + ); } /** @@ -945,9 +1106,10 @@ * * @since 3.1.0 */ -function wp_admin_bar_header() { ?> +function wp_admin_bar_header() { + ?> - +function _admin_bar_bump_cb() { + + ?> -