PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / admin / class-upstream-admin-projects-menu.php

class-upstream-admin-projects-menu.php in UpStream: a Project Management Plugin for WordPress trunk, at includes/admin/class-upstream-admin-projects-menu.php

280 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setup menus in WP admin.
4 *
5 * @author UpStream
6 * @category Admin
7 * @package UpStream/Admin
8 * @version 1.0.0
9 */
10
11 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 if ( ! class_exists( 'UpStream_Admin_Projects_Menu' ) ) :
17
18 /**
19 * UpStream_Admin_Menus Class.
20 */
21 class UpStream_Admin_Projects_Menu {
22
23 /**
24 * User Is Up Stream User
25 *
26 * @var undefined
27 */
28 private static $user_is_up_stream_user = null;
29
30 /**
31 * Hook in tabs.
32 */
33 public function __construct() {
34 if ( null === self::$user_is_up_stream_user ) {
35 $user = wp_get_current_user();
36 self::$user_is_up_stream_user = count(
37 array_intersect(
38 $user->roles,
39 array( 'administrator', 'upstream_manager' )
40 )
41 ) === 0;
42 }
43
44 if ( ! defined( 'UPSTREAM_HAS_INVALID_LICENSE' ) ) {
45 add_action( 'admin_menu', array( $this, 'custom_menu_items' ), 9 );
46 add_filter( 'custom_menu_order', array( $this, 'submenu_order' ) );
47 }
48
49 add_action( 'admin_head', array( $this, 'hide_add_new_project_button_if_needed' ) );
50
51 // highlight proper admin menu & submenus.
52 add_filter( 'parent_file', array( $this, 'highlight_parent_file' ) );
53 add_filter( 'submenu_file', array( $this, 'highlight_submenu_file' ) );
54 }
55
56 /**
57 * Hide Add New Project Button If Needed
58 *
59 * @return void
60 */
61 public function hide_add_new_project_button_if_needed() {
62 if ( is_admin() ) {
63 global $pagenow;
64
65 $get_data = isset( $_GET ) ? wp_unslash( $_GET ) : array();
66
67 if ( 'edit.php' === $pagenow && isset( $get_data['post_type'] ) && 'project' === sanitize_text_field( $get_data['post_type'] ) ) {
68 if ( self::$user_is_up_stream_user ) {
69 echo '<style type="text/css">.page-title-action:not(.upstream-button) { display: none; }</style>';
70
71 if ( upstream_override_access_object( false, UPSTREAM_ITEM_TYPE_PROJECT, 0, null, 0, UPSTREAM_PERMISSIONS_ACTION_CREATE ) ) {
72 ?>
73 <script>
74 jQuery(function(){
75 jQuery("body.post-type-project .wrap h1").append('<a href="<?php print esc_attr( get_post_type_archive_link( 'project' ) ); ?>" class="upstream-button page-title-action"><?php esc_html_e( 'New ', 'upstream' ) . esc_html( upstream_project_label() ); ?></a>');
76 });
77 </script>
78 <?php
79 }
80 ?>
81 <script>
82 jQuery(function(){
83 jQuery(".row-actions span.inline").remove();
84 jQuery(".row-actions span.edit").remove();
85 });
86 </script>
87 <?php
88 }
89 }
90 }
91 }
92
93 /**
94 * Add menu item.
95 */
96 public function custom_menu_items() {
97 add_submenu_page(
98 'edit.php?post_type=project',
99 upstream_client_label_plural(),
100 upstream_client_label_plural(),
101 'edit_clients',
102 'edit.php?post_type=client'
103 );
104
105 add_submenu_page(
106 'edit.php?post_type=project',
107 upstream_milestone_category_label_plural(),
108 upstream_milestone_category_label_plural(),
109 'edit_projects',
110 'edit-tags.php?taxonomy=upst_milestone_category&post_type=upst_milestone'
111 );
112 }
113
114 /**
115 * Submenu Order
116 *
117 * @param mixed $menu Menu.
118 */
119 public function submenu_order( $menu ) {
120 global $submenu;
121
122 $sub_menu_identifier = 'edit.php?post_type=project';
123 if ( isset( $submenu[ $sub_menu_identifier ] )
124 && ! empty( $submenu[ $sub_menu_identifier ] )
125 ) {
126 $upstream_submenu = &$submenu[ $sub_menu_identifier ];
127 $new_up_stream_submenu = array();
128 $search_submenu_item = function ( $needle ) use ( &$upstream_submenu ) {
129 foreach ( $upstream_submenu as $submenu_index => $submenu ) {
130 $regexp = '/' . $needle . '/i';
131 if ( preg_match( $regexp, $submenu[2] ) ) {
132 return $submenu;
133 }
134 }
135
136 return null;
137 };
138
139 $submenu_projects = $search_submenu_item( '^edit\.php\?post_type=project$' );
140 if ( null !== $submenu_projects ) {
141 $new_up_stream_submenu[] = $submenu_projects;
142 }
143 unset( $submenu_projects );
144
145 if ( self::$user_is_up_stream_user ) {
146 $submenu_tasks = $search_submenu_item( '^tasks$' );
147 if ( null !== $submenu_tasks
148 && strpos( $submenu_tasks[0], 'update-count' ) !== false
149 ) {
150 $new_up_stream_submenu[] = $submenu_tasks;
151 }
152 unset( $submenu_tasks );
153
154 $submenu_bugs = $search_submenu_item( '^bugs$' );
155 if ( null !== $submenu_bugs
156 && strpos( $submenu_bugs[0], 'update-count' ) !== false
157 ) {
158 $new_up_stream_submenu[] = $submenu_bugs;
159 }
160 unset( $submenu_bugs );
161 } else {
162 $are_categories_enabled = ! upstream_is_project_categorization_disabled();
163 $are_clients_enabled = ! upstream_is_clients_disabled();
164 $milestones_enabled = ! upstream_disable_milestones();
165 $milestone_tags_enabled = ! upstream_disable_milestone_categories();
166
167 if ( $milestones_enabled ) {
168 $submenu_milestones = $search_submenu_item( '^edit\.php\?post_type=upst_milestone' );
169 if ( null !== $submenu_milestones ) {
170 $new_up_stream_submenu[] = $submenu_milestones;
171 }
172 unset( $submenu_milestones );
173 }
174
175 if ( $milestone_tags_enabled ) {
176 $submenu_milestone_tags = $search_submenu_item( '^edit-tags\.php\?taxonomy=upst_milestone_category&post_type=upst_milestone' );
177 if ( null !== $submenu_milestone_tags ) {
178 $new_up_stream_submenu[] = $submenu_milestone_tags;
179 }
180 unset( $submenu_milestone_tags );
181 }
182
183 $submenu_tasks = $search_submenu_item( '^tasks$' );
184 if ( null !== $submenu_tasks ) {
185 $new_up_stream_submenu[] = $submenu_tasks;
186 }
187 unset( $submenu_tasks );
188
189 $submenu_bugs = $search_submenu_item( '^bugs$' );
190 if ( null !== $submenu_bugs ) {
191 $new_up_stream_submenu[] = $submenu_bugs;
192 }
193 unset( $submenu_bugs );
194
195 if ( $are_clients_enabled ) {
196 $submenu_clients = $search_submenu_item( '^edit\.php\?post_type=client$' );
197 if ( null !== $submenu_clients ) {
198 $new_up_stream_submenu[] = $submenu_clients;
199 }
200 unset( $submenu_clients );
201 }
202
203 if ( $are_categories_enabled ) {
204 $submenu_categories = $search_submenu_item( '^edit\-tags\.php\?taxonomy\=project_category\&amp;post_type=project$' );
205 if ( null !== ! $submenu_categories ) {
206 $new_up_stream_submenu[] = $submenu_categories;
207 }
208 unset( $submenu_categories );
209
210 $submenu_tags = $search_submenu_item( '^edit\-tags\.php\?taxonomy\=upstream_tag\&amp;post_type=project$' );
211 if ( null !== ! $submenu_tags ) {
212 $new_up_stream_submenu[] = $submenu_tags;
213 }
214 unset( $submenu_tags );
215 }
216 }
217
218 $upstream_submenu = apply_filters( 'upstream:custom_menu_order', $new_up_stream_submenu );
219 }
220
221 return $menu;
222 }
223
224 /**
225 * Highlight Parent File
226 *
227 * @param mixed $parent_file Parent File.
228 */
229 public function highlight_parent_file( $parent_file ) {
230 global $current_screen;
231
232 // milestone_categories submenu.
233 if ( isset( $current_screen->taxonomy ) &&
234 'upst_milestone_category' === $current_screen->taxonomy
235 ) {
236 $parent_file = 'edit.php?post_type=project';
237 }
238
239 // clients submenu.
240 if ( isset( $current_screen->post_type ) &&
241 'post' === $current_screen->base &&
242 'client' === $current_screen->post_type
243 ) {
244 $parent_file = 'edit.php?post_type=project';
245 }
246
247 return $parent_file;
248 }
249
250 /**
251 * Highlight Submenu File
252 *
253 * @param mixed $submenu_file Submenu File.
254 */
255 public function highlight_submenu_file( $submenu_file ) {
256 global $current_screen;
257
258 // milestone_categories submenu.
259 if ( isset( $current_screen->taxonomy ) &&
260 'upst_milestone_category' === $current_screen->taxonomy
261 ) {
262 $submenu_file = 'edit-tags.php?taxonomy=upst_milestone_category&post_type=upst_milestone';
263 }
264
265 // clients submenu.
266 if ( isset( $current_screen->post_type ) &&
267 'post' === $current_screen->base &&
268 'client' === $current_screen->post_type
269 ) {
270 $submenu_file = 'edit.php?post_type=client';
271 }
272
273 return $submenu_file;
274 }
275 }
276
277 endif;
278
279 return new UpStream_Admin_Projects_Menu();
280