I've been using the code below for a while with no trouble. I redirect back to the main page if user is not an admin. I just installed SSL and now does not work anymore. I know it has something to do with the code checking for SSL but I'm not sure how to do that. Any help is appreciated.
function redirect_admin_login()
{
global $wpdb;
global $current_user;
$visitor = $current_user->ID;
$login_page = home_url('');
$page_viewed = basename($_SERVER['REQUEST_URI']);
if ($page_viewed == "wp-admin" && $_SERVER['REQUEST_METHOD'] == 'GET' && $visitor != '1')
{
wp_redirect($login_page);
exit;
}
}
add_action('init', 'redirect_admin_login');
Give the following code a shot
function admin_redirect()
{
if (!current_user_can('administrator') && (!defined('DOING_AJAX') || !DOING_AJAX ))
{
wp_safe_redirect(get_home_url());
exit();
}
}
add_action('admin_init', 'admin_redirect', 1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.