Deny wp-admin for non administrator users

Moeilijkheidsniveau:

This code will redirect users without "user delete permissions" to the home url.

add_action('admin_init','mp_admin_init');
// Deny wp-admin for loggedin non administrator users
function mp_admin_init()
{
require_once(ABSPATH . WPINC . '/pluggable.php');
$current_user = wp_get_current_user();
$current_user_id = ! empty($current_user) ? $current_user->id : 0;
$current_user = new WP_User($current_user_id);
if(!$current_user->has_cap('delete_users'))
{
wp_redirect(get_option('home'),302);
die();
}
}


Suggestie? Vraag of opmerking? Laat het ons weten!

Plaats hier je bericht

Reacties (4)

  1. Ramon Fincken says:

    * Changelog: changed 301 redirect to 302 redirect to fix browser caching issue when using multiple accounts ( one having adminstrator rights )

  2. Nick says:

    Hallo!

    Wat betreft; This code will redirect users without "user delete permissions" to the home url.

    Ik zou graag willen weten waar ik deze code toe moet voegen?

    Alvast bedankt. Met vriendelijke groet,
    Nick.

    ( wanneer ik de reply functie op jullie website 'gebruik' krijg ik dit: Fatal error: Class 'c_ws_plugin__qcache_utils_urls' not found in /home/mnpress/domains/mijnpress.nl/public_html/wp-content/plugins/quick-cache-comment-garbagecollector/qc-comment-gc.php on line 33 )