返回介绍

wp_admin_bar_edit_menu()

发布于 2017-09-11 11:21:03 字数 5012 浏览 817 评论 0 收藏 0

wp_admin_bar_edit_menu( WP_Admin_Bar $wp_admin_bar )

Provide an edit link for posts and terms.


description


参数

$wp_admin_bar

(WP_Admin_Bar) (Required)


源代码

File: wp-includes/admin-bar.php

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
			) );
		}
	}
}

更新日志

Versiondescription
3.1.0Introduced.

相关函数

Uses

  • wp-includes/link-template.php: get_preview_post_link()
  • wp-admin/includes/screen.php: get_current_screen()
  • wp-includes/capabilities.php: current_user_can()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/load.php: is_admin()
  • wp-includes/taxonomy.php: get_term_link()
  • wp-includes/taxonomy.php: get_taxonomy()
  • wp-includes/link-template.php: get_post_type_archive_link()
  • wp-includes/link-template.php: get_edit_post_link()
  • wp-includes/link-template.php: get_edit_term_link()
  • wp-includes/link-template.php: get_permalink()
  • wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::add_menu()
  • wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::add_node()
  • wp-includes/option.php: get_option()
  • wp-includes/post.php: get_post()
  • wp-includes/post.php: get_post_type_object()
  • wp-includes/load.php: is_wp_error()
  • Show 12 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文