Site Health / Sitediagnose verbergen voor gebruikers zonder @gladior.com account
PHP Code
php
function hide_site_health_for_specific_users() {
// Definieer de string die in het emailadres moet voorkomen
$email_string = '@gladior.com'; // Pas dit aan naar de gewenste string
// Controleer of de gebruiker is ingelogd
if (!is_user_logged_in()) {
return;
}
// Haal de huidige gebruiker op
$current_user = wp_get_current_user();
$user_email = $current_user->user_email;
// Controleer of de string voorkomt in het emailadres
if (strpos($user_email, $email_string) === false) {
// Verwijder de Site Health menu items
remove_submenu_page('tools.php', 'site-health.php');
// Blokkeer directe toegang tot de pagina
add_action('current_screen', 'block_site_health_access');
}
}
/**
* Blokkeert directe toegang tot de Site Health pagina
*/
function block_site_health_access() {
$screen = get_current_screen();
if ($screen && $screen->id === 'site-health') {
// Redirect naar dashboard met foutmelding
wp_redirect(admin_url('index.php?site-health-blocked=1'));
exit;
}
}
function site_health_blocked_notice() {
if (isset($_GET['site-health-blocked'])) {
echo '<div class="notice notice-error is-dismissible">
<p><strong>Toegang geweigerd:</strong> U heeft geen toegang tot de Site Health pagina.</p>
</div>';
}
}
// Hook de functies aan de juiste WordPress acties
add_action('admin_menu', 'hide_site_health_for_specific_users', 999);
add_action('admin_notices', 'site_health_blocked_notice');
function hide_site_health_by_capability() {
// Alleen administrators kunnen Site Health zien
if (!current_user_can('manage_options')) {
remove_submenu_page('tools.php', 'site-health.php');
add_action('current_screen', 'block_site_health_access');
}
}
add_action('admin_menu', 'hide_site_health_by_capability', 999);