Last active
March 11, 2019 12:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
¡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
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) pormanage_categories
(propia de un editor).Con esos cambios funciona de maravilla :)
Un abrazo!