PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.0.8
Nested Pages v3.0.8
3.3.1 3.2.15 3.2.14 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 8 years ago NavMenuFrontEnd.php 8 years ago NavMenuRemoveItem.php 9 years ago NavMenuRepository.php 8 years ago NavMenuSync.php 9 years ago NavMenuSyncListing.php 8 years ago NavMenuSyncMenu.php 8 years ago NavMenuTrashActions.php 7 years ago
NavMenuSyncListing.php
121 lines
1 <?php
2 namespace NestedPages\Entities\NavMenu;
3
4 use NestedPages\Entities\NavMenu\NavMenuSync;
5 use NestedPages\Helpers;
6 use NestedPages\Entities\Post\PostDataFactory;
7
8 /**
9 * Syncs the Generated Menu to Match the Listing
10 */
11 class NavMenuSyncListing extends NavMenuSync
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 public function __construct()
31 {
32 parent::__construct();
33 $this->post_factory = new PostDataFactory;
34 }
35
36 /**
37 * Recursive function loops through pages/links and their children
38 */
39 public function sync($parent = 0, $menu_parent = 0, $nest_level = 0)
40 {
41 $post_types = ['page'];
42 if ( !$this->integrations->plugins->wpml->installed ) $post_types[] = 'np-redirect';
43 try {
44 $this->count = $this->count + 1;
45 $args = [
46 'post_type' => $post_types,
47 'posts_per_page' => -1,
48 'post_status' => 'publish',
49 'orderby' => 'menu_order',
50 'order' => 'ASC',
51 'post_parent' => $parent
52 ];
53 $page_q = new \WP_Query(apply_filters('nestedpages_menu_sync', $args, $nest_level));
54 if ( $page_q->have_posts() ) : while ( $page_q->have_posts() ) : $page_q->the_post();
55 $nest_level++;
56 global $post;
57 $this->post = $this->post_factory->build($post);
58 $this->syncPost($menu_parent, $nest_level);
59 endwhile; endif; wp_reset_postdata();
60 } catch ( \Exception $e ){
61 throw new \Exception($e->getMessage());
62 }
63 }
64
65 /**
66 * Sync an individual item
67 * @since 1.3.4
68 */
69 private function syncPost($menu_parent, $nest_level)
70 {
71 // Get the Menu Item
72 $query_type = ( $this->post->type == 'np-redirect' ) ? 'xfn' : 'object_id';
73 $menu_item_id = $this->nav_menu_repo->getMenuItem($this->post->id, $query_type);
74 if ( $this->post->nav_status == 'hide' ) return $this->removeItem($menu_item_id);
75 $menu = $this->syncMenuItem($menu_parent, $menu_item_id);
76 $this->sync( $this->post->id, $menu, $nest_level );
77 }
78
79 /**
80 * Sync Link Menu Item
81 * @since 1.1.4
82 */
83 private function syncMenuItem($menu_parent, $menu_item_id)
84 {
85 $type = ( $this->post->nav_type ) ? $this->post->nav_type : 'custom';
86 $object = ( $this->post->nav_object ) ? $this->post->nav_object : 'custom';
87 $object_id = ( $this->post->nav_object_id ) ? intval($this->post->nav_object_id) : null;
88 $url = ( $type == 'custom' ) ? esc_url($this->post->content) : '';
89 $xfn = $this->post->id;
90 $title = ( $this->post->nav_title && $this->post->type == 'page' ) ? $this->post->nav_title : $this->post->title;
91
92 // Compatibility for 1.4.1 - Reset Page links
93 if ( $this->post->type == 'page' ){
94 $type = 'post_type';
95 $object = 'page';
96 $object_id = $this->post->id;
97 $xfn = 'page';
98 }
99
100 // WP 4.4 Fix, empty nav title attribute causing post_excerpt null error
101 $attr_title = ( $this->post->nav_title_attr ) ? $this->post->nav_title_attr : '';
102
103 $args = [
104 'menu-item-title' => $title,
105 'menu-item-position' => $this->count,
106 'menu-item-url' => $url,
107 'menu-item-attr-title' => $attr_title,
108 'menu-item-status' => 'publish',
109 'menu-item-classes' => $this->post->nav_css,
110 'menu-item-type' => $type,
111 'menu-item-object' => $object,
112 'menu-item-object-id' => $object_id,
113 'menu-item-parent-id' => $menu_parent,
114 'menu-item-xfn' => $xfn,
115 'menu-item-target' => $this->post->link_target,
116 'menu-item-description' => ' '
117 ];
118 $menu = wp_update_nav_menu_item($this->id, $menu_item_id, $args);
119 return $menu;
120 }
121 }