PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.2.15
Nested Pages v3.2.15
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 / Post / PostTrashActions.php
wp-nested-pages / app / Entities / Post Last commit date
PostCloner.php 3 years ago PostDataFactory.php 3 years ago PostFactory.php 3 days ago PostRepository.php 5 years ago PostSaveActions.php 3 years ago PostTrashActions.php 8 years ago PostUpdateRepository.php 3 days ago PrivatePostParent.php 3 years ago
PostTrashActions.php
94 lines
1 <?php
2 namespace NestedPages\Entities\Post;
3
4 use NestedPages\Entities\User\UserRepository;
5 use NestedPages\Entities\NavMenu\NavMenuSyncListing;
6 use NestedPages\Entities\NavMenu\NavMenuRemoveItem;
7 use NestedPages\Entities\NavMenu\NavMenuRepository;
8
9 /**
10 * WP Actions tied to a Post
11 */
12 class PostTrashActions
13 {
14 /**
15 * User Repository
16 * @var object
17 */
18 private $user_repo;
19
20 /**
21 * Nav Menu Repository
22 */
23 private $nav_menu_repo;
24
25 public function __construct()
26 {
27 $this->user_repo = new UserRepository;
28 $this->nav_menu_repo = new NavMenuRepository;
29 add_action( 'trashed_post', [$this, 'trashHook']);
30 add_action( 'delete_post', [$this, 'removeLinkNavItem'], 10 );
31 }
32
33 /**
34 * Trash hook - make sure child pages of trashed page are visible
35 * @since 1.3.4
36 */
37 public function trashHook($post_id)
38 {
39 $post_type = get_post_type($post_id);
40 $this->resetToggles($post_id, $post_type);
41 if ( get_option('nestedpages_menusync') !== 'sync' ) return;
42 $this->removeNavMenuItem($post_id);
43 if ( $post_type == 'page' ){
44 $sync = new NavMenuSyncListing;
45 $sync->sync();
46 }
47 }
48
49 /**
50 * Link Post Types are immediately deleted, so trash hook isn't called
51 * Must remove nav menu items when they're deleted
52 */
53 public function removeLinkNavItem($post_id)
54 {
55 $post_type = get_post_type($post_id);
56 if ( $post_type == 'nav_menu_item' ) return;
57 if ( $post_type == 'np-redirect' ) $this->removeNavMenuItem($post_id);
58 }
59
60 /**
61 * Remove the nav menu item
62 */
63 private function removeNavMenuItem($post_id)
64 {
65 $query_type = ( get_post_type($post_id) == 'np-redirect' ) ? 'xfn' : 'object_id';
66 $nav_item_id = $this->nav_menu_repo->getMenuItem($post_id, $query_type);
67 if ( $nav_item_id ) new NavMenuRemoveItem($nav_item_id);
68 }
69
70 /**
71 * Make sure children of trashed pages are viewable in Nested Pages
72 */
73 private function resetToggles($post_id, $post_type)
74 {
75 $visible_pages = $this->user_repo->getVisiblePages();
76 if ( !isset($visible_pages[$post_type]) ) return;
77 $visible_pages = $visible_pages[$post_type];
78
79 if ( !isset($visible_pages[$post_type]) ) return;
80
81 $child_pages = [];
82
83 $children = new \WP_Query(['post_type'=>$post_type, 'posts_per_page'=>-1, 'post_parent'=>$post_id]);
84 if ( $children->have_posts() ) : while ( $children->have_posts() ) : $children->the_post();
85 array_push($child_pages, get_the_id());
86 endwhile; endif; wp_reset_postdata();
87
88 foreach($child_pages as $child_page){
89 if ( !in_array($child_page, $visible_pages) ) array_push($visible_pages, $child_page);
90 }
91
92 $this->user_repo->updateVisiblePages($post_type, $visible_pages);
93 }
94 }