• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_save_nav_menu_items函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_save_nav_menu_items函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_save_nav_menu_items函数的具体用法?PHP wp_save_nav_menu_items怎么用?PHP wp_save_nav_menu_items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_save_nav_menu_items函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: wp_ajax_add_menu_item

/**
 * Ajax handler for adding a menu item.
 *
 * @since 3.1.0
 */
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';
    // 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();
    foreach ((array) $_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 'post_type_archive':
                    $_object = get_post_type_object($menu_item_data['menu-item-object']);
                    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 = reset($_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)) {
        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 documented in wp-admin/includes/nav-menu.php */
    $walker_class_name = apply_filters('wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu']);
    if (!class_exists($walker_class_name, false)) {
        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);
    }
    wp_die();
}
开发者ID:hughnet,项目名称:WordPress,代码行数:60,代码来源:ajax-actions.php


示例2: wp_enqueue_script

wp_enqueue_script('postbox');
// 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;
// Allowed actions: add, update, delete
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'edit';
switch ($action) {
    case 'add-menu-item':
        check_admin_referer('add-menu_item', 'menu-settings-column-nonce');
        if (isset($_REQUEST['nav-menu-locations'])) {
            set_theme_mod('nav_menu_locations', array_map('absint', $_REQUEST['menu-locations']));
        } elseif (isset($_REQUEST['menu-item'])) {
            wp_save_nav_menu_items($nav_menu_selected_id, $_REQUEST['menu-item']);
        }
        break;
    case 'move-down-menu-item':
        // moving down a menu item is the same as moving up the next in order
        check_admin_referer('move-menu_item');
        $menu_item_id = isset($_REQUEST['menu-item']) ? (int) $_REQUEST['menu-item'] : 0;
        if (is_nav_menu_item($menu_item_id)) {
            $menus = isset($_REQUEST['menu']) ? array((int) $_REQUEST['menu']) : wp_get_object_terms($menu_item_id, 'nav_menu', array('fields' => 'ids'));
            if (!is_wp_error($menus) && !empty($menus[0])) {
                $menu_id = (int) $menus[0];
                $ordered_menu_items = wp_get_nav_menu_items($menu_id);
                $menu_item_data = (array) wp_setup_nav_menu_item(get_post($menu_item_id));
                // set up the data we need in one pass through the array of menu items
                $dbids_to_orders = array();
                $orders_to_dbids = array();
开发者ID:Esleelkartea,项目名称:asociacion-tecnicos-artes-escenicas-ATAE-,代码行数:31,代码来源:nav-menus.php


示例3: set_theme_mod

 }
 // 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();
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:31,代码来源:nav-menus.php


示例4: 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


示例5: switch

         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 Walker_Nav_Menu_Edit());
     echo walk_nav_menu_tree($menu_items, 0, (object) $args);
开发者ID:vivekkodira1,项目名称:wordpress,代码行数:31,代码来源:admin-ajax.php


示例6: 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


示例7: 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


示例8: wp_save_nav_menu_items

		'id' => $comment->comment_ID,
		'data' => $comment_list_item,
		'position' => $position
	));

	$x->send();
	break;
case 'add-menu-item' :
	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' => '',
开发者ID:realfluid,项目名称:umbaugh,代码行数:31,代码来源:admin-ajax.php


示例9: 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


示例10: 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


示例11: add_menu_item

 public function add_menu_item($menu_id, $menu_items)
 {
     if (empty($menu_id) || is_nav_menu($menu_id) === false) {
         return false;
     }
     //$this->_out(new Upfront_JsonResponse_Error('Cannot create menu!'));
     $new_menu_items = wp_save_nav_menu_items($menu_id, $menu_items);
     return $new_menu_items;
 }
开发者ID:sedici,项目名称:wpmu-istec,代码行数:9,代码来源:unewnavigation.php


示例12: duplicate_item

 /**
  * TODO: documentation
  */
 public function duplicate_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';
     $item = wp_setup_nav_menu_item(clone get_post($_GET['db_id']));
     $menu_items = array();
     $menu_item = array('menu-item-object' => $item->object, 'menu-item-object-id' => $item->object_id, 'menu-item-parent-id' => isset($_GET['parent_id']) ? $_GET['parent_id'] : $item->menu_item_parent, 'menu-item-type' => $item->type, 'menu-item-title' => $item->title, 'menu-item-url' => $item->url);
     $item_ids = wp_save_nav_menu_items($_GET['menu'], array($menu_item));
     if (is_wp_error($item_ids)) {
         wp_die(0);
     }
     $menu_obj = get_post($item_ids[0]);
     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;
     }
     $walker_class_name = apply_filters('wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_GET['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());
         $output = walk_nav_menu_tree($menu_items, 0, (object) $args);
         $output = preg_replace_callback('/(menu-item-depth-)([0-9]+)/', function ($matches) {
             return $matches[1] . ($matches[2] + 1);
         }, $output);
         echo $output;
         wp_die();
     }
 }
开发者ID:peazz,项目名称:mega-menu,代码行数:38,代码来源:mega-menu-admin.php



注:本文中的wp_save_nav_menu_items函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_save_post_revision函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_save_image_file函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap