Exemple #1
0
 function test_wp_get_associated_nav_menu_items()
 {
     $tag_id = $this->factory->tag->create();
     $cat_id = $this->factory->category->create();
     $post_id = $this->factory->post->create();
     $post_2_id = $this->factory->post->create();
     $page_id = $this->factory->post->create(array('post_type' => 'page'));
     $tag_insert = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'taxonomy', 'menu-item-object' => 'post_tag', 'menu-item-object-id' => $tag_id, 'menu-item-status' => 'publish'));
     $cat_insert = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'taxonomy', 'menu-item-object' => 'category', 'menu-item-object-id' => $cat_id, 'menu-item-status' => 'publish'));
     $post_insert = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-object' => 'post', 'menu-item-object-id' => $post_id, 'menu-item-status' => 'publish'));
     // Item without menu-item-object arg
     $post_2_insert = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-object-id' => $post_2_id, 'menu-item-status' => 'publish'));
     $page_insert = wp_update_nav_menu_item($this->menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-object' => 'page', 'menu-item-object-id' => $page_id, 'menu-item-status' => 'publish'));
     $tag_items = wp_get_associated_nav_menu_items($tag_id, 'taxonomy', 'post_tag');
     $this->assertEqualSets(array($tag_insert), $tag_items);
     $cat_items = wp_get_associated_nav_menu_items($cat_id, 'taxonomy', 'category');
     $this->assertEqualSets(array($cat_insert), $cat_items);
     $post_items = wp_get_associated_nav_menu_items($post_id);
     $this->assertEqualSets(array($post_insert), $post_items);
     $post_2_items = wp_get_associated_nav_menu_items($post_2_id);
     $this->assertEqualSets(array($post_2_insert), $post_2_items);
     $page_items = wp_get_associated_nav_menu_items($page_id);
     $this->assertEqualSets(array($page_insert), $page_items);
     wp_delete_term($tag_id, 'post_tag');
     $tag_items = wp_get_associated_nav_menu_items($tag_id, 'taxonomy', 'post_tag');
     $this->assertEqualSets(array(), $tag_items);
     wp_delete_term($cat_id, 'category');
     $cat_items = wp_get_associated_nav_menu_items($cat_id, 'taxonomy', 'category');
     $this->assertEqualSets(array(), $cat_items);
     wp_delete_post($post_id, true);
     $post_items = wp_get_associated_nav_menu_items($post_id);
     $this->assertEqualSets(array(), $post_items);
     wp_delete_post($post_2_id, true);
     $post_2_items = wp_get_associated_nav_menu_items($post_2_id);
     $this->assertEqualSets(array(), $post_2_items);
     wp_delete_post($page_id, true);
     $page_items = wp_get_associated_nav_menu_items($page_id);
     $this->assertEqualSets(array(), $page_items);
 }
	function test_wp_get_associated_nav_menu_items() {
		$tag_id = $this->factory->tag->create();
		$cat_id = $this->factory->category->create();

		$tag_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
			'menu-item-type' => 'taxonomy',
			'menu-item-object' => 'post_tag',
			'menu-item-object-id' => $tag_id,
			'menu-item-status' => 'publish'
		) );

		$cat_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
			'menu-item-type' => 'taxonomy',
			'menu-item-object' => 'category',
			'menu-item-object-id' => $cat_id,
			'menu-item-status' => 'publish'
		) );

		$tag_items = wp_get_associated_nav_menu_items( $tag_id, 'taxonomy', 'post_tag' );
		$this->assertEqualSets( array( $tag_insert ), $tag_items );
		$cat_items = wp_get_associated_nav_menu_items( $cat_id, 'taxonomy', 'category' );
		$this->assertEqualSets( array( $cat_insert ), $cat_items );
	}
/**
 * Callback for handling a menu item when its original object is deleted.
 *
 * @since 3.0.0
 * @access private
 *
 * @param int $object_id The ID of the original object being trashed.
 *
 */
function _wp_delete_tax_menu_item($object_id = 0, $tt_id, $taxonomy)
{
    $object_id = (int) $object_id;
    $menu_item_ids = wp_get_associated_nav_menu_items($object_id, 'taxonomy', $taxonomy);
    foreach ((array) $menu_item_ids as $menu_item_id) {
        wp_delete_post($menu_item_id, true);
    }
}
 /**
  * Called via WP Ajax action 'wp_ajax_spm_delete_page' if can_edit_pages
  *
  * Ajax function to delete a page
  */
 public function ajax_delete_page()
 {
     if (!current_user_can('delete_pages')) {
         wp_die(__('You do not have sufficient permissions to access this page. #708'));
     }
     $post_id = intval($_POST['post_ID']);
     if (isset($post_id) && !empty($post_id)) {
         $menu_items = wp_get_associated_nav_menu_items($post_id, 'post_type', 'page');
         foreach ($menu_items as $menu_item_id) {
             wp_delete_post($menu_item_id, true);
         }
         $post_data = wp_delete_post($post_id, false);
         if (is_object($post_data)) {
             echo '1';
         } else {
             echo '0';
             // fail, tell js
         }
     } else {
         echo '0';
         // fail, tell js
     }
     exit;
 }