1

I am using a plugin to allow users access to specific posts, but for restricted users, it shows:

You do not have sufficient permissions to access this page

How can I redirect restricted users to a specified page when it shows this?

1 Answer 1

1

This is not the direct answer to your problem. I personally believe that even if it possible it might not be wise to do it the way you want to do it. If you know a little programming then you can use the following one page plugin to achieve what you want.

<?php
/**
 * Plugin Name: Limit User Access To Pages
 */
defined('ABSPATH') or die("No script kiddies please!");
function RestrictPageAccessToUsers()
{
    /**
     * Global Intializations
     */
    global $current_user;
    get_currentuserinfo();
    global $post;

    /**
     * @var array $usersToRedirect Contains user IDs that 
     * should be restricted to enter $pageToRestrict
     */
    $usersToRedirect = array(2, 3);

    /**
     * @var array $pagesToRestrict Contains post (page) IDs 
     * that should be restricted for $usersToRedirect
     */
    $pagesToRestrict = array(14);

    /**
     * @var string $redirectUrl Contains link where the user 
     * should be redirected if it is not allowed to access 
     * the page.
     */
    $redirectUrl = home_url();

    if (in_array($current_user->ID, $usersToRedirect) === true && in_array($post->ID, $pagesToRestrict) === true) {
        wp_redirect( $redirectUrl );
        exit();
    }

}
add_action( 'template_redirect', 'RestrictPageAccessToUsers' );

There are three things that you need to configure in this plugin. These are:-

$usersToRedirect
$pagesToRestrict
$redirectUrl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.