PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 1.3.4
Nested Pages v1.3.4
3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / app / Entities / NavMenu / NavMenuSyncListing.php
wp-nested-pages / app / Entities / NavMenu Last commit date
NavMenuActions.php 11 years ago NavMenuRemoveItem.php 11 years ago NavMenuRepository.php 11 years ago NavMenuSync.php 11 years ago NavMenuSyncInterface.php 11 years ago NavMenuSyncListing.php 11 years ago NavMenuSyncMenu.php 11 years ago NavMenuTrashActions.php 11 years ago
NavMenuSyncListing.php
127 lines
1 <?php namespace NestedPages\Entities\NavMenu;
2
3 use NestedPages\Entities\NavMenu\NavMenuSync;
4 use NestedPages\Helpers;
5 use NestedPages\Entities\Post\PostDataFactory;
6
7 /**
8 * Syncs the Generated Menu to Match the Listing
9 */
10 class NavMenuSyncListing extends NavMenuSync implements NavMenuSyncInterface {
11
12
13 /**
14 * Individual Post
15 * @var array
16 */
17 private $post;
18
19 /**
20 * Menu Position Count
21 * @var int
22 */
23 private $count = 0;
24
25 /**
26 * Post Data Factory
27 */
28 private $post_factory;
29
30
31 public function __construct()
32 {
33 parent::__construct();
34 $this->post_factory = new PostDataFactory;
35 }
36
37
38 /**
39 * Create the menu with nested pages
40 */
41 public function sync($parent = 0, $menu_parent = 0)
42 {
43 $this->count = $this->count + 1;
44 $page_q = new \WP_Query(array(
45 'post_type' => array('page','np-redirect'),
46 'posts_per_page' => -1,
47 'post_status' => 'publish',
48 'orderby' => 'menu_order',
49 'order' => 'ASC',
50 'post_parent' => $parent
51 ));
52 if ( $page_q->have_posts() ) : while ( $page_q->have_posts() ) : $page_q->the_post();
53 global $post;
54 $this->post = $this->post_factory->build($post);
55 $this->syncItem($menu_parent);
56 endwhile; endif; wp_reset_postdata();
57 }
58
59
60 /**
61 * Sync an individual item
62 * @since 1.3.4
63 */
64 private function syncItem($menu_parent)
65 {
66 // Get the Menu Item ID using the post ID
67 $menu_item_id = $this->nav_menu_repo->getMenuItemID($this->post->id);
68
69 if ( $this->post->nav_status == 'hide' ) return $this->removeItem($menu_item_id);
70
71 $menu = ( $this->post->type == 'page' )
72 ? $this->syncPageItem($menu_parent, $menu_item_id)
73 : $this->syncLinkItem($menu_parent, $menu_item_id);
74
75 $this->sync( $this->post->id, $menu );
76 }
77
78
79
80 /**
81 * Sync Page Menu Item
82 * @since 1.1.4
83 */
84 private function syncPageItem($menu_parent, $menu_item_id)
85 {
86 $menu = wp_update_nav_menu_item($this->id, $menu_item_id, array(
87 'menu-item-title' => $this->post->nav_title,
88 'menu-item-position' => $this->count,
89 'menu-item-url' => $this->post->link,
90 'menu-item-attr-title' => $this->post->nav_title_attr,
91 'menu-item-status' => 'publish',
92 'menu-item-classes' => $this->post->nav_css,
93 'menu-item-type' => 'post_type',
94 'menu-item-object' => 'page',
95 'menu-item-object-id' => $this->post->id,
96 'menu-item-parent-id' => $menu_parent,
97 'menu-item-target' => $this->post->link_target
98 ));
99 return $menu;
100 }
101
102
103 /**
104 * Sync Link Menu Item
105 * @since 1.1.4
106 */
107 private function syncLinkItem($menu_parent, $menu_item_id)
108 {
109 $menu = wp_update_nav_menu_item($this->id, $menu_item_id, array(
110 'menu-item-title' => $this->post->title,
111 'menu-item-position' => $this->count,
112 'menu-item-url' => Helpers::check_url(get_the_content($this->post->id)),
113 'menu-item-attr-title' => $this->post->nav_title_attr,
114 'menu-item-status' => 'publish',
115 'menu-item-classes' => $this->post->nav_css,
116 'menu-item-type' => 'custom',
117 'menu-item-object' => 'np-redirect',
118 'menu-item-object-id' => $this->post->id,
119 'menu-item-parent-id' => $menu_parent,
120 'menu-item-xfn' => $this->post->id,
121 'menu-item-target' => $this->post->link_target
122 ));
123 return $menu;
124 }
125
126
127 }