Created
April 10, 2017 20:40
-
-
Save marcosnakamine/7feb0da40a77e113ab769180ee468ba0 to your computer and use it in GitHub Desktop.
WordPress - Deny access for admin pages
This file contains hidden or 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 | |
add_filter( 'init', 'exclude_pages_from_normal_admin' ); | |
function exclude_pages_from_normal_admin() { | |
global $pagenow; | |
$deny_pages = array( | |
'edit.php', | |
'update-core.php', | |
'upload.php', | |
'edit-comments.php', | |
'themes.php', | |
'customize.php', | |
'theme-editor.php', | |
'plugins.php', | |
'tools.php', | |
'import.php', | |
'export.php', | |
'options-general.php', | |
'options-writing.php', | |
'options-reading.php', | |
'options-discussion.php', | |
'options-media.php', | |
'options-permalink.php' | |
); | |
$current_user = wp_get_current_user(); | |
if ( $current_user->ID != 1 && is_admin() && in_array( $pagenow , $deny_pages ) ) { | |
wp_redirect( admin_url() ); | |
} | |
} | |
add_action( 'admin_menu', 'remove_menus' ); | |
function remove_menus() { | |
$current_user = wp_get_current_user(); | |
if ( $current_user->ID != 1 && is_admin() ) { | |
$deny_pages = array( | |
'edit.php', | |
'edit.php?post_type=page', | |
'update-core.php', | |
'upload.php', | |
'edit-comments.php', | |
'themes.php', | |
'customize.php', | |
'theme-editor.php', | |
'plugins.php', | |
'tools.php', | |
'import.php', | |
'export.php', | |
'options-general.php', | |
'options-writing.php', | |
'options-reading.php', | |
'options-discussion.php', | |
'options-media.php', | |
'options-permalink.php' | |
); | |
foreach ($deny_pages as $key => $value) { | |
remove_menu_page( $value ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment