PluginProbe
Nested Pages / 1.1.2
Nested Pages v1.1.2
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 All 106 releases
wp-nested-pages / includes / class-np-posttypes.php
class-np-posttypes.php
70 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once('class-np-navmenu.php');
3 /**
4 * Post Types required by Nested Pages
5 */
6 class NP_PostTypes {
7
8 public function __construct()
9 {
10 add_action( 'init', array( $this, 'registerRedirects') );
11 add_action( 'trashed_post', array( $this, 'trashHook' ) );
12 }
13
14
15 /**
16 * Redirects Post Type
17 */
18 public function registerRedirects()
19 {
20 $labels = array(
21 'name' => __('Redirects'),
22 'singular_name' => __('Redirect'),
23 'add_new_item'=> 'Add Redirect',
24 'edit_item' => 'Edit Redirect',
25 'view_item' => 'View Redirect'
26 );
27 $args = array(
28 'labels' => $labels,
29 'public' => false,
30 'show_ui' => false,
31 'menu_position' => 5,
32 'capability_type' => 'post',
33 'hierarchical' => true,
34 'has_archive' => true,
35 'supports' => array('title','editor'),
36 'rewrite' => array('slug' => 'np-redirect', 'with_front' => false)
37 );
38 register_post_type( 'np-redirect' , $args );
39 }
40
41
42
43 /**
44 * Trash hook - unset parent pages
45 */
46 public function trashHook($post_id)
47 {
48 $post_type = get_post_type($post_id);
49 if ( $post_type == 'page' ) $this->resetToggles($post_id);
50 }
51
52
53 /**
54 * Make sure children of trashed pages are viewable in Nested Pages
55 */
56 private function resetToggles($post_id)
57 {
58 $visible_pages = unserialize(get_user_meta(get_current_user_id(), 'np_visible_pages', true));
59 $child_pages = array();
60 $children = new WP_Query(array('post_type'=>'page', 'posts_per_page'=>-1, 'post_parent'=>$post_id));
61 if ( $children->have_posts() ) : while ( $children->have_posts() ) : $children->the_post();
62 array_push($child_pages, get_the_id());
63 endwhile; endif; wp_reset_postdata();
64 foreach($child_pages as $child_page){
65 if ( !in_array($child_page, $visible_pages) ) array_push($visible_pages, $child_page);
66 }
67 update_user_meta(get_current_user_id(), 'np_visible_pages', serialize($visible_pages));
68 }
69
70 }