Created
May 3, 2023 10:47
-
-
Save Glinkfr/c48aa3f91135cf22df3a5053466548ba to your computer and use it in GitHub Desktop.
Function.php Snippets to Modify admin area Administrator rights and appearance except for a specific Administrator username (CHANGE_USERNAME)
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 | |
/** | |
* Modify admin rights and appearance except for a specific administrator username (CHANGE_USERNAME) | |
*/ | |
$current_user = wp_get_current_user(); | |
//Checking if the current user has the 'administrator' role and their username is not 'CHANGE_USERNAME' | |
if ( | |
in_array("administrator", $current_user->roles) && | |
$current_user->user_login !== "CHANGE_USERNAME" | |
) { | |
//Remove the right to modify files including php files | |
define('DISALLOW_FILE_EDIT', true); | |
//Remove WPFC Toolbar Button | |
define('WPFC_HIDE_TOOLBAR', true); | |
//Remove menus and submenus in admin area | |
function remove_menu_items(){ | |
//Remove submenu site health | |
remove_submenu_page("tools.php", "site-health.php"); | |
//Remove submenu theme editor | |
remove_submenu_page("themes.php", "theme-editor.php"); | |
//Remove all menu plugins | |
remove_menu_page("plugins.php"); | |
//Remove all menu Divi Theme | |
remove_menu_page("et_divi_options"); | |
//Remove all menu BWS Sitemap Plugin | |
remove_menu_page('google-sitemap-plugin.php'); | |
//Remove all menu WPFC | |
remove_menu_page("wpfastestcacheoptions"); | |
//Remove all menu WPCF7 | |
remove_menu_page( 'wpcf7' ); | |
//Remove all menu post | |
remove_menu_page( 'edit.php' ); | |
}; | |
add_action("admin_menu", "remove_menu_items", 999); | |
//Remove site health and quick press metaboxes | |
function clean_wp_dashboard_setup(){ | |
remove_meta_box("dashboard_site_health", "dashboard", "normal"); | |
remove_meta_box("health_check_status", "dashboard", "normal"); | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); | |
}; | |
add_action("wp_dashboard_setup", "clean_wp_dashboard_setup"); | |
//Remove notifications from the admin area | |
function hide_admin_notices_except_specific_admin(){ | |
//Removing all actions of 'admin_notices' | |
remove_all_actions("admin_notices"); | |
} | |
add_action("admin_init", "hide_admin_notices_except_specific_admin"); | |
//Remove +New post and Wordpress Logo in top Admin Menu Bar | |
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) { | |
$wp_admin_bar->remove_node( 'new-post' ); | |
$wp_admin_bar->remove_node( 'wp-logo' ); | |
}, 999 ); | |
//Modify Text footer admin area | |
function custom_admin_footer_text() { | |
return '<span id="footer-thankyou">Merci de choisir <a href="https://www.glink.fr">Glink</a> pour votre site internet</span>'; | |
} | |
add_filter( 'admin_footer_text', 'custom_admin_footer_text' ); | |
//Modify number version admin area | |
function custom_admin_footer_version() { | |
return 'Version 2.0.3'; | |
} | |
add_filter( 'update_footer', 'custom_admin_footer_version', 11 ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment