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 / Post / PostTrashActions.php
wp-nested-pages / app / Entities / Post Last commit date
PostDataFactory.php 11 years ago PostFactory.php 11 years ago PostRepository.php 11 years ago PostTrashActions.php 11 years ago PostUpdateRepository.php 11 years ago
PostTrashActions.php
93 lines
1 <?php namespace NestedPages\Entities\Post;
2
3 use NestedPages\Entities\User\UserRepository;
4 use NestedPages\Entities\NavMenu\NavMenuSyncListing;
5 use NestedPages\Entities\NavMenu\NavMenuRemoveItem;
6 use NestedPages\Entities\NavMenu\NavMenuRepository;
7
8 /**
9 * WP Actions tied to a Post
10 */
11 class PostTrashActions {
12
13 /**
14 * User Repository
15 * @var object
16 */
17 private $user_repo;
18
19 /**
20 * Nav Menu Repository
21 */
22 private $nav_menu_repo;
23
24
25 public function __construct()
26 {
27 $this->user_repo = new UserRepository;
28 $this->nav_menu_repo = new NavMenuRepository;
29 add_action( 'trashed_post', array( $this, 'trashHook' ) );
30 add_action( 'delete_post', array( $this, 'removeLinkNavItem'), 10 );
31 }
32
33
34 /**
35 * Trash hook - make sure child pages of trashed page are visible
36 * @since 1.3.4
37 */
38 public function trashHook($post_id)
39 {
40 $post_type = get_post_type($post_id);
41 $this->resetToggles($post_id, $post_type);
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 /**
62 * Remove the nav menu item
63 */
64 private function removeNavMenuItem($post_id)
65 {
66 $nav_item_id = $this->nav_menu_repo->getMenuItemID($post_id);
67 if ( $nav_item_id ) new NavMenuRemoveItem($nav_item_id);
68 }
69
70
71 /**
72 * Make sure children of trashed pages are viewable in Nested Pages
73 */
74 private function resetToggles($post_id, $post_type)
75 {
76 $visible_pages = $this->user_repo->getVisiblePages();
77 $visible_pages = $visible_pages[$post_type];
78
79 $child_pages = array();
80
81 $children = new \WP_Query(array('post_type'=>$post_type, 'posts_per_page'=>-1, 'post_parent'=>$post_id));
82 if ( $children->have_posts() ) : while ( $children->have_posts() ) : $children->the_post();
83 array_push($child_pages, get_the_id());
84 endwhile; endif; wp_reset_postdata();
85
86 foreach($child_pages as $child_page){
87 if ( !in_array($child_page, $visible_pages) ) array_push($visible_pages, $child_page);
88 }
89
90 $this->user_repo->updateVisiblePages($post_type, $visible_pages);
91 }
92
93 }