Skip to content

Instantly share code, notes, and snippets.

@Kevin-LeMasters-PixelParade
Last active April 18, 2024 17:32
Show Gist options
  • Save Kevin-LeMasters-PixelParade/45caf8546f06d5fe8be4f4ce24413beb to your computer and use it in GitHub Desktop.
Save Kevin-LeMasters-PixelParade/45caf8546f06d5fe8be4f4ce24413beb to your computer and use it in GitHub Desktop.

Hide WPCodebox menu item and page from other users.

Make it availble to all admins with email of @agencyemail or by username

add_action("admin_init", "disable_access_to_wpcodebox");
function disable_access_to_wpcodebox()
{
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
$username = $current_user->user_login;
if (
strpos($current_user->user_email, "@agencyemail") === false &&
!in_array($username, ["Usernameexample1", "Usernameexample2"])
) {
remove_menu_page("wpcodebox2");
if (isset($_GET["page"]) && $_GET["page"] === "wpcodebox2") {
wp_die("You do not have permission to access this page.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment