We can do this by adding a function function to remove the menu item in the functions.php file.
Add the following code to the functions.php file in the current topic:
code is as follows |
copy code |
function Remove_menus () { Global $menu; //The menu items that need to be removed are listed below $restricted = Array (__ (' Dashboard '), __ (' Posts '), __ (' Media ') ), __ (' Links '), __ (' Pages '), __ (' appearance '), __ (' Tools '), __ (' Users '), __ (' Settings '), __ (' Comments '), __ (' Plugins ') ); End ($menu); while (prev ($menu)) { $value = explode (', $menu [Key ($menu)][0]); if (In_array ($value [0]!= NULL? $value [0]: " ", $restricted)) { unset ($menu [Key ($menu)]); } } //Remove Sidebar menu add_action (' Admin_menu ', ' Remove_menus '); |
The $restricted array in the above code provides all the menu items, and if you copy the above code to the functions.php file intact, then you don't have any menus in WordPress background, so You should only remove unnecessary menu items according to the actual needs.
The code is as follows |
Copy Code |
$restricted the menu corresponding to each array item in English: __ (' Dashboard '): Control Panel __ (' Posts '): article __ (' media '): Media __ (' links '): Links __ (' pages '): page __ (' Comments '): Comments __ (' appearance '): Appearance __ (' Plugins '): Plugin __ (' users '): User __ (' Tools '): Tools __ (' Settings '): setting |
If you want to remove the sidebar menu by different user roles, you can add a user-level judgment. We can do this: add a judgment statement to the add_action mentioned in the above code, and change it to read as follows:
code is as follows |
copy code |
function Remove_menus () { Global $menu; The $restricted here sets the appearance and media two menu items $restricted = Array (__ (' appearance '), __ (' Media '); End ($menu); while (prev ($menu)) { $value = Explode (', $menu [Key ($menu)][0]); if (In_array ($value [0]!= NULL? $value [0]: "", $restricted)) { unset ($menu [Key ($menu)]); } } } Global $current _user; Get_currentuserinfo (); If the current user's level is less than 4, delete the corresponding menu item if ($current _user->user_level < 4) { Add_action (' Admin_menu ', ' Remove_menus '); } |
Attached: User roles and their level of correspondence are as follows:
0-Level counterpart subscriber
Level 1 Counterpart Contributors
2–4-level corresponding author
5–7 level corresponding Edit
8–10 level corresponding Administrator