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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 1 year ago class-admin-menu-organizer.php 1 year ago class-auto-publish-posts-with-missed-schedule.php 1 year ago class-avif-upload.php 1 year ago class-captcha-protection.php 1 year ago class-change-login-url.php 1 year ago class-cleanup-admin-bar.php 1 year ago class-common-methods.php 1 year ago class-content-duplication.php 1 year ago class-content-order.php 1 year ago class-custom-admin-footer-text.php 1 year ago class-custom-body-class.php 1 year ago class-custom-css.php 1 year ago class-custom-nav-menu-items-in-new-tab.php 1 year ago class-deactivation.php 1 year ago class-disable-comments.php 1 year ago class-disable-dashboard-widgets.php 1 year ago class-disable-feeds.php 1 year ago class-disable-gutenberg.php 1 year ago class-disable-rest-api.php 1 year ago class-disable-smaller-components.php 1 year ago class-disable-updates.php 1 year ago class-disable-xml-rpc.php 1 year ago class-display-system-summary.php 1 year ago class-email-address-obfuscator.php 1 year ago class-email-delivery.php 1 year ago class-enhance-list-tables.php 1 year ago class-external-permalinks.php 1 year ago class-heartbeat-control.php 1 year ago class-hide-admin-bar.php 1 year ago class-hide-admin-notices.php 1 year ago class-image-sizes-panel.php 1 year ago class-image-upload-control.php 1 year ago class-insert-head-body-footer-code.php 1 year ago class-last-login-column.php 1 year ago class-limit-login-attempts.php 1 year ago class-login-id-type.php 1 year ago class-login-logout-menu.php 1 year ago class-maintenance-mode.php 1 year ago class-manage-ads-appads-txt.php 1 year ago class-manage-robots-txt.php 1 year ago class-media-replacement.php 1 year ago class-multiple-user-roles.php 1 year ago class-obfuscate-author-slugs.php 1 year ago class-open-external-links-in-new-tab.php 1 year ago class-password-protection.php 1 year ago class-redirect-after-login.php 1 year ago class-redirect-after-logout.php 1 year ago class-redirect-fourofour.php 1 year ago class-registration-date-column.php 1 year ago class-revisions-control.php 1 year ago class-search-engines-visibility.php 1 year ago class-settings-fields-render.php 1 year ago class-settings-sanitization.php 1 year ago class-settings-sections-fields.php 1 year ago class-show-custom-taxonomy-filters.php 1 year ago class-site-identity-on-login-page.php 1 year ago class-svg-upload.php 1 year ago class-various-admin-ui-enhancements.php 1 year ago class-view-admin-as-role.php 1 year ago class-wider-admin-menu.php 1 year ago class-wp-config-transformer.php 1 year ago
class-admin-menu-organizer.php
415 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 * Add Admin Menu item under Settings menu
13 *
14 * @since 7.8.5
15 */
16 public function add_menu_item() {
17 add_submenu_page(
18 'options-general.php',
19 // Parent page/menu
20 __( 'Admin Menu Settings', 'admin-site-enhancements' ),
21 // Browser tab/window title
22 __( 'Admin Menu', 'admin-site-enhancements' ),
23 // Sube menu title
24 'manage_options',
25 // Minimal user capabililty
26 'admin-menu-organizer',
27 // Page slug. Shows up in URL.
28 array($this, 'add_admin_menu_settings_page')
29 );
30 }
31
32 /**
33 * Create settings page for Admin Menu
34 *
35 * @since 7.8.5
36 */
37 public function add_admin_menu_settings_page() {
38 $render_field = new Settings_Fields_Render();
39 ?>
40 <div class="wrap admin-menu-organizer">
41 <h1 class="wp-heading-inline"><?php
42 echo __( 'Admin Menu Organizer', 'admin-site-enhancements' );
43 ?></h1>
44 <div class="admin-menu-organizer-main">
45 <div class="admin-menu-sortables-wrapper">
46 <?php
47 $render_field->render_sortable_menu();
48 ?>
49 </div>
50 <div class="admin-menu-actions">
51 <button id="amo-save-changes" class="button button-primary button-large"><?php
52 echo __( 'Save Changes', 'admin-site-enhancements' );
53 ?></button>
54 <div class="asenha-saving-changes" style="display:none;"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="#2271b1" d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z" opacity=".25"/><path fill="#2271b1" d="M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"><animateTransform attributeName="transform" dur="0.75s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></svg></div>
55 <div class="asenha-changes-saved" style="display:none;"><svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24"><path fill="seagreen" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10s10-4.48 10-10S17.52 2 12 2zM9.29 16.29L5.7 12.7a.996.996 0 1 1 1.41-1.41L10 14.17l6.88-6.88a.996.996 0 1 1 1.41 1.41l-7.59 7.59a.996.996 0 0 1-1.41 0z"/></svg></div>
56 </div>
57 </div>
58 </div>
59 <?php
60 }
61
62 /**
63 * Render custom menu order
64 *
65 * @param $menu_order array an ordered array of menu items
66 * @link https://developer.wordpress.org/reference/hooks/menu_order/
67 * @since 2.0.0
68 */
69 public function render_custom_menu_order( $menu_order ) {
70 global $menu;
71 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
72 $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() );
73 // Get current menu order. We're not using the default $menu_order which uses index.php, edit.php as array values.
74 $current_menu_order = array();
75 foreach ( $menu as $menu_key => $menu_info ) {
76 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
77 $menu_item_id = $menu_info[2];
78 } else {
79 $menu_item_id = $menu_info[5];
80 }
81 $current_menu_order[] = array($menu_item_id, $menu_info[2]);
82 }
83 // Get custom menu order
84 $custom_menu_order = $options['custom_menu_order'];
85 // comma separated
86 $custom_menu_order = explode( ",", $custom_menu_order );
87 // array of menu ID, e.g. menu-dashboard
88 // Return menu order for rendering
89 $rendered_menu_order = array();
90 // Render menu based on items saved in custom menu order
91 foreach ( $custom_menu_order as $custom_menu_item_id ) {
92 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
93 if ( $custom_menu_item_id == $current_menu_item[0] ) {
94 $rendered_menu_order[] = $current_menu_item[1];
95 }
96 }
97 }
98 // Add items from current menu not already part of custom menu order, e.g. new plugin activated and adds new menu item
99 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
100 if ( !in_array( $current_menu_item[0], $custom_menu_order ) ) {
101 $rendered_menu_order[] = $current_menu_item[1];
102 }
103 }
104 return $rendered_menu_order;
105 }
106
107 /**
108 * Apply custom menu item titles
109 *
110 * @since 2.9.0
111 */
112 public function apply_custom_menu_item_titles() {
113 global $menu;
114 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
115 $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() );
116 // Get custom menu item titles
117 $custom_menu_titles = $options['custom_menu_titles'];
118 $custom_menu_titles = explode( ',', $custom_menu_titles );
119 foreach ( $menu as $menu_key => $menu_info ) {
120 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
121 $menu_item_id = $menu_info[2];
122 } else {
123 $menu_item_id = $menu_info[5];
124 }
125 // Get defaul/custom menu item title
126 foreach ( $custom_menu_titles as $custom_menu_title ) {
127 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
128 $custom_menu_title = explode( '__', $custom_menu_title );
129 if ( $custom_menu_title[0] == $menu_item_id ) {
130 $menu_item_title = $custom_menu_title[1];
131 // e.g. Code Snippets
132 break;
133 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
134 } else {
135 $menu_item_title = $menu_info[0];
136 }
137 }
138 $menu[$menu_key][0] = $menu_item_title;
139 }
140 }
141
142 /**
143 * Get custom title for 'Posts' menu item
144 *
145 * @since 6.9.13
146 */
147 public function get_posts_custom_title() {
148 $post_object = get_post_type_object( 'post' );
149 // object
150 $posts_default_title = '';
151 if ( is_object( $post_object ) ) {
152 if ( property_exists( $post_object, 'label' ) ) {
153 $posts_default_title = $post_object->label;
154 } else {
155 $posts_default_title = $post_object->labels->name;
156 }
157 }
158 $posts_custom_title = $posts_default_title;
159 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
160 $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() );
161 $custom_menu_titles = ( isset( $options['custom_menu_titles'] ) ? explode( ',', $options['custom_menu_titles'] ) : array() );
162 if ( !empty( $custom_menu_titles ) ) {
163 foreach ( $custom_menu_titles as $custom_menu_title ) {
164 if ( false !== strpos( $custom_menu_title, 'menu-posts__' ) ) {
165 $custom_menu_title = explode( '__', $custom_menu_title );
166 $posts_custom_title = $custom_menu_title[1];
167 }
168 }
169 }
170 return $posts_custom_title;
171 }
172
173 /**
174 * For 'Posts', apply custom label
175 *
176 * @link https://developer.wordpress.org/reference/hooks/post_type_labels_post_type/
177 * @since 6.9.13
178 */
179 public function change_post_labels( $labels ) {
180 $post_object = get_post_type_object( 'post' );
181 // object
182 $posts_default_title_plural = '';
183 if ( is_object( $post_object ) ) {
184 if ( property_exists( $post_object, 'label' ) ) {
185 $posts_default_title_plural = $post_object->label;
186 } else {
187 $posts_default_title_plural = $post_object->labels->name;
188 }
189 $posts_default_title_singular = $post_object->labels->singular_name;
190 $posts_custom_title = $this->get_posts_custom_title();
191 foreach ( $labels as $key => $label ) {
192 if ( null === $label ) {
193 continue;
194 }
195 $labels->{$key} = str_replace( [$posts_default_title_plural, $posts_default_title_singular], $posts_custom_title, $label );
196 }
197 }
198 return $labels;
199 }
200
201 /**
202 * For 'Posts', apply custom label in post object
203 *
204 * @since 6.9.12
205 */
206 public function change_post_object_label() {
207 global $wp_post_types;
208 $posts_custom_title = $this->get_posts_custom_title();
209 $labels =& $wp_post_types['post']->labels;
210 $labels->name = $posts_custom_title;
211 $labels->singular_name = $posts_custom_title;
212 $labels->all_items = sprintf(
213 /* translators: %s is post type or taxonomy label */
214 __( 'All %s', 'admin-site-enhancements' ),
215 $posts_custom_title
216 );
217 $labels->add_new = __( 'Add New', 'admin-site-enhancements' );
218 $labels->add_new_item = __( 'Add New', 'admin-site-enhancements' );
219 $labels->edit_item = __( 'Edit', 'admin-site-enhancements' );
220 $labels->new_item = $posts_custom_title;
221 $labels->view_item = __( 'View', 'admin-site-enhancements' );
222 $labels->search_items = sprintf(
223 /* translators: %s is post type or taxonomy label */
224 __( 'Search %s', 'admin-site-enhancements' ),
225 $posts_custom_title
226 );
227 $labels->not_found = sprintf(
228 /* translators: %s is the post type label */
229 __( 'No %s found', 'admin-site-enhancements' ),
230 strtolower( $posts_custom_title )
231 );
232 $labels->not_found_in_trash = sprintf(
233 /* translators: %s is the post type label */
234 __( 'No %s found in Trash', 'admin-site-enhancements' ),
235 strtolower( $posts_custom_title )
236 );
237 }
238
239 /**
240 * For 'Posts', apply custom label in menu and submenu
241 *
242 * @since 6.9.12
243 */
244 public function change_post_menu_label() {
245 global $submenu;
246 $posts_custom_title = $this->get_posts_custom_title();
247 if ( !empty( $posts_custom_title ) ) {
248 $submenu['edit.php'][5][0] = sprintf(
249 /* translators: %s is post type or taxonomy label */
250 __( 'All %s', 'admin-site-enhancements' ),
251 $posts_custom_title
252 );
253 } else {
254 $submenu['edit.php'][5][0] = sprintf(
255 /* translators: %s is post type or taxonomy label */
256 __( 'All %s', 'admin-site-enhancements' ),
257 $posts_default_title
258 );
259 }
260 }
261
262 /**
263 * For 'Posts', apply custom label in admin bar
264 *
265 * @since 6.9.12
266 */
267 public function change_wp_admin_bar( $wp_admin_bar ) {
268 $posts_custom_title = $this->get_posts_custom_title();
269 $new_post_node = $wp_admin_bar->get_node( 'new-post' );
270 if ( $new_post_node ) {
271 $new_post_node->title = $posts_custom_title;
272 $wp_admin_bar->add_node( $new_post_node );
273 }
274 }
275
276 /**
277 * Hide parent menu items by adding class(es) to hide them
278 *
279 * @since 2.0.0
280 */
281 public function hide_menu_items() {
282 global $menu;
283 $common_methods = new Common_Methods();
284 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
285 // indexed array
286 foreach ( $menu as $menu_key => $menu_info ) {
287 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
288 $menu_item_id = $menu_info[2];
289 } else {
290 $menu_item_id = $menu_info[5];
291 }
292 // Append 'hidden' class to hide menu item until toggled
293 if ( in_array( $menu_item_id, $menu_hidden_by_toggle ) ) {
294 $menu[$menu_key][4] = $menu_info[4] . ' hidden asenha_hidden_menu';
295 }
296 }
297 }
298
299 /**
300 * Add toggle to show hidden menu items
301 *
302 * @since 2.0.0
303 */
304 public function add_hidden_menu_toggle() {
305 global $current_user;
306 // Get menu items hidden by toggle
307 $common_methods = new Common_Methods();
308 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
309 $submenu_hidden_by_toggle = array();
310 // Get user capabilities the "Show All/Less" toggle should be shown for
311 $user_capabilities_to_show_menu_toggle_for = $common_methods->get_user_capabilities_to_show_menu_toggle_for();
312 // Get current user's capabilities from the user's role(s)
313 $current_user_capabilities = '';
314 $current_user_roles = $current_user->roles;
315 // indexed array of role slugs
316 foreach ( $current_user_roles as $current_user_role ) {
317 $current_user_role_capabilities = get_role( $current_user_role )->capabilities;
318 if ( is_array( $current_user_role_capabilities ) ) {
319 $current_user_role_capabilities = array_keys( $current_user_role_capabilities );
320 // indexed array
321 $current_user_role_capabilities = implode( ",", $current_user_role_capabilities );
322 $current_user_capabilities .= $current_user_role_capabilities;
323 }
324 }
325 // Maybe show "Show All/Less" toggle
326 $show_toggle_menu = false;
327 if ( !empty( $current_user_capabilities ) ) {
328 $current_user_capabilities = array_unique( explode( ",", $current_user_capabilities ) );
329 foreach ( $user_capabilities_to_show_menu_toggle_for as $user_capability_to_show_menu_toggle_for ) {
330 if ( in_array( $user_capability_to_show_menu_toggle_for, $current_user_capabilities ) ) {
331 $show_toggle_menu = true;
332 break;
333 }
334 }
335 }
336 if ( (!empty( $menu_hidden_by_toggle ) || !empty( $submenu_hidden_by_toggle )) && $show_toggle_menu ) {
337 add_menu_page(
338 __( 'Show All', 'admin-site-enhancements' ),
339 __( 'Show All', 'admin-site-enhancements' ),
340 'read',
341 'asenha_show_hidden_menu',
342 function () {
343 return false;
344 },
345 "dashicons-arrow-down-alt2",
346 300
347 );
348 add_menu_page(
349 __( 'Show Less', 'admin-site-enhancements' ),
350 __( 'Show Less', 'admin-site-enhancements' ),
351 'read',
352 'asenha_hide_hidden_menu',
353 function () {
354 return false;
355 },
356 "dashicons-arrow-up-alt2",
357 301
358 );
359 }
360 }
361
362 /**
363 * Script to toggle hidden menu itesm
364 *
365 * @since 2.0.0
366 */
367 public function enqueue_toggle_hidden_menu_script() {
368 // Get menu items hidden by toggle
369 $common_methods = new Common_Methods();
370 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
371 $submenu_hidden_by_toggle = array();
372 if ( !empty( $menu_hidden_by_toggle ) || !empty( $submenu_hidden_by_toggle ) ) {
373 // Script to set behaviour and actions of the sortable menu
374 wp_enqueue_script(
375 'asenha-toggle-hidden-menu',
376 ASENHA_URL . 'assets/js/toggle-hidden-menu.js',
377 array(),
378 ASENHA_VERSION,
379 false
380 );
381 }
382 }
383
384 /**
385 * Save admin menu via AJAX
386 *
387 * @since 6.3.1
388 */
389 public function save_admin_menu() {
390 if ( isset( $_REQUEST ) ) {
391 if ( check_ajax_referer( 'save-menu-nonce', 'nonce', false ) ) {
392 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
393 $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() );
394 $options['custom_menu_order'] = ( isset( $_REQUEST['custom_menu_order'] ) ? $_REQUEST['custom_menu_order'] : $options['custom_menu_order'] );
395 $options['custom_menu_titles'] = ( isset( $_REQUEST['custom_menu_titles'] ) ? $_REQUEST['custom_menu_titles'] : $options['custom_menu_titles'] );
396 $options['custom_menu_hidden'] = ( isset( $_REQUEST['custom_menu_hidden'] ) ? $_REQUEST['custom_menu_hidden'] : $options['custom_menu_hidden'] );
397 $options_extra['admin_menu'] = $options;
398 // vi( $options_extra, '', 'save menu' );
399 $updated = update_option( ASENHA_SLUG_U . '_extra', $options_extra, true );
400 if ( $updated ) {
401 $response = array(
402 'status' => 'success',
403 );
404 } else {
405 $response = array(
406 'status' => 'failed',
407 );
408 }
409 echo json_encode( $response );
410 }
411 }
412 }
413
414 }
415