Skip to content

Instantly share code, notes, and snippets.

@planetahuevo
Forked from fernandiez/functions.php
Created November 27, 2017 14:00
Show Gist options
  • Save planetahuevo/5fe080e3d9586dde98193cd414fdcff7 to your computer and use it in GitHub Desktop.
Save planetahuevo/5fe080e3d9586dde98193cd414fdcff7 to your computer and use it in GitHub Desktop.
Create menu section under Tools in WordPress admin dashboard and Editor role redirect
<?php
// Create menu section under Tools in WordPress admin
add_action( 'admin_menu', 'docs_admin_menu' );
// New section under Tools
function docs_admin_menu() {
add_management_page( 'Docs', 'Docs', 'manage_categories', 'docs', 'content_docs_admin_menu' );
}
// Contents for the new section
function content_docs_admin_menu() {
echo '<div class="wrap">';
echo '<h1>Docs Section</h1>';
echo '<h2>Lorem ipsum dolor sit amet</h2>';
echo '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec cursus magna.</p>';
echo '<h2>Ut laoreet hendrerit dui</h2>';
echo '<p>Sed nec ipsum scelerisque, pellentesque urna at, fermentum nisi.</p>';
echo '<h3>Morbi vehicula quam quis lorem ultrices viverra</h3>';
echo '<p>Integer massa ipsum, consectetur eu luctus non, venenatis et est.</p>';
echo '</div>';
}
/**
* Redirect Editor role to new section
* @author Mauricio Gelves <[email protected]>
*/
function mg_dashboard_redirect(){
// Get the current user
$user = wp_get_current_user();
// Asking for Editor role
if( in_array( 'editor', $user->roles ) ):
// If Editor role exists then redirect
wp_redirect(admin_url('tools.php?page=docs'));
exit;
endif;
}
add_action('load-index.php', 'mg_dashboard_redirect');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment