Created
January 11, 2018 11:21
-
-
Save fernandiez/76e797bb900de6d8bb2ead596d803085 to your computer and use it in GitHub Desktop.
Customizing WordPress Admin Panel Plugin
This file contains 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 | |
/** | |
* | |
* Customizing WordPress Admin Panel Plugin | |
* | |
* @link https://www.fernan.com.es/ | |
* @since 1.0.0 | |
* | |
* Plugin Name: Customizing WordPress Admin Panel Plugin | |
* Plugin URI: https://www.betabeers.com/blog/ | |
* Description: Plugin para personalizar el panel de administración de WordPress | |
* Version: 1.0.0 | |
* Author: Fernan Díez | |
* Author URI: https://www.fernan.com.es/ | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Text Domain: customize-wp-admin-panel-plugin | |
* Domain Path: /languages | |
*/ | |
// Modificar el estilo de colores de panel | |
function set_default_admin_color($user_id) { | |
$args = array( | |
'ID' => $user_id, | |
'admin_color' => 'sunrise' | |
); | |
wp_update_user( $args ); | |
} | |
add_action('user_register', 'set_default_admin_color'); | |
// Añadir enlaces en la barra de herramientas | |
function custom_toolbar_link($wp_admin_bar) { | |
$args = array( | |
'id' => 'support', | |
'title' => 'Help Section', | |
'href' => 'https://www.google.com', | |
'meta' => array( | |
'class' => 'support', | |
'title' => 'Help Section' | |
) | |
); | |
$wp_admin_bar->add_node($args); | |
} | |
add_action('admin_bar_menu', 'custom_toolbar_link', 999); | |
// Modificar el pie de página del panel | |
function remove_footer_admin () { | |
echo 'Powered by <a href="http://www.wordpress.org" target="_blank">WordPress</a> | Built by <a href="https://acme.com/" target="_blank">Acme Inc</a>'; | |
} | |
add_filter('admin_footer_text', 'remove_footer_admin'); | |
// Eliminar enlaces a WordPress.org de la barra de herramientas | |
add_action( 'admin_bar_menu', 'remove_wp_logo', 999 ); | |
function remove_wp_logo( $wp_admin_bar ) { | |
$wp_admin_bar->remove_node( 'wp-logo' ); | |
} | |
// Eliminar enlaces de la barra de administración | |
function remove_admin_bar_links() { | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_menu('wp-logo'); // Remove the WordPress logo | |
$wp_admin_bar->remove_menu('about'); // Remove the about WordPress link | |
$wp_admin_bar->remove_menu('wporg'); // Remove the WordPress.org link | |
$wp_admin_bar->remove_menu('documentation'); // Remove the WordPress documentation link | |
$wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link | |
$wp_admin_bar->remove_menu('feedback'); // Remove the feedback link | |
$wp_admin_bar->remove_menu('site-name'); // Remove the site name menu | |
$wp_admin_bar->remove_menu('view-site'); // Remove the view site link | |
$wp_admin_bar->remove_menu('updates'); // Remove the updates link | |
$wp_admin_bar->remove_menu('comments'); // Remove the comments link | |
$wp_admin_bar->remove_menu('new-content'); // Remove the content link | |
$wp_admin_bar->remove_menu('my-account'); // Remove the user details tab | |
} | |
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' ); | |
// Eliminar enlaces de la barra de administración salvo para administradores | |
function remove_admin_bar_links() { | |
global $wp_admin_bar, $current_user; | |
if ($current_user->ID != 1) { | |
$wp_admin_bar->remove_menu('updates'); // Remove the updates link | |
$wp_admin_bar->remove_menu('comments'); // Remove the comments link | |
$wp_admin_bar->remove_menu('new-content'); // Remove the content link | |
} | |
} | |
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' ); | |
// Eliminar elementos del menú principal | |
function remove_menus(){ | |
remove_menu_page( 'index.php' ); //Dashboard | |
remove_menu_page( 'jetpack' ); //Jetpack* | |
remove_menu_page( 'edit.php' ); //Posts | |
remove_menu_page( 'upload.php' ); //Media | |
remove_menu_page( 'edit.php?post_type=page' ); //Pages | |
remove_menu_page( 'edit-comments.php' ); //Comments | |
remove_menu_page( 'themes.php' ); //Appearance | |
remove_menu_page( 'plugins.php' ); //Plugins | |
remove_menu_page( 'users.php' ); //Users | |
remove_menu_page( 'tools.php' ); //Tools | |
remove_menu_page( 'options-general.php' ); //Settings | |
} | |
add_action( 'admin_menu', 'remove_menus' ); | |
// Modificar el logotipo de acceso | |
function my_login_logo() { ?> | |
<style type="text/css"> | |
#login h1 a, .login h1 a { | |
background-image: url('<?php echo get_stylesheet_directory_uri();?>/acme.png') !important; | |
width: 320px !important; | |
height: 240px !important; | |
background-size: 320px 240px !important; | |
} | |
</style> | |
<?php } | |
add_action( 'login_enqueue_scripts', 'my_login_logo' ); | |
<pre> | |
// Reordenar los elementos comunes del menú de administración | |
function custom_menu_order($menu_ord) { | |
if (!$menu_ord) return true; | |
return array( | |
'index.php', // Dashboard | |
'upload.php', // Media | |
'plugins.php', // Plugins | |
'edit-comments.php', // Comments | |
'edit.php?post_type=page', // Pages | |
'edit.php', // Posts | |
); | |
} | |
add_filter('custom_menu_order', 'custom_menu_order'); | |
add_filter('menu_order', 'custom_menu_order'); | |
</pre> | |
// Eliminar widgets de contenido de la portada | |
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets'); | |
function my_custom_dashboard_widgets() { | |
global $wp_meta_boxes; | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); //remove at-a-glance | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); //remove WordPress-newsfeed | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); //remove quick-draft | |
} | |
// Añadir widgets de contenido en la portada del panel | |
add_action('wp_dashboard_setup', 'recopilatorio_dashboard_widgets'); | |
function recopilatorio_dashboard_widgets() { | |
global $wp_meta_boxes; | |
wp_add_dashboard_widget('recopilatorio_help_widget', 'Help Section Title', 'recopilatorio_dashboard_help'); | |
} | |
function recopilatorio_dashboard_help() { | |
echo '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum posuere ipsum at porttitor lobortis. </p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment