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 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-admin-menu-organizer.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-columns-manager.php 2 years ago class-admin-menu-organizer.php 2 years ago class-auto-publish-posts-with-missed-schedule.php 2 years ago class-avif-upload.php 2 years ago class-change-login-url.php 2 years ago class-cleanup-admin-bar.php 2 years ago class-code-snippets-manager.php 2 years ago class-common-methods.php 2 years ago class-content-duplication.php 2 years ago class-content-order.php 2 years ago class-custom-admin-footer-text.php 2 years ago class-custom-body-class.php 2 years ago class-custom-content-types.php 2 years ago class-custom-css.php 2 years ago class-custom-nav-menu-items-in-new-tab.php 2 years ago class-deactivation.php 2 years ago class-disable-comments.php 2 years ago class-disable-dashboard-widgets.php 2 years ago class-disable-feeds.php 2 years ago class-disable-gutenberg.php 2 years ago class-disable-rest-api.php 2 years ago class-disable-smaller-components.php 2 years ago class-disable-updates.php 2 years ago class-disable-xml-rpc.php 2 years ago class-display-system-summary.php 2 years ago class-email-address-obfuscator.php 2 years ago class-email-delivery.php 2 years ago class-enhance-list-tables.php 2 years ago class-external-permalinks.php 2 years ago class-heartbeat-control.php 2 years ago class-hide-admin-bar.php 2 years ago class-hide-admin-notices.php 2 years ago class-image-sizes-panel.php 2 years ago class-image-upload-control.php 2 years ago class-insert-head-body-footer-code.php 2 years ago class-last-login-column.php 2 years ago class-limit-login-attempts.php 2 years ago class-login-id-type.php 2 years ago class-login-logout-menu.php 2 years ago class-maintenance-mode.php 2 years ago class-manage-ads-appads-txt.php 2 years ago class-manage-robots-txt.php 2 years ago class-media-replacement.php 2 years ago class-multiple-user-roles.php 2 years ago class-obfuscate-author-slugs.php 2 years ago class-open-external-links-in-new-tab.php 2 years ago class-password-protection.php 2 years ago class-redirect-after-login.php 2 years ago class-redirect-after-logout.php 2 years ago class-redirect-fourofour.php 2 years ago class-revisions-control.php 2 years ago class-search-engines-visibility.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-show-custom-taxonomy-filters.php 2 years ago class-site-identity-on-login-page.php 2 years ago class-svg-upload.php 2 years ago class-various-admin-ui-enhancements.php 2 years ago class-view-admin-as-role.php 2 years ago class-wider-admin-menu.php 2 years ago
class-admin-menu-organizer.php
316 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class for Admin Menu Organizer module
7 *
8 * @since 6.9.5
9 */
10 class Admin_Menu_Organizer {
11 /**
12 * Render custom menu order
13 *
14 * @param $menu_order array an ordered array of menu items
15 * @link https://developer.wordpress.org/reference/hooks/menu_order/
16 * @since 2.0.0
17 */
18 public function render_custom_menu_order( $menu_order ) {
19 global $menu;
20 $options = get_option( ASENHA_SLUG_U );
21 // Get current menu order. We're not using the default $menu_order which uses index.php, edit.php as array values.
22 $current_menu_order = array();
23 foreach ( $menu as $menu_key => $menu_info ) {
24 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
25 $menu_item_id = $menu_info[2];
26 } else {
27 $menu_item_id = $menu_info[5];
28 }
29 $current_menu_order[] = array($menu_item_id, $menu_info[2]);
30 }
31 // Get custom menu order
32 $custom_menu_order = $options['custom_menu_order'];
33 // comma separated
34 $custom_menu_order = explode( ",", $custom_menu_order );
35 // array of menu ID, e.g. menu-dashboard
36 // Return menu order for rendering
37 $rendered_menu_order = array();
38 // Render menu based on items saved in custom menu order
39 foreach ( $custom_menu_order as $custom_menu_item_id ) {
40 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
41 if ( $custom_menu_item_id == $current_menu_item[0] ) {
42 $rendered_menu_order[] = $current_menu_item[1];
43 }
44 }
45 }
46 // Add items from current menu not already part of custom menu order, e.g. new plugin activated and adds new menu item
47 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
48 if ( !in_array( $current_menu_item[0], $custom_menu_order ) ) {
49 $rendered_menu_order[] = $current_menu_item[1];
50 }
51 }
52 return $rendered_menu_order;
53 }
54
55 /**
56 * Apply custom menu item titles
57 *
58 * @since 2.9.0
59 */
60 public function apply_custom_menu_item_titles() {
61 global $menu;
62 $options = get_option( ASENHA_SLUG_U );
63 // Get custom menu item titles
64 $custom_menu_titles = $options['custom_menu_titles'];
65 $custom_menu_titles = explode( ',', $custom_menu_titles );
66 foreach ( $menu as $menu_key => $menu_info ) {
67 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
68 $menu_item_id = $menu_info[2];
69 } else {
70 $menu_item_id = $menu_info[5];
71 }
72 // Get defaul/custom menu item title
73 foreach ( $custom_menu_titles as $custom_menu_title ) {
74 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
75 $custom_menu_title = explode( '__', $custom_menu_title );
76 if ( $custom_menu_title[0] == $menu_item_id ) {
77 $menu_item_title = $custom_menu_title[1];
78 // e.g. Code Snippets
79 break;
80 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
81 } else {
82 $menu_item_title = $menu_info[0];
83 }
84 }
85 $menu[$menu_key][0] = $menu_item_title;
86 }
87 }
88
89 /**
90 * Get custom title for 'Posts' menu item
91 *
92 * @since 6.9.13
93 */
94 public function get_posts_custom_title() {
95 $post_object = get_post_type_object( 'post' );
96 // object
97 if ( property_exists( $post_object, 'label' ) ) {
98 $posts_default_title = $post_object->label;
99 } else {
100 $posts_default_title = $post_object->labels->name;
101 }
102 $posts_custom_title = $posts_default_title;
103 $options = get_option( ASENHA_SLUG_U );
104 $custom_menu_titles = ( isset( $options['custom_menu_titles'] ) ? explode( ',', $options['custom_menu_titles'] ) : array() );
105 if ( !empty( $custom_menu_titles ) ) {
106 foreach ( $custom_menu_titles as $custom_menu_title ) {
107 if ( false !== strpos( $custom_menu_title, 'menu-posts__' ) ) {
108 $custom_menu_title = explode( '__', $custom_menu_title );
109 $posts_custom_title = $custom_menu_title[1];
110 }
111 }
112 }
113 return $posts_custom_title;
114 }
115
116 /**
117 * For 'Posts', apply custom label
118 *
119 * @link https://developer.wordpress.org/reference/hooks/post_type_labels_post_type/
120 * @since 6.9.13
121 */
122 public function change_post_labels( $labels ) {
123 $post_object = get_post_type_object( 'post' );
124 // object
125 if ( property_exists( $post_object, 'label' ) ) {
126 $posts_default_title_plural = $post_object->label;
127 } else {
128 $posts_default_title_plural = $post_object->labels->name;
129 }
130 $posts_default_title_singular = $post_object->labels->singular_name;
131 $posts_custom_title = $this->get_posts_custom_title();
132 foreach ( $labels as $key => $label ) {
133 if ( null === $label ) {
134 continue;
135 }
136 $labels->{$key} = str_replace( [$posts_default_title_plural, $posts_default_title_singular], $posts_custom_title, $label );
137 }
138 return $labels;
139 }
140
141 /**
142 * For 'Posts', apply custom label in post object
143 *
144 * @since 6.9.12
145 */
146 public function change_post_object_label() {
147 global $wp_post_types;
148 $posts_custom_title = $this->get_posts_custom_title();
149 $labels =& $wp_post_types['post']->labels;
150 $labels->name = $posts_custom_title;
151 $labels->singular_name = $posts_custom_title;
152 $labels->add_new = __( 'Add New', 'admin-site-enhancements' );
153 $labels->add_new_item = __( 'Add New', 'admin-site-enhancements' );
154 $labels->edit_item = __( 'Edit', 'admin-site-enhancements' );
155 $labels->new_item = $posts_custom_title;
156 $labels->view_item = __( 'View', 'admin-site-enhancements' );
157 $labels->search_items = sprintf(
158 /* translators: %s is the post type label */
159 'Search %s',
160 $posts_custom_title
161 );
162 $labels->not_found = sprintf(
163 /* translators: %s is the post type label */
164 'No %s found',
165 strtolower( $posts_custom_title )
166 );
167 $labels->not_found_in_trash = sprintf(
168 /* translators: %s is the post type label */
169 'No %s found in Trash',
170 strtolower( $posts_custom_title )
171 );
172 }
173
174 /**
175 * For 'Posts', apply custom label in menu and submenu
176 *
177 * @since 6.9.12
178 */
179 public function change_post_menu_label() {
180 global $submenu;
181 $posts_custom_title = $this->get_posts_custom_title();
182 if ( !empty( $posts_custom_title ) ) {
183 $submenu['edit.php'][5][0] = sprintf(
184 /* translators: %s is the post type label */
185 'All %s',
186 $posts_custom_title
187 );
188 } else {
189 $submenu['edit.php'][5][0] = sprintf(
190 /* translators: %s is the post type label */
191 'All %s',
192 $posts_default_title
193 );
194 }
195 }
196
197 /**
198 * For 'Posts', apply custom label in admin bar
199 *
200 * @since 6.9.12
201 */
202 public function change_wp_admin_bar( $wp_admin_bar ) {
203 $posts_custom_title = $this->get_posts_custom_title();
204 $new_post_node = $wp_admin_bar->get_node( 'new-post' );
205 if ( $new_post_node ) {
206 $new_post_node->title = $posts_custom_title;
207 $wp_admin_bar->add_node( $new_post_node );
208 }
209 }
210
211 /**
212 * Hide parent menu items by adding class(es) to hide them
213 *
214 * @since 2.0.0
215 */
216 public function hide_menu_items() {
217 global $menu;
218 $common_methods = new Common_Methods();
219 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
220 // indexed array
221 foreach ( $menu as $menu_key => $menu_info ) {
222 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
223 $menu_item_id = $menu_info[2];
224 } else {
225 $menu_item_id = $menu_info[5];
226 }
227 // Append 'hidden' class to hide menu item until toggled
228 if ( in_array( $menu_item_id, $menu_hidden_by_toggle ) ) {
229 $menu[$menu_key][4] = $menu_info[4] . ' hidden asenha_hidden_menu';
230 }
231 }
232 }
233
234 /**
235 * Add toggle to show hidden menu items
236 *
237 * @since 2.0.0
238 */
239 public function add_hidden_menu_toggle() {
240 global $current_user;
241 // Get menu items hidden by toggle
242 $common_methods = new Common_Methods();
243 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
244 $submenu_hidden_by_toggle = array();
245 // Get user capabilities the "Show All/Less" toggle should be shown for
246 $user_capabilities_to_show_menu_toggle_for = $common_methods->get_user_capabilities_to_show_menu_toggle_for();
247 // Get current user's capabilities from the user's role(s)
248 $current_user_capabilities = '';
249 $current_user_roles = $current_user->roles;
250 // indexed array of role slugs
251 foreach ( $current_user_roles as $current_user_role ) {
252 $current_user_role_capabilities = get_role( $current_user_role )->capabilities;
253 $current_user_role_capabilities = array_keys( $current_user_role_capabilities );
254 // indexed array
255 $current_user_role_capabilities = implode( ",", $current_user_role_capabilities );
256 $current_user_capabilities .= $current_user_role_capabilities;
257 }
258 $current_user_capabilities = array_unique( explode( ",", $current_user_capabilities ) );
259 // Maybe show "Show All/Less" toggle
260 $show_toggle_menu = false;
261 foreach ( $user_capabilities_to_show_menu_toggle_for as $user_capability_to_show_menu_toggle_for ) {
262 if ( in_array( $user_capability_to_show_menu_toggle_for, $current_user_capabilities ) ) {
263 $show_toggle_menu = true;
264 break;
265 }
266 }
267 if ( (!empty( $menu_hidden_by_toggle ) || !empty( $submenu_hidden_by_toggle )) && $show_toggle_menu ) {
268 add_menu_page(
269 __( 'Show All', 'admin-site-enhancements' ),
270 __( 'Show All', 'admin-site-enhancements' ),
271 'read',
272 'asenha_show_hidden_menu',
273 function () {
274 return false;
275 },
276 "dashicons-arrow-down-alt2",
277 300
278 );
279 add_menu_page(
280 __( 'Show Less', 'admin-site-enhancements' ),
281 __( 'Show Less', 'admin-site-enhancements' ),
282 'read',
283 'asenha_hide_hidden_menu',
284 function () {
285 return false;
286 },
287 "dashicons-arrow-up-alt2",
288 301
289 );
290 }
291 }
292
293 /**
294 * Script to toggle hidden menu itesm
295 *
296 * @since 2.0.0
297 */
298 public function enqueue_toggle_hidden_menu_script() {
299 // Get menu items hidden by toggle
300 $common_methods = new Common_Methods();
301 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
302 $submenu_hidden_by_toggle = array();
303 if ( !empty( $menu_hidden_by_toggle ) || !empty( $submenu_hidden_by_toggle ) ) {
304 // Script to set behaviour and actions of the sortable menu
305 wp_enqueue_script(
306 'asenha-toggle-hidden-menu',
307 ASENHA_URL . 'assets/js/toggle-hidden-menu.js',
308 array(),
309 ASENHA_VERSION,
310 false
311 );
312 }
313 }
314
315 }
316