本文整理汇总了PHP中wp_setup_nav_menu_item函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_setup_nav_menu_item函数的具体用法?PHP wp_setup_nav_menu_item怎么用?PHP wp_setup_nav_menu_item使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_setup_nav_menu_item函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($menu_term_slug)
{
parent::__construct();
$menu = wp_get_nav_menu_object($menu_term_slug);
if (!empty($menu)) {
$this->menu = $menu;
$nav_menu_items = wp_get_nav_menu_items($this->menu->term_id);
cfd_tmp_dbg('nav_menu_items_raw.txt', $nav_menu_items, 'print');
foreach ($nav_menu_items as $item) {
$menu_item = wp_setup_nav_menu_item($item);
$menu_item->metadata = get_metadata('post', $item->ID);
foreach ($menu_item->metadata as $key => &$value) {
$value[0] = maybe_unserialize($value[0]);
}
if ($menu_item->type == 'post_type') {
$menu_item->parent = get_post($menu_item->metadata['_menu_item_object_id'][0]);
} elseif ($menu_item->type == 'taxonomy' && (!property_exists($menu, 'object') || $menu->object != 'custom')) {
$menu_item->term = get_term($menu_item->metadata['_menu_item_object_id'][0], $menu_item->metadata['_menu_item_object'][0]);
}
$this->items[] = $menu_item;
}
} else {
throw new Exception(__('Invalid menu id', 'cf-deploy') . ': ' . esc_attr($menu_term_slug));
}
}
开发者ID:niko-lgdcom,项目名称:wp-install,代码行数:25,代码来源:menu.class.php
示例2: ajax_add_to_menu
/**
* Ajax callback for our menu items
*
* @wordpress-action wp_ajax_buggypress_add_to_menu
* @return void Exits the program on completion
*/
public function ajax_add_to_menu()
{
check_ajax_referer('buggypress-menu', 'buggypress_nonce');
if (empty($_POST['menu_items'])) {
die('-1');
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
$menu_items = $_POST['menu_items'];
$item_ids = array();
foreach ($menu_items as $item) {
$item_ids[] = $this->add_menu_item($item);
}
if (is_wp_error($item_ids)) {
die('-1');
}
// Set up menu items
$output_menu_items = array();
foreach ($item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
$menu_obj->label = $menu_obj->title;
// don't show "(pending)" in ajax-added items
$menu_obj->type_label = 'BuggyPress';
$output_menu_items[] = $menu_obj;
}
}
// build the HTML output
if (!empty($output_menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new Walker_Nav_Menu_Edit());
echo walk_nav_menu_tree($output_menu_items, 0, (object) $args);
}
exit;
}
开发者ID:jbrinley,项目名称:BuggyPress,代码行数:40,代码来源:BuggyPress_Menus.php
示例3: test_orphan_nav_menu_item
/**
* @ticket 27113
*/
function test_orphan_nav_menu_item()
{
// Create an orphan nav menu item
$custom_item_id = wp_update_nav_menu_item(0, 0, array('menu-item-type' => 'custom', 'menu-item-title' => 'Wordpress.org', 'menu-item-link' => 'http://wordpress.org', 'menu-item-status' => 'publish'));
// Confirm it saved properly
$custom_item = wp_setup_nav_menu_item(get_post($custom_item_id));
$this->assertEquals('Wordpress.org', $custom_item->title);
// Update the orphan with an associated nav menu
wp_update_nav_menu_item($this->menu_id, $custom_item_id, array('menu-item-title' => 'WordPress.org'));
$menu_items = wp_get_nav_menu_items($this->menu_id);
$custom_item = wp_filter_object_list($menu_items, array('db_id' => $custom_item_id));
$custom_item = array_pop($custom_item);
$this->assertEquals('WordPress.org', $custom_item->title);
}
开发者ID:Benrajalu,项目名称:philRaj,代码行数:17,代码来源:nav-menu.php
示例4: theme_get_list_menu
function theme_get_list_menu($args = array())
{
global $wp_query;
$menu_items = wp_get_nav_menu_items($args['menu']->term_id);
if (empty($menu_items)) {
return '';
}
$home_page_id = (int) get_option('page_for_posts');
$queried_object = $wp_query->get_queried_object();
$queried_object_id = (int) $wp_query->queried_object_id;
$active_ID = null;
$IdToKey = array();
foreach ((array) $menu_items as $key => $menu_item) {
$IdToKey[$menu_item->ID] = $key;
if ($menu_item->object_id == $queried_object_id && (!empty($home_page_id) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id || 'post_type' == $menu_item->type && $wp_query->is_singular || 'taxonomy' == $menu_item->type && ($wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax))) {
$active_ID = $menu_item->ID;
} elseif ('custom' == $menu_item->object) {
if (theme_is_current_url($menu_item->url)) {
$active_ID = $menu_item->ID;
}
}
}
$current_ID = $active_ID;
while ($current_ID && isset($IdToKey[$current_ID])) {
$activeIDs[] = $current_ID;
$current_item =& $menu_items[$IdToKey[$current_ID]];
$current_item->classes[] = 'active';
$current_ID = $current_item->menu_item_parent;
}
$sorted_menu_items = array();
foreach ((array) $menu_items as $key => $menu_item) {
$sorted_menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item($menu_item);
}
$items = array();
foreach ($sorted_menu_items as $el) {
$id = $el->db_id;
$title = $el->title;
//Jordi
//$classes = empty($el->classes) ? array() : (array) $el->classes;
$classes = empty($el->classes) ? array('nav') : array_merge((array) $el->classes, array('nav'));
$active = in_array('active', $classes);
$items[] = new theme_MenuItem(array('id' => $id, 'active' => $active, 'attr' => array('title' => strip_tags(empty($el->attr_title) ? $title : $el->attr_title), 'target' => $el->target, 'rel' => $el->xfn, 'href' => $el->url, 'class' => join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $el))), 'title' => $title, 'parent' => $el->menu_item_parent));
}
$walker = new theme_MenuWalker();
$items = apply_filters('wp_nav_menu_objects', $items, $args);
$items = $walker->walk($items, $args);
$items = apply_filters('wp_nav_menu_items', $items, $args);
return apply_filters('wp_nav_menu', $items, $args);
}
开发者ID:JordiCruells,项目名称:mwt,代码行数:49,代码来源:navigation.php
示例5: sugarforms_menu_items
function sugarforms_menu_items($items)
{
// query sugarforms
$args = array('post_type' => 'sugarform', 'meta_key' => 'sugarform_display_menu', 'meta_value' => '1', 'meta_compare' => '=');
$loop = new WP_Query($args);
// add to menu
if ($loop->found_posts > 0) {
foreach ($loop->posts as $post) {
$new_item = wp_setup_nav_menu_item($post);
$items[] = $new_item;
//print_r($new_item);
}
}
return $items;
}
开发者ID:ThatWilsonNerd,项目名称:SugarPress,代码行数:15,代码来源:sugarpress.php
示例6: menu_customizer_add_item_ajax
/**
* Ajax handler for adding a menu item. Based on wp_ajax_add_menu_item().
*
* @since Menu Customizer 0.0.
*/
function menu_customizer_add_item_ajax()
{
check_ajax_referer('customize-menus', 'customize-menu-item-nonce');
if (!current_user_can('edit_theme_options')) {
wp_die(-1);
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
$menu_item_data = (array) $_POST['menu-item'];
$menu_id = absint($_POST['menu']);
// Used only for display, new item is created as an orphan - menu id of 0.
$id = 0;
// For performance reasons, we omit some object properties from the checklist.
// The following is a hacky way to restore them when adding non-custom items.
// @todo: do we really need this - do we need to populate the description field here?
if (!empty($menu_item_data['obj_type']) && 'custom' != $menu_item_data['obj_type'] && !empty($menu_item_data['id'])) {
switch ($menu_item_data['obj_type']) {
case 'post_type':
$id = absint(str_replace('post-', '', $menu_item_data['id']));
$_object = get_post($id);
break;
case 'taxonomy':
$id = absint(str_replace('term-', '', $menu_item_data['id']));
$_object = get_term($id, $menu_item_data['type']);
break;
}
$_menu_items = array_map('wp_setup_nav_menu_item', array($_object));
$_menu_item = array_shift($_menu_items);
// Restore the missing menu item properties
$menu_item_data['menu-item-description'] = $_menu_item->description;
}
// Make the "Home" item into the custom link that it actually is.
if ('page' == $menu_item_data['type'] && 'custom' == $menu_item_data['obj_type']) {
$menu_item_data['type'] = 'custom';
$menu_item_data['url'] = home_url('/');
}
// Map data from menu customizer keys to nav-menus.php keys.
$item_data = array('menu-item-db-id' => 0, 'menu-item-object-id' => $id, 'menu-item-object' => isset($menu_item_data['type']) ? $menu_item_data['type'] : '', 'menu-item-type' => isset($menu_item_data['obj_type']) ? $menu_item_data['obj_type'] : '', 'menu-item-title' => isset($menu_item_data['name']) ? $menu_item_data['name'] : '', 'menu-item-url' => isset($menu_item_data['url']) ? $menu_item_data['url'] : '', 'menu-item-description' => isset($menu_item_data['menu-item-description']) ? $menu_item_data['menu-item-description'] : '');
// `wp_save_nav_menu_items` requires `menu-item-db-id` to not be set for custom items.
if ('custom' == $item_data['menu-item-type']) {
unset($item_data['menu-item-db-id']);
}
$item_ids = wp_save_nav_menu_items(0, array(0 => $item_data));
if (is_wp_error($item_ids) || empty($item_ids)) {
wp_die(0);
}
$item = get_post($item_ids[0]);
if (!empty($item->ID)) {
$item = wp_setup_nav_menu_item($item);
$item->label = $item->title;
// Don't show "(pending)" in ajax-added items.
}
// Output the markup for this item.
menu_customizer_render_item_control($item, $menu_id, 0);
wp_die();
}
开发者ID:dauidus,项目名称:woof,代码行数:60,代码来源:menu-customize-ajax.php
示例7: ajax_add_menu_item
/**
* Ajax handler is triggered when
* something is added to the nav menu
* @ajax
*/
public function ajax_add_menu_item()
{
if (!tf_current_user_can(array('manage_options', 'edit_theme_options'), false)) {
die('-1');
}
check_ajax_referer('add-menu_item', 'menu-settings-column-nonce');
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
// For performance reasons, we omit some object properties from the checklist.
// The following is a hacky way to restore them when adding non-custom items.
$menu_items_data = array();
if ($this->request->POST('menu-item')) {
foreach ((array) $this->request->POST('menu-item') as $menu_item_data) {
if (!empty($menu_item_data['menu-item-type']) && 'custom' != $menu_item_data['menu-item-type'] && !empty($menu_item_data['menu-item-object-id'])) {
switch ($menu_item_data['menu-item-type']) {
case 'post_type':
$_object = get_post($menu_item_data['menu-item-object-id']);
break;
case 'taxonomy':
$_object = get_term($menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object']);
break;
}
$_menu_items = array_map('wp_setup_nav_menu_item', array($_object));
$_menu_item = array_shift($_menu_items);
// Restore the missing menu item properties
$menu_item_data['menu-item-description'] = $_menu_item->description;
}
$menu_items_data[] = $menu_item_data;
}
}
$item_ids = wp_save_nav_menu_items(0, $menu_items_data);
if (is_wp_error($item_ids)) {
die('-1');
}
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
$menu_obj->label = $menu_obj->title;
// don't show "(pending)" in ajax-added items
$menu_items[] = $menu_obj;
}
}
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new TF_ADMIN_MENU_WALKER());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
die;
}
开发者ID:pinchpointer,项目名称:ppsitewordpress,代码行数:53,代码来源:TF_MEGAMENU.php
示例8: wp_ajax_add_menu_item
function wp_ajax_add_menu_item()
{
check_ajax_referer('add-menu_item', 'menu-settings-column-nonce');
if (!current_user_can('edit_theme_options')) {
wp_die(-1);
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
$menu_items_data = array();
$search_keys = array();
foreach ((array) $_POST['menu-item'] as $k => $menu_item_data) {
if (!isset($menu_item_data['menu-item-type']) || $menu_item_data['menu-item-type'] !== 'search') {
continue;
}
$menu_item_data['menu-item-description'] = _x('Search box', 'menu-item-description', 'bop-nav-search-box-item');
$menu_items_data[] = $menu_item_data;
$search_keys[] = $k;
}
foreach ($search_keys as $k) {
unset($_POST['menu-item'][$k]);
}
if (!$menu_items_data) {
return;
}
$item_ids = wp_save_nav_menu_items(0, $menu_items_data);
if (is_wp_error($item_ids)) {
wp_die(0);
}
$menu_items = array();
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
$menu_obj->label = $menu_obj->title;
// don't show "(pending)" in ajax-added items
$menu_items[] = $menu_obj;
}
}
/**
* This filter is defined in wp-admin/includes/nav-menu.php
*
* @since 1.0.0
*/
$walker_class_name = apply_filters('wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu']);
if (!class_exists($walker_class_name)) {
wp_die(0);
}
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new $walker_class_name());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
if (!$_POST['menu-item']) {
wp_die();
}
}
开发者ID:beccarefford,项目名称:techgirlz-redesign,代码行数:54,代码来源:plugin.php
示例9: array
$dbids_to_orders = array();
$orders_to_dbids = array();
foreach ((array) $ordered_menu_items as $ordered_menu_item_object) {
if (isset($ordered_menu_item_object->ID)) {
if (isset($ordered_menu_item_object->menu_order)) {
$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
}
}
}
// if this menu item is not first
if (!empty($dbids_to_orders[$menu_item_id]) && !empty($orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1])) {
// if this menu item is a child of the previous
if (!empty($menu_item_data['menu_item_parent']) && in_array($menu_item_data['menu_item_parent'], array_keys($dbids_to_orders)) && isset($orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]) && $menu_item_data['menu_item_parent'] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]) {
$parent_db_id = in_array($menu_item_data['menu_item_parent'], $orders_to_dbids) ? (int) $menu_item_data['menu_item_parent'] : 0;
$parent_object = wp_setup_nav_menu_item(get_post($parent_db_id));
if (!is_wp_error($parent_object)) {
$parent_data = (array) $parent_object;
// if there is something before the parent and parent a child of it, make menu item a child also of it
if (!empty($dbids_to_orders[$parent_db_id]) && !empty($orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1]) && !empty($parent_data['menu_item_parent'])) {
$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
// else if there is something before parent and parent not a child of it, make menu item a child of that something's parent
} elseif (!empty($dbids_to_orders[$parent_db_id]) && !empty($orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1])) {
$_possible_parent_id = (int) get_post_meta($orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true);
if (in_array($_possible_parent_id, array_keys($dbids_to_orders))) {
$menu_item_data['menu_item_parent'] = $_possible_parent_id;
} else {
$menu_item_data['menu_item_parent'] = 0;
}
// else there isn't something before the parent
} else {
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:31,代码来源:nav-menus.php
示例10: ajax_add_post_type
/**
*
*/
function ajax_add_post_type()
{
if (!current_user_can('edit_theme_options')) {
die('-1');
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
if (empty($_POST['post_types'])) {
exit;
}
// Create menu items and store IDs in array
$item_ids = array();
foreach ((array) $_POST['post_types'] as $post_type) {
$post_type_obj = get_post_type_object($post_type);
if (!$post_type_obj) {
continue;
}
$menu_item_data = array('menu-item-title' => esc_attr($post_type_obj->labels->name), 'menu-item-type' => 'post_type_archive', 'menu-item-object' => esc_attr($post_type), 'menu-item-url' => get_post_type_archive_link($post_type));
//Collect the items' IDs.
$item_ids[] = wp_update_nav_menu_item(0, 0, $menu_item_data);
}
// If there was an error die here
if (is_wp_error($item_ids)) {
die('-1');
}
// Set up menu items
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
$menu_obj->label = $menu_obj->title;
// don't show "(pending)" in ajax-added items
$menu_items[] = $menu_obj;
}
}
// This gets the HTML to returns it to the menu
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new Walker_Nav_Menu_Edit());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
// Finally don't forget to exit
exit;
}
开发者ID:hoangsoft90,项目名称:hw-hoangweb-plugin,代码行数:45,代码来源:class-redrokk-post-class.php
示例11: ajax_add_multisite_page
public function ajax_add_multisite_page()
{
switch_to_blog($_POST['blogId']);
$post = get_post($_POST['ids'][0]);
$url = get_permalink($post->ID);
restore_current_blog();
$item_ids = wp_update_nav_menu_item(0, 0, array('menu-item-title' => esc_attr($post->post_title), 'menu-item-type' => 'custom', 'menu-item-url' => $url));
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
// don't show "(pending)" in ajax-added items
$menu_obj->label = $menu_obj->title;
$menu_items[] = $menu_obj;
}
}
// Needed to get the Walker up and running
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
// This gets the HTML to returns it to the menu
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new Walker_Nav_Menu_Edit());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
exit;
}
开发者ID:ryan2407,项目名称:Vision,代码行数:25,代码来源:index.php
示例12: test_sanitize
/**
* Test sanitize method.
*
* @see WP_Customize_Nav_Menu_Item_Setting::sanitize()
*/
function test_sanitize()
{
do_action('customize_register', $this->wp_customize);
$menu_id = wp_create_nav_menu('Primary');
$setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'nav_menu_item[123]');
$this->assertNull($setting->sanitize('not an array'));
$this->assertNull($setting->sanitize(123));
$unsanitized = array('object_id' => 'bad', 'object' => '<b>hello</b>', 'menu_item_parent' => 'asdasd', 'position' => -123, 'type' => 'custom<b>', 'title' => '\\o/ o\'o Hi<script>unfilteredHtml()</script>', 'url' => 'javascript:alert(1)', 'target' => '" onclick="', 'attr_title' => '\\o/ o\'o <b>bolded</b><script>unfilteredHtml()</script>', 'description' => '\\o/ o\'o <b>Hello world</b><script>unfilteredHtml()</script>', 'classes' => 'hello " inject="', 'xfn' => 'hello " inject="', 'status' => 'forbidden', 'original_title' => 'Hi<script>unfilteredHtml()</script>', 'nav_menu_term_id' => 'heilo', '_invalid' => false);
$expected_sanitized = array('object_id' => 0, 'object' => 'bhellob', 'menu_item_parent' => 0, 'position' => -123, 'type' => 'customb', 'title' => current_user_can('unfiltered_html') ? '\\o/ o\'o Hi<script>unfilteredHtml()</script>' : '\\o/ o\'o HiunfilteredHtml()', 'url' => '', 'target' => 'onclick', 'attr_title' => current_user_can('unfiltered_html') ? '\\o/ o\'o <b>bolded</b><script>unfilteredHtml()</script>' : '\\o/ o\'o <b>bolded</b>unfilteredHtml()', 'description' => current_user_can('unfiltered_html') ? '\\o/ o\'o <b>Hello world</b><script>unfilteredHtml()</script>' : '\\o/ o\'o <b>Hello world</b>unfilteredHtml()', 'classes' => 'hello inject', 'xfn' => 'hello inject', 'status' => 'draft', 'original_title' => 'Hi', 'nav_menu_term_id' => 0);
$sanitized = $setting->sanitize($unsanitized);
$this->assertEqualSets(array_keys($unsanitized), array_keys($sanitized));
foreach ($expected_sanitized as $key => $value) {
$this->assertEquals($value, $sanitized[$key], "Expected {$key} to be sanitized.");
}
$nav_menu_item_id = wp_update_nav_menu_item($menu_id, 0, wp_slash(array('menu-item-object-id' => $unsanitized['object_id'], 'menu-item-object' => $unsanitized['object'], 'menu-item-parent-id' => $unsanitized['menu_item_parent'], 'menu-item-position' => $unsanitized['position'], 'menu-item-type' => $unsanitized['type'], 'menu-item-title' => $unsanitized['title'], 'menu-item-url' => $unsanitized['url'], 'menu-item-description' => $unsanitized['description'], 'menu-item-attr-title' => $unsanitized['attr_title'], 'menu-item-target' => $unsanitized['target'], 'menu-item-classes' => $unsanitized['classes'], 'menu-item-xfn' => $unsanitized['xfn'], 'menu-item-status' => $unsanitized['status'])));
$post = get_post($nav_menu_item_id);
$nav_menu_item = wp_setup_nav_menu_item(clone $post);
$this->assertEquals($expected_sanitized['object_id'], $nav_menu_item->object_id);
$this->assertEquals($expected_sanitized['object'], $nav_menu_item->object);
$this->assertEquals($expected_sanitized['menu_item_parent'], $nav_menu_item->menu_item_parent);
$this->assertEquals($expected_sanitized['position'], $post->menu_order);
$this->assertEquals($expected_sanitized['type'], $nav_menu_item->type);
$this->assertEquals($expected_sanitized['title'], $post->post_title);
$this->assertEquals($expected_sanitized['url'], $nav_menu_item->url);
$this->assertEquals($expected_sanitized['description'], $post->post_content);
$this->assertEquals($expected_sanitized['attr_title'], $post->post_excerpt);
$this->assertEquals($expected_sanitized['target'], $nav_menu_item->target);
$this->assertEquals($expected_sanitized['classes'], implode(' ', $nav_menu_item->classes));
$this->assertEquals($expected_sanitized['xfn'], $nav_menu_item->xfn);
$this->assertEquals($expected_sanitized['status'], $post->post_status);
}
开发者ID:kucrut,项目名称:wordpress,代码行数:36,代码来源:nav-menu-item-setting.php
示例13: test_wp_setup_nav_menu_item_for_unknown_post_type_archive_no_description
/**
* @ticket 35324
*/
function test_wp_setup_nav_menu_item_for_unknown_post_type_archive_no_description()
{
$post_type_slug = rand_str(12);
$post_type_archive_item_id = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'post_type_archive', 'menu-item-object' => $post_type_slug, 'menu-item-status' => 'publish'));
$post_type_archive_item = wp_setup_nav_menu_item(get_post($post_type_archive_item_id));
$this->assertEmpty($post_type_archive_item->description);
}
开发者ID:pbearne,项目名称:contrib2core,代码行数:10,代码来源:nav-menu.php
示例14: ajax_add_year
/**
* AJAX Callback to create the menu item and add it to menu
* @return string $HTML built with walk_nav_menu_tree()
* use \Post_Type_Archive_Links::is_allowed() Check request and return choosen post types
*/
public function ajax_add_year()
{
$years = $this->is_allowed();
// Create menu items and store IDs in array
$item_ids = array();
$menu_item_data = array('menu-item-title' => esc_attr($years[0]), 'menu-item-type' => 'cyear_archive', 'menu-item-object' => esc_attr($years[0]), 'menu-item-url' => get_year_link($years[0]));
// Collect the items' IDs.
$item_ids[] = wp_update_nav_menu_item(0, 0, $menu_item_data);
// If there was an error die here
is_wp_error($item_ids) and die('-1');
// Set up menu items
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
// don't show "(pending)" in ajax-added items
$menu_obj->label = $menu_obj->title;
$menu_items[] = $menu_obj;
}
}
// Needed to get the Walker up and running
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
// This gets the HTML to returns it to the menu
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new Walker_Nav_Menu_Edit());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
// Finally don't forget to exit
exit;
}
开发者ID:OssprO,项目名称:current-year-archive-link,代码行数:35,代码来源:current-year-archive-links.php
示例15: test_value_nav_menu_term_id_returns_zero
/**
* Test value method returns zero for nav_menu_term_id when previewing a new menu.
*
* @see WP_Customize_Nav_Menu_Item_Setting::value()
*/
function test_value_nav_menu_term_id_returns_zero()
{
do_action('customize_register', $this->wp_customize);
$menu_id = -123;
$post_value = array('name' => 'Secondary', 'description' => '', 'parent' => 0, 'auto_add' => false);
$setting_id = "nav_menu[{$menu_id}]";
$menu = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id);
$this->wp_customize->set_post_value($menu->id, $post_value);
$menu->preview();
$value = $menu->value();
$this->assertEquals($post_value, $value);
$post_id = $this->factory->post->create(array('post_title' => 'Hello World'));
$item_id = wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-object' => 'post', 'menu-item-object-id' => $post_id, 'menu-item-title' => 'Hello World', 'menu-item-status' => 'publish'));
$post = get_post($item_id);
$menu_item = wp_setup_nav_menu_item($post);
$setting_id = "nav_menu_item[{$item_id}]";
$setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id);
$value = $setting->value();
$this->assertEquals(0, $value['nav_menu_term_id']);
}
开发者ID:plis197715,项目名称:wordpress-develop,代码行数:25,代码来源:nav-menu-item-setting.php
示例16: set_menu_item_meta
/**
* Set item meta data.
*
* @param WP_Post $menu_item
* @param int $blog_id
* @return WP_Post
*/
private function set_menu_item_meta($menu_item, $blog_id)
{
// don't show "(pending)" in ajax-added items
$menu_item->post_type = 'nav_menu_item';
$menu_item->url = get_home_url($blog_id, '/');
$menu_item->object = 'mlp_language';
$menu_item->xfn = 'alternate';
$menu_item = wp_setup_nav_menu_item($menu_item);
$menu_item->label = $menu_item->title;
// Replace the "Custom" in the management screen
$menu_item->type_label = esc_html__('Language', 'multilingualpress');
$menu_item->classes[] = "blog-id-{$blog_id}";
$menu_item->classes[] = "mlp-language-nav-item";
$menu_item->url = get_home_url($blog_id, '/');
update_post_meta($menu_item->ID, $this->meta_key, $blog_id);
$url = esc_url_raw(get_home_url($blog_id, '/'));
update_post_meta($menu_item->ID, '_menu_item_url', $url);
return $menu_item;
}
开发者ID:ycms,项目名称:multilingual-press,代码行数:26,代码来源:Mlp_Language_Nav_Menu_Data.php
示例17: getNavMenu
/**
* Called when generating a menu via `wp_nav_menu`
*
* You can have submenus automatically generated by passing 'auto_show_children'
* in the menu args.
*
* ```
* wp_get_nav_menu_items(
* $locations['main'],
* array('auto_show_children' => true)
* );
* ```
*
* @param array $items Items from `wp_get_nav_menu_items`
* @param array $menu Menu object
* @param array $args Args used in getting menu items
* @return array
* @see `wp_get_nav_menu_items`
*/
public function getNavMenu($items = array(), $menu = null, $args = array())
{
if (isset($args['auto_show_children']) && $args['auto_show_children']) {
$subMenus = array();
foreach ($items as $index => $item) {
if ($item->menu_item_parent) {
unset($items[$index]);
continue;
}
$children = get_children(array('post_parent' => $item->object_id, 'post_status' => 'publish', 'post_type' => 'page', 'orderby' => 'menu_order', 'order' => 'ASC'));
foreach ($children as &$child) {
$child = wp_setup_nav_menu_item($child);
$child->menu_item_parent = $item->ID;
$child->post_type = 'nav_menu_item';
$subMenus[] = $child;
}
}
$items = array_merge($items, $subMenus);
// restructure the menu based on the new items
foreach ($items as $index => &$item) {
$item->menu_order = $index;
}
}
return $items;
}
开发者ID:bsetter,项目名称:rockharbor,代码行数:44,代码来源:rockharbor_theme_base.php
示例18: avia_ajax_switch_menu_walker
function avia_ajax_switch_menu_walker()
{
if (!current_user_can('edit_theme_options')) {
die('-1');
}
check_ajax_referer('add-menu_item', 'menu-settings-column-nonce');
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
$item_ids = wp_save_nav_menu_items(0, $_POST['menu-item']);
if (is_wp_error($item_ids)) {
die('-1');
}
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
$menu_obj->label = $menu_obj->title;
// don't show "(pending)" in ajax-added items
$menu_items[] = $menu_obj;
}
}
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new avia_backend_walker());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
die('end');
}
开发者ID:erikdukker,项目名称:medisom,代码行数:26,代码来源:function-set-avia-ajax.php
示例19: array_map
}
$_menu_items = array_map('wp_setup_nav_menu_item', array($_object));
$_menu_item = array_shift($_menu_items);
// Restore the missing menu item properties
$menu_item_data['menu-item-description'] = $_menu_item->description;
}
$menu_items_data[] = $menu_item_data;
}
$item_ids = wp_save_nav_menu_items(0, $menu_items_data);
if (is_wp_error($item_ids)) {
die('-1');
}
foreach ((array) $item_ids as $menu_item_id) {
$menu_obj = get_post($menu_item_id);
if (!empty($menu_obj->ID)) {
$menu_obj = wp_setup_nav_menu_item($menu_obj);
$menu_obj->label = $menu_obj->title;
// don't show "(pending)" in ajax-added items
$menu_items[] = $menu_obj;
}
}
if (!empty($menu_items)) {
$args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new Walker_Nav_Menu_Edit());
echo walk_nav_menu_tree($menu_items, 0, (object) $args);
}
break;
case 'add-meta':
check_ajax_referer('add-meta', '_ajax_nonce-add-meta');
$c = 0;
$pid = (int) $_POST['post_id'];
$post = get_post($pid);
开发者ID:vivekkodira1,项目名称:wordpress,代码行数:31,代码来源:admin-ajax.php
示例20: wp_nav_menu
/**
* Displays a navigation menu.
*
* Optional $args contents:
*
* id - The menu id. Defaults to blank.
* slug - The menu slug. Defaults to blank.
* menu_class - CSS class to use for the div container of the menu list. Defaults to 'menu'.
* format - Whether to format the ul. Defaults to 'div'.
* fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'.
* before - Text before the link text.
* after - Text after the link text.
* link_before - Text before the link.
* link_after - Text after the link.
* echo - Whether to echo the menu or return it. Defaults to echo.
*
* @todo show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link.
*
* @since 3.0.0
*
* @param array $args Arguments
*/
function wp_nav_menu($args = array())
{
$defaults = array('menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'depth' => 0, 'walker' => '', 'context' => 'frontend');
$args = wp_parse_args($args, $defaults);
$args = apply_filters('wp_nav_menu_args', $args);
$args = (object) $args;
// Get the nav menu
$menu = wp_get_nav_menu_object($args->menu);
// If we couldn't find a menu based off the name, id or slug,
// get the first menu that has items.
if (!$menu) {
$menus = wp_get_nav_menus();
foreach ($menus as $menu_maybe) {
if (wp_get_nav_menu_items($menu_maybe->term_id)) {
$menu = $menu_maybe;
break;
}
}
}
// If the menu exists, get it's items.
if ($menu && !is_wp_error($menu)) {
$menu_items = wp_get_nav_menu_items($menu->term_id, $args->context);
}
// If no menu was found or if the menu has no items, call the fallback_cb
if (!$menu || is_wp_error($menu) || isset($menu_items) && empty($menu_items)) {
if ('frontend' == $args->context && (function_exists($args->fallback_cb) || is_callable($args->fallback_cb))) {
return call_user_func($args->fallback_cb, (array) $args);
}
}
$nav_menu = '';
$items = '';
$container_allowedtags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'p', 'nav'));
if (in_array($args->container, $container_allowedtags)) {
$class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-' . $menu->slug . '-container"';
$nav_menu .= '<' . $args->container . $class . '>';
}
// Set up the $menu_item variables
foreach ((array) $menu_items as $key => $menu_item) {
$menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item($menu_item, 'frontend');
}
$items .= walk_nav_menu_tree($menu_items, $args->depth, $args);
// Attributes
$attributes = ' id="menu-' . $menu->slug . '"';
$attributes .= $args->menu_class ? ' class="' . $args->menu_class . '"' : '';
$nav_menu .= '<ul' . $attributes . '>';
// Allow plugins to hook into the menu to add their
|
请发表评论