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 / AdminMenu / EnabledMenus.php
wp-nested-pages / app / Entities / AdminMenu Last commit date
AdminMenu.php 6 years ago AdminSubmenu.php 4 years ago AdminSubmenuDefault.php 8 years ago AdminSubmenuExpander.php 5 years ago BlockEditorLink.php 6 years ago EnabledMenus.php 6 years ago
EnabledMenus.php
146 lines
1 <?php
2 namespace NestedPages\Entities\AdminMenu;
3
4 use NestedPages\Entities\PostType\PostTypeRepository;
5 use NestedPages\Entities\Listing\Listing;
6 use NestedPages\Entities\AdminMenu\AdminSubmenu;
7 use NestedPages\Entities\AdminMenu\AdminSubmenuDefault;
8 use NestedPages\Entities\User\UserRepository;
9
10 /**
11 * Other User-Enabled Post Types
12 */
13 class EnabledMenus
14 {
15 /**
16 * Post Type
17 */
18 private $post_type;
19
20 /**
21 * Post Type Repository
22 * @var object
23 */
24 private $post_type_repo;
25
26 /**
27 * Enabled Post Types
28 */
29 private $enabled_types;
30
31 /**
32 * User Repository
33 */
34 private $user;
35
36 public function __construct()
37 {
38 $this->post_type_repo = new PostTypeRepository;
39 $this->user = new UserRepository;
40 $this->setEnabled();
41 $this->loopEnabledTypes();
42 }
43
44 /**
45 * Set Enabled Post Types
46 */
47 private function setEnabled()
48 {
49 $this->enabled_types = $this->post_type_repo->getPostTypesObject();
50 }
51
52 /**
53 * Set the Menus for each of the enabled post types
54 */
55 private function loopEnabledTypes()
56 {
57 $c = 1; // Counter for position
58 global $np_page_params;
59 foreach($this->enabled_types as $key => $type){
60 $user_can_view = apply_filters("nestedpages_sort_view_$type->name", $this->user->canViewSorting($type->name), $this->user->getRoles());
61 if ( $type->np_enabled !== true ) continue;
62 if ( !$user_can_view ) continue;
63 if ( $type->replace_menu ) {
64 $this->post_type = get_post_type_object($key);
65 if ( (current_user_can($this->post_type->cap->edit_posts)) ){
66 $this->addMenu($c);
67 $this->addSubmenu();
68 $this->removeExistingMenu();
69 }
70 } else {
71 $default = new AdminSubmenuDefault($type);
72 $np_page_params[$default->getHook()] = ['post_type' => $type->name];
73 }
74 $c++;
75 }
76 }
77
78 /**
79 * Add the primary top-level menu item
80 * @param int counter
81 */
82 private function addMenu($c)
83 {
84 global $np_page_params;
85 $hook = add_menu_page(
86 __($this->post_type->labels->name),
87 __($this->post_type->labels->name),
88 $this->post_type->cap->edit_posts,
89 $this->getSlug(),
90 Listing::admin_menu($this->post_type->name),
91 $this->menuIcon(),
92 $this->menuPosition($c)
93 );
94 $np_page_params[$hook] = ['post_type' => $this->post_type->name];
95 }
96
97 /**
98 * Add Submenus
99 */
100 private function addSubmenu()
101 {
102 $submenu = new AdminSubmenu($this->post_type);
103 $submenu->addSubmenu();
104 }
105
106 /**
107 * Remove Default Menus
108 */
109 private function removeExistingMenu()
110 {
111 remove_menu_page('edit.php?post_type=' . $this->post_type->name);
112 if ( $this->post_type->name == 'post' ) remove_menu_page('edit.php');
113 }
114
115 /**
116 * Get the correct icon to use in menu
117 * @return string
118 */
119 private function menuIcon()
120 {
121 if ( $this->post_type->name == 'page' ) return 'dashicons-admin-page';
122 if ( $this->post_type->menu_icon ) return $this->post_type->menu_icon;
123 return 'dashicons-admin-post';
124 }
125
126 /**
127 * Get the correct menu position for item
128 * @param int counter
129 */
130 private function menuPosition($c)
131 {
132 global $_wp_last_object_menu;
133 if ( $this->post_type->name == 'post' ) return apply_filters('nestedpages_menu_order', 5, $this->post_type);
134 if ( $this->post_type->name == 'page') return apply_filters('nestedpages_menu_order', 20, $this->post_type);
135 if ( $this->post_type->menu_position ) return apply_filters('nestedpages_menu_order', $this->post_type->menu_position + 1, $this->post_type);
136 return $_wp_last_object_menu + $c;
137 }
138
139 /**
140 * Get the Edit Slug for post type
141 */
142 private function getSlug()
143 {
144 return $this->post_type_repo->getMenuSlug($this->post_type);
145 }
146 }