wp_admin_bar_edit_menu

The timeline below displays how wordpress function wp_admin_bar_edit_menu has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Provides an edit link for posts and terms.
 *
 * @since 3.1.0
 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post.
 *
 * @global WP_Term  $tag
 * @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 The WP_Admin_Bar instance.
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id, $post_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        $post_type_object = null;
        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) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_node(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_node(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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) && !('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);
            if (is_term_publicly_viewable($tag)) {
                $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();
        if (empty($current_object)) {
            return;
        }
        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 ($current_object instanceof 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));
            }
        }
    }
}

WordPress Version: 6.1

/**
 * Provides an edit link for posts and terms.
 *
 * @since 3.1.0
 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post.
 *
 * @global WP_Term  $tag
 * @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 The WP_Admin_Bar instance.
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id, $post_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        $post_type_object = null;
        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) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_node(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_node(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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) && !('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);
            if (is_term_publicly_viewable($tag)) {
                $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();
        if (empty($current_object)) {
            return;
        }
        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));
            }
        }
    }
}

WordPress Version: 5.9

/**
 * Provides an edit link for posts and terms.
 *
 * @since 3.1.0
 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post.
 *
 * @global WP_Term  $tag
 * @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 The WP_Admin_Bar instance.
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id, $post_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        $post_type_object = null;
        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) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_node(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_node(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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) && !('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);
            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();
        if (empty($current_object)) {
            return;
        }
        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));
            }
        }
    }
}

WordPress Version: 5.8

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post.
 *
 * @global WP_Term  $tag
 * @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, $post_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        $post_type_object = null;
        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) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_node(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_node(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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) && !('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);
            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();
        if (empty($current_object)) {
            return;
        }
        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));
            }
        }
    }
}

WordPress Version: 5.5

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @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, $post_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        $post_type_object = null;
        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) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_node(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_node(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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) && !('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);
            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();
        if (empty($current_object)) {
            return;
        }
        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));
            }
        }
    }
}

WordPress Version: 5.4

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @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.
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        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);
        }
        if ('post' == $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) {
                $preview_link = get_preview_post_link($post);
                $wp_admin_bar->add_node(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_node(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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) && !('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);
            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();
        if (empty($current_object)) {
            return;
        }
        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));
            }
        }
    }
}

WordPress Version: 5.3

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @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.
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $post = get_post();
        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);
        }
        if ('post' == $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) {
                $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)));
            } else {
                $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 && $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);
            if (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);
            $view_link = get_author_posts_url($user_object->ID);
            if ($user_object->exists() && $view_link) {
                $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)) {
            return;
        }
        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_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);
            $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_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);
            if ($edit_user_link) {
                $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => __('Edit User'), 'href' => $edit_user_link));
            }
        }
    }
}

WordPress Version: 5.1

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @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
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            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)));
            } else {
                $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)));
        } 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));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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));
        } 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));
        }
    }
}

WordPress Version: 4.9

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @global WP_Query $wp_the_query
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query, $user_id;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            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)));
            } else {
                $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)));
        } 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)));
        } 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));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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));
        } 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));
        }
    }
}

WordPress Version: 4.7

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @global WP_Query $wp_the_query
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            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)));
            } else {
                $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)));
        } 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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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));
        } 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));
        }
    }
}

WordPress Version: 4.5

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @global WP_Query $wp_the_query
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            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)));
            } else {
                $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } 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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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));
        } elseif (!empty($current_object->taxonomy) && ($tax = get_taxonomy($current_object->taxonomy)) && current_user_can($tax->cap->edit_terms) && $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));
        }
    }
}

WordPress Version: 4.4

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global WP_Term  $tag
 * @global WP_Query $wp_the_query
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            if ('draft' == $post->post_status) {
                $draft_link = set_url_scheme(get_permalink($post->ID));
                $preview_link = get_preview_post_link($post, array(), $draft_link);
                $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)));
            }
        } elseif ('edit-tags' == $current_screen->base && isset($tag) && is_object($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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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));
        } elseif (!empty($current_object->taxonomy) && ($tax = get_taxonomy($current_object->taxonomy)) && current_user_can($tax->cap->edit_terms) && $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));
        }
    }
}

WordPress Version: 4.3

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @global object   $tag
 * @global WP_Query $wp_the_query
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            if ('draft' == $post->post_status) {
                $preview_link = set_url_scheme(get_permalink($post->ID));
                /** This filter is documented in wp-admin/includes/meta-boxes.php */
                $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_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)));
            } else {
                $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } elseif ('edit-tags' == $current_screen->base && isset($tag) && is_object($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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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_ui && $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($tax->cap->edit_terms) && $tax->show_ui && $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));
        }
    }
}

WordPress Version: 4.1

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            if ('draft' == $post->post_status) {
                $preview_link = set_url_scheme(get_permalink($post->ID));
                /** This filter is documented in wp-admin/includes/meta-boxes.php */
                $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_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)));
            } else {
                $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } elseif ('edit-tags' == $current_screen->base && isset($tag) && is_object($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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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_ui && $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($tax->cap->edit_terms) && $tax->show_ui && $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));
        }
    }
}

WordPress Version: 4.0

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            if ('draft' == $post->post_status) {
                $preview_link = set_url_scheme(get_permalink($post->ID));
                /** This filter is documented in wp-admin/includes/meta-boxes.php */
                $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_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)));
            } else {
                $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
            }
        } elseif ('edit-tags' == $current_screen->base && isset($tag) && is_object($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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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_ui && $post_type_object->show_in_admin_bar) {
            $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => $post_type_object->labels->edit_item, 'href' => get_edit_post_link($current_object->ID)));
        } elseif (!empty($current_object->taxonomy) && ($tax = get_taxonomy($current_object->taxonomy)) && current_user_can($tax->cap->edit_terms) && $tax->show_ui) {
            $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => $tax->labels->edit_item, 'href' => get_edit_term_link($current_object->term_id, $current_object->taxonomy)));
        }
    }
}

WordPress Version: 3.7

/**
 * Provide an edit link for posts and terms.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_edit_menu($wp_admin_bar)
{
    global $tag, $wp_the_query;
    if (is_admin()) {
        $current_screen = get_current_screen();
        $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) {
            $wp_admin_bar->add_menu(array('id' => 'view', 'title' => $post_type_object->labels->view_item, 'href' => get_permalink($post->ID)));
        } elseif ('edit-tags' == $current_screen->base && isset($tag) && is_object($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)));
        }
    } else {
        $current_object = $wp_the_query->get_queried_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_ui && $post_type_object->show_in_admin_bar) {
            $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => $post_type_object->labels->edit_item, 'href' => get_edit_post_link($current_object->ID)));
        } elseif (!empty($current_object->taxonomy) && ($tax = get_taxonomy($current_object->taxonomy)) && current_user_can($tax->cap->edit_terms) && $tax->show_ui) {
            $wp_admin_bar->add_menu(array('id' => 'edit', 'title' => $tax->labels->edit_item, 'href' => get_edit_term_link($current_object->term_id, $current_object->taxonomy)));
        }
    }
}