Skip to content

Commit

Permalink
organize admin sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericoAndrade committed Sep 25, 2024
1 parent dccee24 commit 241691d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions wp-content/themes/blankslate-child/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
require_once('includes/template-helpers.php');
require_once('includes/rest-endpoints.php');
require_once('includes/batch-operations.php');
require_once('includes/admin-helpers.php');
63 changes: 63 additions & 0 deletions wp-content/themes/blankslate-child/includes/admin-helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

function custom_reorder_admin_menu($menu_order) {
global $menu;

// Ensure $menu is properly initialized
if (!is_array($menu)) {
return $menu_order; // Return the original order if $menu is not properly initialized
}

// Define the new order you want for the menu items
$new_order = array(
'index.php', // Dashboard
'separator1', // Separator
'edit.php?post_type=page', // Pages
'separator2', // Separator
'edit.php?post_type=languages', // Languages
'edit.php?post_type=videos', // Videos
'edit.php?post_type=lexicons', // Lexicons
'edit.php?post_type=resources', // Resources
'edit.php?post_type=fellows', // Fellows
'edit.php?post_type=team', // Team
'edit.php?post_type=partners', // Partners
'edit.php?post_type=reports', // Reports
'separator3', // Separator
'upload.php', // Media
'themes.php', // Appearance
'plugins.php', // Plugins
'batch-update.php', // Batch Update
'users.php', // Users
'tools.php', // Tools
'options-general.php', // Settings
);

// Create a new array to hold the reordered menu
$reordered_menu = array();

// Loop through the desired order and add the menu items to the reordered array
foreach ($new_order as $item) {
foreach ($menu as $key => $value) {
if ($value[2] == $item) {
$reordered_menu[$key] = $value;
unset($menu[$key]); // Remove the item from the original menu
break;
}
}
}

// Add any remaining menu items that were not in the desired order to the end
$menu = array_merge($reordered_menu, $menu); // Update the global $menu with the new order

return array_keys($menu); // Return the reordered menu keys
}
add_filter('custom_menu_order', '__return_true');
add_filter('menu_order', 'custom_reorder_admin_menu', 999); // Set a high priority to execute last

// Remove specific menu items
function custom_remove_menu_pages() {
remove_menu_page('edit.php'); // Posts
// remove_menu_page('upload.php'); // Media
remove_menu_page('edit-comments.php'); // Comments
}
add_action('admin_menu', 'custom_remove_menu_pages', 999); // Ensure this runs after custom_reorder_admin_menu

0 comments on commit 241691d

Please sign in to comment.