Skip to content

Instantly share code, notes, and snippets.

@fernandiez
Last active March 11, 2019 12:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fernandiez/f06efa92c629b2371f9ef7f7db6a80cb to your computer and use it in GitHub Desktop.
Save fernandiez/f06efa92c629b2371f9ef7f7db6a80cb 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 <mg@maugelves.com>
*/
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');
@maugelves
Copy link

maugelves commented Oct 30, 2017

Excelente idea Fernan!

Agrégale el <?php en la primera así te coge los estilos ;)
Por otra parte, cambia la capabilite manage_options (propia del administrador) por manage_categories (propia de un editor).
Con esos cambios funciona de maravilla :)

Un abrazo!

@fernandiez
Copy link
Author

¡Hey! No había visto el comentario. Correcciones añadidas, ¡Muchas gracias Mau!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment