diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/admin-bar.php --- a/wp/wp-includes/admin-bar.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/admin-bar.php Tue Dec 15 13:49:49 2020 +0100 @@ -28,7 +28,7 @@ } /* Load the admin bar class code ready for instantiation */ - require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' ); + require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; /* Instantiate the admin bar */ @@ -55,8 +55,11 @@ /** * Renders the admin bar to the page based on the $wp_admin_bar->menu member var. * - * This is called very late on the footer actions so that it will render after - * anything else being added to the footer. + * This is called very early on the {@see 'wp_body_open'} action so that it will render + * before anything else being added to the page body. + * + * For backward compatibility with themes not using the 'wp_body_open' action, + * the function is also called late on {@see 'wp_footer'}. * * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and * add new menus to the admin bar. That way you can be sure that you are adding at most @@ -64,11 +67,17 @@ * the `$post` global, among others. * * @since 3.1.0 + * @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback. * * @global WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_render() { global $wp_admin_bar; + static $rendered = false; + + if ( $rendered ) { + return; + } if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { return; @@ -100,6 +109,8 @@ * @since 3.1.0 */ do_action( 'wp_after_admin_bar_render' ); + + $rendered = true; } /** @@ -131,11 +142,11 @@ ); } - $wp_admin_bar->add_menu( $wp_logo_menu_args ); + $wp_admin_bar->add_node( $wp_logo_menu_args ); if ( $about_url ) { - // Add "About WordPress" link - $wp_admin_bar->add_menu( + // Add "About WordPress" link. + $wp_admin_bar->add_node( array( 'parent' => 'wp-logo', 'id' => 'about', @@ -145,8 +156,8 @@ ); } - // Add WordPress.org link - $wp_admin_bar->add_menu( + // Add WordPress.org link. + $wp_admin_bar->add_node( array( 'parent' => 'wp-logo-external', 'id' => 'wporg', @@ -155,8 +166,8 @@ ) ); - // Add codex link - $wp_admin_bar->add_menu( + // Add Codex link. + $wp_admin_bar->add_node( array( 'parent' => 'wp-logo-external', 'id' => 'documentation', @@ -165,8 +176,8 @@ ) ); - // Add forums link - $wp_admin_bar->add_menu( + // Add forums link. + $wp_admin_bar->add_node( array( 'parent' => 'wp-logo-external', 'id' => 'support-forums', @@ -175,8 +186,8 @@ ) ); - // Add feedback link - $wp_admin_bar->add_menu( + // Add feedback link. + $wp_admin_bar->add_node( array( 'parent' => 'wp-logo-external', 'id' => 'feedback', @@ -195,7 +206,7 @@ */ function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { if ( is_admin() ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'menu-toggle', 'title' => '' . __( 'Menu' ) . '', @@ -229,11 +240,11 @@ } $avatar = get_avatar( $user_id, 26 ); - /* translators: %s: current user's display name */ + /* translators: %s: Current user's display name. */ $howdy = sprintf( __( 'Howdy, %s' ), '' . $current_user->display_name . '' ); $class = empty( $avatar ) ? '' : 'with-avatar'; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'my-account', 'parent' => 'top-secondary', @@ -283,7 +294,7 @@ $user_info .= "{$current_user->user_login}"; } - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'user-info', @@ -296,17 +307,17 @@ ); if ( false !== $profile_url ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'edit-profile', - 'title' => __( 'Edit My Profile' ), + 'title' => __( 'Edit Profile' ), 'href' => $profile_url, ) ); } - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'logout', @@ -341,16 +352,16 @@ } if ( is_network_admin() ) { - /* translators: %s: site name */ + /* translators: %s: Site title. */ $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); } elseif ( is_user_admin() ) { - /* translators: %s: site name */ + /* translators: %s: Site title. */ $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); } $title = wp_html_excerpt( $blogname, 40, '…' ); - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'site-name', 'title' => $title, @@ -362,7 +373,7 @@ if ( is_admin() ) { // Add an option to visit the site. - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'site-name', 'id' => 'view-site', @@ -372,7 +383,7 @@ ); if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'site-name', 'id' => 'edit-site', @@ -383,7 +394,7 @@ } } elseif ( current_user_can( 'read' ) ) { // We're on the front end, link to the Dashboard. - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'site-name', 'id' => 'dashboard', @@ -414,7 +425,9 @@ } // Don't show if the user cannot edit a given customize_changeset post currently being previewed. - 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() ) ) { + 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() ) + ) { return; } @@ -428,7 +441,7 @@ $customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url ); } - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'customize', 'title' => __( 'Customize' ), @@ -465,7 +478,7 @@ $my_sites_url = admin_url( 'my-sites.php' ); } - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'my-sites', 'title' => __( 'My Sites' ), @@ -481,7 +494,7 @@ ) ); - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'my-sites-super-admin', 'id' => 'network-admin', @@ -490,7 +503,7 @@ ) ); - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'network-admin', 'id' => 'network-admin-d', @@ -500,7 +513,7 @@ ); if ( current_user_can( 'manage_sites' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'network-admin', 'id' => 'network-admin-s', @@ -511,7 +524,7 @@ } if ( current_user_can( 'manage_network_users' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'network-admin', 'id' => 'network-admin-u', @@ -522,7 +535,7 @@ } if ( current_user_can( 'manage_network_themes' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'network-admin', 'id' => 'network-admin-t', @@ -533,7 +546,7 @@ } if ( current_user_can( 'manage_network_plugins' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'network-admin', 'id' => 'network-admin-p', @@ -544,7 +557,7 @@ } if ( current_user_can( 'manage_network_options' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'network-admin', 'id' => 'network-admin-o', @@ -555,7 +568,7 @@ } } - // Add site links + // Add site links. $wp_admin_bar->add_group( array( 'parent' => 'my-sites', @@ -580,7 +593,7 @@ $menu_id = 'blog-' . $blog->userblog_id; if ( current_user_can( 'read' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'my-sites-list', 'id' => $menu_id, @@ -589,7 +602,7 @@ ) ); - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => $menu_id, 'id' => $menu_id . '-d', @@ -598,7 +611,7 @@ ) ); } else { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'my-sites-list', 'id' => $menu_id, @@ -609,7 +622,7 @@ } if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => $menu_id, 'id' => $menu_id . '-n', @@ -620,7 +633,7 @@ } if ( current_user_can( 'edit_posts' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => $menu_id, 'id' => $menu_id . '-c', @@ -630,7 +643,7 @@ ); } - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => $menu_id, 'id' => $menu_id . '-v', @@ -660,7 +673,7 @@ $html = ''; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => $id, 'title' => __( 'Shortlink' ), @@ -676,28 +689,41 @@ * @since 3.1.0 * * @global WP_Term $tag - * @global WP_Query $wp_the_query + * @global WP_Query $wp_the_query WordPress Query object. * @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. + * @global int $post_id The ID of the post when editing comments for a single post. * * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_edit_menu( $wp_admin_bar ) { - global $tag, $wp_the_query, $user_id; + global $tag, $wp_the_query, $user_id, $post_id; if ( is_admin() ) { - $current_screen = get_current_screen(); - $post = get_post(); + $current_screen = get_current_screen(); + $post = get_post(); + $post_type_object = null; - if ( 'post' == $current_screen->base - && 'add' != $current_screen->action - && ( $post_type_object = get_post_type_object( $post->post_type ) ) + if ( 'post' === $current_screen->base ) { + $post_type_object = get_post_type_object( $post->post_type ); + } elseif ( 'edit' === $current_screen->base ) { + $post_type_object = get_post_type_object( $current_screen->post_type ); + } elseif ( 'edit-comments' === $current_screen->base && $post_id ) { + $post = get_post( $post_id ); + if ( $post ) { + $post_type_object = get_post_type_object( $post->post_type ); + } + } + + if ( ( 'post' === $current_screen->base || 'edit-comments' === $current_screen->base ) + && 'add' !== $current_screen->action + && ( $post_type_object ) && current_user_can( 'read_post', $post->ID ) && ( $post_type_object->public ) && ( $post_type_object->show_in_admin_bar ) ) { - if ( 'draft' == $post->post_status ) { + if ( 'draft' === $post->post_status ) { $preview_link = get_preview_post_link( $post ); - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'preview', 'title' => $post_type_object->labels->view_item, @@ -706,7 +732,7 @@ ) ); } else { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'view', 'title' => $post_type_object->labels->view_item, @@ -714,8 +740,8 @@ ) ); } - } elseif ( 'edit' == $current_screen->base - && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) + } elseif ( 'edit' === $current_screen->base + && ( $post_type_object ) && ( $post_type_object->public ) && ( $post_type_object->show_in_admin_bar ) && ( get_post_type_archive_link( $post_type_object->name ) ) @@ -727,29 +753,29 @@ '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 ) ) - && 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, - ) - ); + } elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) { + $tax = get_taxonomy( $tag->taxonomy ); + if ( is_taxonomy_viewable( $tax ) ) { + $wp_admin_bar->add_node( + 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 ); + $view_link = get_author_posts_url( $user_object->ID ); + if ( $user_object->exists() && $view_link ) { + $wp_admin_bar->add_node( + array( + 'id' => 'view', + 'title' => __( 'View User' ), + 'href' => $view_link, + ) + ); + } } } else { $current_object = $wp_the_query->get_queried_object(); @@ -758,39 +784,44 @@ 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, - ) - ); - } 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, - ) - ); - } 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, - ) - ); + if ( ! empty( $current_object->post_type ) ) { + $post_type_object = get_post_type_object( $current_object->post_type ); + $edit_post_link = get_edit_post_link( $current_object->ID ); + if ( $post_type_object + && $edit_post_link + && current_user_can( 'edit_post', $current_object->ID ) + && $post_type_object->show_in_admin_bar ) { + $wp_admin_bar->add_node( + 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 ); + $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ); + if ( $tax && $edit_term_link && current_user_can( 'edit_term', $current_object->term_id ) ) { + $wp_admin_bar->add_node( + 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 ); + if ( $edit_user_link ) { + $wp_admin_bar->add_node( + array( + 'id' => 'edit', + 'title' => __( 'Edit User' ), + 'href' => $edit_user_link, + ) + ); + } } } } @@ -849,7 +880,7 @@ $title = '' . _x( 'New', 'admin bar menu group label' ) . ''; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'new-content', 'title' => $title, @@ -860,7 +891,7 @@ foreach ( $actions as $link => $action ) { list( $title, $id ) = $action; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'new-content', 'id' => $id, @@ -886,7 +917,7 @@ $awaiting_mod = wp_count_comments(); $awaiting_mod = $awaiting_mod->moderated; $awaiting_text = sprintf( - /* translators: %s: number of comments in moderation */ + /* translators: %s: Number of comments. */ _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); @@ -895,7 +926,7 @@ $title = ''; $title .= '' . $awaiting_text . ''; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'comments', 'title' => $icon . $title, @@ -920,7 +951,7 @@ ); if ( current_user_can( 'switch_themes' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'themes', @@ -935,7 +966,7 @@ } if ( current_theme_supports( 'widgets' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'widgets', @@ -946,7 +977,7 @@ } if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'menus', @@ -957,7 +988,7 @@ } if ( current_theme_supports( 'custom-background' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'background', @@ -971,7 +1002,7 @@ } if ( current_theme_supports( 'custom-header' ) ) { - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'header', @@ -1004,7 +1035,7 @@ $title = '' . number_format_i18n( $update_data['counts']['total'] ) . ''; $title .= '' . $update_data['title'] . ''; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'id' => 'updates', 'title' => $title, @@ -1034,7 +1065,7 @@ $form .= ''; $form .= ''; - $wp_admin_bar->add_menu( + $wp_admin_bar->add_node( array( 'parent' => 'top-secondary', 'id' => 'search', @@ -1063,7 +1094,7 @@ $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( + $wp_admin_bar->add_node( array( 'parent' => 'top-secondary', 'id' => 'recovery-mode', @@ -1107,8 +1138,9 @@ * @since 3.1.0 */ function wp_admin_bar_header() { + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; ?> - + media="print">#wpadminbar { display:none; } -