Instantly share code, notes, and snippets.
Created
July 21, 2013 08:58
-
Save aristath/6047982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Custom Remove Admin Menus - Extras | |
Plugin URI: http://aristeides.com | |
Description: Remove admin menus & secure some areas of the dashboard - Upload and Activate. | |
Author: Aristeides Stathopoulos | |
Version: 1.0 | |
Author URI: http://aristeides.com | |
*/ | |
/* | |
* Hide admin menus for non Network Admins | |
*/ | |
function custom_remove_admin_theme_remove_menus () { | |
if( !current_user_can( 'manage_network' ) ) { | |
global $menu; | |
$restricted = array(__('Posts'), __('Media'), __('Links'), __('Pages'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'), __('QRcode'), __('CustomPress')); | |
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_menu_page( 'edit-comments.php' ); | |
remove_menu_page( 'themes.php' ); | |
remove_menu_page( 'plugins.php' ); | |
remove_menu_page( 'admin.php?page=mp_st' ); | |
remove_menu_page( 'admin.php?page=cp_main' ); | |
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_category&post_type=product' ); | |
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=brand&post_type=product' ); | |
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=model&post_type=product' ); | |
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_tag&post_type=product' ); | |
} | |
} | |
add_action('admin_menu', 'custom_remove_admin_theme_remove_menus', 10); | |
/* | |
* Hide Dahboard Widgets | |
*/ | |
function custom_remove_remove_dashboard_widgets() { | |
remove_meta_box('icl_dashboard_widget', 'dashboard', 'normal'); | |
} | |
add_action('admin_init', 'custom_remove_remove_dashboard_widgets'); | |
/* | |
* If user is not an admin, do not allow access to the dashboard AT ALL. | |
*/ | |
function custom_remove_no_admin_access(){ | |
if( !current_user_can( 'administrator' ) ) { | |
wp_redirect( home_url() ); | |
die(); | |
} | |
} | |
add_action( 'admin_init', 'custom_remove_no_admin_access', 1 ); | |
/* | |
* If user is not a SuperAdmin, when they try to access the below URLs they are redirected back to the dashboard. | |
*/ | |
function restrict_admin_with_redirect() { | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/widgets.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/user-new.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/upgrade-functions.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/upgrade.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/themes.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/theme-install.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/theme-editor.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/setup-config.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/plugins.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/plugin-install.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-writing.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-reading.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-privacy.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-permalink.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-media.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-head.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-general.php.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options-discussion.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/options.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/network.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-users.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-upgrade-network.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-themes.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-sites.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-options.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-edit.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-delete-site.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/ms-admin.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/moderation.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/menu-header.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/menu.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/edit-tags.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/edit-tag-form.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/edit-link-form.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/edit-comments.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/credits.php'){ wp_redirect(admin_url() ); exit; } | |
if (!current_user_can('manage_network') && $_SERVER['PHP_SELF'] == '/wp-admin/about.php'){ wp_redirect(admin_url() ); exit; } | |
} | |
add_action('admin_init', 'restrict_admin_with_redirect'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment