Esempio n. 1
0
 /**
  * @group bu-cache
  */
 public function test_run()
 {
     // Before state:
     $this->assertEquals($this->posts['parent'], get_post($this->posts['child'])->post_parent);
     $this->assertEquals($this->posts['child'], get_post($this->posts['grandchild_one'])->post_parent);
     $this->assertEquals(1, get_post($this->posts['grandchild_one'])->menu_order);
     $this->assertEquals(2, get_post($this->posts['grandchild_two'])->menu_order);
     $this->assertEquals(0, get_post($this->posts['hidden'])->post_parent);
     $this->assertEquals(1, get_post($this->posts['parent'])->menu_order);
     $this->assertEquals(2, get_post($this->posts['hidden'])->menu_order);
     $this->assertEquals(3, get_post($this->posts['edit'])->menu_order);
     $this->assertEquals(4, get_post($this->posts['private'])->menu_order);
     $this->assertEquals(5, get_post($this->posts['google'])->menu_order);
     $this->assertEquals(6, get_post($this->posts['last_page'])->menu_order);
     $tracker = new BU_Navigation_Reorder_Tracker('page');
     wp_update_post(array('ID' => $this->posts['hidden'], 'post_parent' => $this->posts['child'], 'menu_order' => 1));
     wp_update_post(array('ID' => $this->posts['child'], 'post_parent' => 0, 'menu_order' => 1));
     wp_delete_post($this->posts['grandchild_two'], true);
     wp_update_post(array('ID' => $this->posts['private'], 'menu_order' => 5));
     $move_one = get_post($this->posts['hidden']);
     $move_two = get_post($this->posts['child']);
     $move_three = get_post($this->posts['private']);
     // Mark two posts as moved, reorder section that contained deleted child
     $tracker->mark_post_as_moved($move_one);
     $tracker->mark_post_as_moved($move_two);
     $tracker->mark_post_as_moved($move_three);
     $tracker->mark_section_for_reordering($this->posts['child']);
     // Perform reordering
     $tracker->run();
     $this->assertEquals($this->posts['child'], get_post($this->posts['hidden'])->post_parent);
     $this->assertEquals(1, get_post($this->posts['hidden'])->menu_order);
     $this->assertEquals(2, get_post($this->posts['grandchild_one'])->menu_order);
     $this->assertEquals(0, get_post($this->posts['child'])->post_parent);
     $this->assertEquals(1, get_post($this->posts['child'])->menu_order);
     $this->assertEquals(2, get_post($this->posts['parent'])->menu_order);
     $this->assertEquals(3, get_post($this->posts['edit'])->menu_order);
     $this->assertEquals(4, get_post($this->posts['google'])->menu_order);
     $this->assertEquals(5, get_post($this->posts['private'])->menu_order);
     $this->assertEquals(6, get_post($this->posts['last_page'])->menu_order);
 }
Esempio n. 2
0
 /**
  * Update navigation related meta data on post save
  *
  * WordPress will handle updating of post_parent and menu_order prior to this callback being run
  * The post property of stored in this object will hold the post data prior to update
  *
  * @todo don't hard code meta keys
  */
 public function save($post_id, $post)
 {
     if (!in_array($post->post_type, $this->plugin->supported_post_types())) {
         return;
     }
     if ('auto-draft' == $post->post_status) {
         return;
     }
     if (array_key_exists('nav_label', $_POST)) {
         // update the navigation meta data
         $nav_label = wp_kses_post($_POST['nav_label']);
         $exclude = array_key_exists('nav_display', $_POST) ? 0 : 1;
         update_post_meta($post_id, BU_NAV_META_PAGE_LABEL, $nav_label);
         update_post_meta($post_id, BU_NAV_META_PAGE_EXCLUDE, $exclude);
     }
     // Perform reordering if post parent or menu order has changed
     $reorder = new BU_Navigation_Reorder_Tracker($post->post_type);
     // Reorder old and new section if parent has changed
     if ($this->post->post_parent != $post->post_parent) {
         $reorder->mark_post_as_moved($post);
         $reorder->mark_section_for_reordering($this->post->post_parent);
     } else {
         if ($this->post->menu_order != $post->menu_order) {
             $reorder->mark_post_as_moved($post);
         }
     }
     // Reorder
     if ($reorder->has_moves()) {
         $reorder->run();
     }
 }