Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@maugelves 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

This comment has been minimized.

Copy link
Owner Author

@fernandiez fernandiez commented Nov 10, 2017

¡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