Skip to content

Instantly share code, notes, and snippets.

@vaughnroyko
Last active June 23, 2017 20:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaughnroyko/8960185 to your computer and use it in GitHub Desktop.
Save vaughnroyko/8960185 to your computer and use it in GitHub Desktop.
Advanced/Basic Menu & Workflow for Wordpress Admin
<?php
//Add in a customized Wordpress admin workflow for a simplified experience
function edit_admin_menus() {
//Set this as what ever you want the default admin landing page to be
$redirect = 'edit.php?post_type=page'; //Pages
$defaultURL = get_option( 'siteurl' ) . '/wp-admin/' . $redirect;
//Add/remove cookies/redirects
if ( isset( $_GET['wp-advanced'] ) ) {
if ( $_GET['wp-advanced'] == 0 ) {
setcookie( 'wp-advanced', 0, time() - 86400 );
} else {
setcookie( 'wp-advanced', 1, time() + 86400 );
}
unset( $_GET['wp-advanced'] );
wp_redirect( $defaultURL );
}
//Remove these links from the menu no matter if advanced or not
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'link-manager.php' ); //Links
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'tools.php' ); //Tools
//Remove these links if user is editor
if ( !current_user_can( 'activate_plugins' ) ) {
remove_menu_page( 'profile.php' ); //Profile Page
}
//Redirect if user tries to go to Dashboard
if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI'] ) ) {
wp_redirect( $defaultURL );
}
//Set up the basic/advanced link properly
$getrequest = strpos( $redirect, '?' );
if ( $getrequest !== false ) {
$pageURL = $redirect."&wp-advanced=";
} else {
$pageURL = $redirect."?wp-advanced=";
}
if ( !isset( $_COOKIE["wp-advanced"] ) ) {
//If the user is in Basic (default) mode, strip the following pages:
remove_menu_page( 'update-core.php' ); //Updates
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'options-general.php' ); //Settings
remove_menu_page( 'users.php' ); //Users
remove_menu_page( 'themes.php' ); //Themes
//Since we removed themes menu, add the navigation menus button back as a main menu item
add_menu_page( 'Change Menus', 'Menus', 'add_users', 'nav-menus.php', '', 'div', 6 ); //Move Nav Menu
//Add the Advanced button at the bottom
$pageURL .= "1";
add_menu_page( 'Switch to Advanced Menus', 'Advanced Menu', 'add_users', $pageURL );
} else {
//Add the Basic button at the bottom
$pageURL .= "0";
add_menu_page( 'Switch to Basic Menus', 'Basic Menu', 'add_users', $pageURL );
}
}
add_action( 'admin_menu', 'edit_admin_menus', 999 );
//Add in custom Wordpress 3.8 icons for our Advanced/Basic Menu
function custom_menu_icons() {
echo '<style type="text/css">
.toplevel_page_nav-menus div.wp-menu-image:before{content: "\f333";}
</style>';
}
add_action( 'admin_head', 'custom_menu_icons' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment