wp_ajax_menu_get_metabox() - WordPress 函数参考中文文档

返回介绍

wp_ajax_menu_get_metabox()

发布于 2017-09-11 字数2402 浏览 907 评论 0

wp_ajax_menu_get_metabox()

Ajax handler for retrieving menu meta boxes.


描述


源代码

File: wp-admin/includes/ajax-actions.php

function wp_ajax_menu_get_metabox() {
	if ( ! current_user_can( 'edit_theme_options' ) )
		wp_die( -1 );

	require_once ABSPATH . 'wp-admin/includes/nav-menu.php';

	if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) {
		$type = 'posttype';
		$callback = 'wp_nav_menu_item_post_type_meta_box';
		$items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
	} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) {
		$type = 'taxonomy';
		$callback = 'wp_nav_menu_item_taxonomy_meta_box';
		$items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
	}

	if ( ! empty( $_POST['item-object'] ) && isset( $items[$_POST['item-object']] ) ) {
		$menus_meta_box_object = $items[ $_POST['item-object'] ];

		/** This filter is documented in wp-admin/includes/nav-menu.php */
		$item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object );
		ob_start();
		call_user_func_array($callback, array(
			null,
			array(
				'id' => 'add-' . $item->name,
				'title' => $item->labels->name,
				'callback' => $callback,
				'args' => $item,
			)
		));

		$markup = ob_get_clean();

		echo wp_json_encode(array(
			'replace-id' => $type . '-' . $item->name,
			'markup' => $markup,
		));
	}

	wp_die();
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    wp_json_encode()
  • wp-admin/includes/nav-menu.php:
    nav_menu_meta_box_object
  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/functions.php:
    wp_die()
  • wp-includes/taxonomy.php:
    get_taxonomies()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post.php:
    get_post_types()
  • Show 2 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!