本文整理汇总了PHP中wp_nav_menu_update_menu_items函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_nav_menu_update_menu_items函数的具体用法?PHP wp_nav_menu_update_menu_items怎么用?PHP wp_nav_menu_update_menu_items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_nav_menu_update_menu_items函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>';
$menu_title = $_menu_object->name;
}
if (!is_wp_error($_menu_object)) {
$_nav_menu_selected_id = wp_update_nav_menu_object($nav_menu_selected_id, array('menu-name' => $menu_title));
if (is_wp_error($_nav_menu_selected_id)) {
$_menu_object = $_nav_menu_selected_id;
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else {
$_menu_object = wp_get_nav_menu_object($_nav_menu_selected_id);
$nav_menu_selected_title = $_menu_object->name;
}
}
// Update menu items
if (!is_wp_error($_menu_object)) {
$messages = array_merge($messages, wp_nav_menu_update_menu_items($nav_menu_selected_id, $nav_menu_selected_title));
}
}
break;
case 'locations':
if (!$num_locations) {
wp_redirect(admin_url('nav-menus.php'));
exit;
}
add_filter('screen_options_show_screen', '__return_false');
if (isset($_POST['menu-locations'])) {
check_admin_referer('save-menu-locations');
$new_menu_locations = array_map('absint', $_POST['menu-locations']);
$menu_locations = array_merge($menu_locations, $new_menu_locations);
// Set menu locations
set_theme_mod('nav_menu_locations', $menu_locations);
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:31,代码来源:nav-menus.php
示例2: wp_ajax_oxy_save_menu
/**
* Saves wordpress menu using ajax calls
*
* @return json messages from nav-menus.php
* @author
**/
public function wp_ajax_oxy_save_menu()
{
@error_reporting(0);
// Don't break the JSON result
// parse variables sent from $.serialize into an array
$oxy_menu_to_save = json_decode(stripslashes($_POST['menu']), true);
// set request and post to parsed menu data to fake the request
$_REQUEST = $oxy_menu_to_save;
$_POST = $oxy_menu_to_save;
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
// Container for any messages displayed to the user
$messages = array();
// Container that stores the name of the active menu
$nav_menu_selected_title = '';
// The menu id of the current menu being edited
$nav_menu_selected_id = isset($_REQUEST['menu']) ? (int) $_REQUEST['menu'] : 0;
// Get existing menu locations assignments
$locations = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
$num_locations = count(array_keys($locations));
check_admin_referer('update-nav_menu', 'update-nav-menu-nonce');
// Remove menu locations that have been unchecked
foreach ($locations as $location => $description) {
if ((empty($_POST['menu-locations']) || empty($_POST['menu-locations'][$location])) && isset($menu_locations[$location]) && $menu_locations[$location] == $nav_menu_selected_id) {
unset($menu_locations[$location]);
}
}
// Merge new and existing menu locations if any new ones are set
if (isset($_POST['menu-locations'])) {
$new_menu_locations = array_map('absint', $_POST['menu-locations']);
$menu_locations = array_merge($menu_locations, $new_menu_locations);
}
// Set menu locations
set_theme_mod('nav_menu_locations', $menu_locations);
// Add Menu
if (0 == $nav_menu_selected_id) {
$new_menu_title = trim(esc_html($_POST['menu-name']));
if ($new_menu_title) {
$_nav_menu_selected_id = wp_update_nav_menu_object(0, array('menu-name' => $new_menu_title));
if (is_wp_error($_nav_menu_selected_id)) {
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else {
$_menu_object = wp_get_nav_menu_object($_nav_menu_selected_id);
$nav_menu_selected_id = $_nav_menu_selected_id;
$nav_menu_selected_title = $_menu_object->name;
if (isset($_REQUEST['menu-item'])) {
wp_save_nav_menu_items($nav_menu_selected_id, absint($_REQUEST['menu-item']));
}
if (isset($_REQUEST['zero-menu-state'])) {
// If there are menu items, add them
wp_nav_menu_update_menu_items($nav_menu_selected_id, $nav_menu_selected_title);
// Auto-save nav_menu_locations
$locations = get_nav_menu_locations();
foreach ($locations as $location => $menu_id) {
$locations[$location] = $nav_menu_selected_id;
break;
// There should only be 1
}
set_theme_mod('nav_menu_locations', $locations);
}
if (isset($_REQUEST['use-location'])) {
$locations = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
if (isset($locations[$_REQUEST['use-location']])) {
$menu_locations[$_REQUEST['use-location']] = $nav_menu_selected_id;
}
set_theme_mod('nav_menu_locations', $menu_locations);
}
// $messages[] = '<div id="message" class="updated"><p>' . sprintf(__('<strong>%s</strong> has been created.'), $nav_menu_selected_title) . '</p></div>';
wp_redirect(admin_url('nav-menus.php?menu=' . $_nav_menu_selected_id));
exit;
}
} else {
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.', 'lambda-admin-td') . '</p></div>';
}
// Update existing menu
} else {
$_menu_object = wp_get_nav_menu_object($nav_menu_selected_id);
$menu_title = trim(esc_html($_POST['menu-name']));
if (!$menu_title) {
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.', 'lambda-admin-td') . '</p></div>';
$menu_title = $_menu_object->name;
}
if (!is_wp_error($_menu_object)) {
$_nav_menu_selected_id = wp_update_nav_menu_object($nav_menu_selected_id, array('menu-name' => $menu_title));
if (is_wp_error($_nav_menu_selected_id)) {
$_menu_object = $_nav_menu_selected_id;
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else {
$_menu_object = wp_get_nav_menu_object($_nav_menu_selected_id);
$nav_menu_selected_title = $_menu_object->name;
}
}
// Update menu items
//.........这里部分代码省略.........
开发者ID:ntngiri,项目名称:Wordpress-dhaba,代码行数:101,代码来源:OxygennaMegaMenu.php
注:本文中的wp_nav_menu_update_menu_items函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论