• Resolved chazzo

    (@chazzo)


    Can someone help me create a simple WP action to test whether the current visitor is restricted, so that I can run some code based on the result?

    I see many people here have asked for a filter to give restricted visitors access to specific pages. The stock reply (see below) is working fine for me.

    So I thought that in my functions.php I could simply change add_filter to add_action, and check the value of $is_restricted. But that doesn’t work ($is_restricted is always true). What stupid error am I making? Is $is_restricted out of scope, and if so, is there a way round this?

    Many thanks for any suggestions.

    add_filter( 'restricted_site_access_is_restricted', 'my_allow_access', 10, 2 );
    
    function my_allow_access( $is_restricted, $wp ) {
    	if( 'about' === $wp->request ) {
    		return false;
    	}
    	return $is_restricted;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @chazzo, can you share with us why do you need to check where the current visitor is restricted? I think the is_user_logged_in() function may fit your needs, but I’m not sure what exactly your problem is?

    Thread Starter chazzo

    (@chazzo)

    @dinhtungdu Many thanks for listening. This is an extremely useful plugin and I can see you spend a good deal of time supporting it. It’s appreciated!

    So … I have a restricted site that users access either from approved IP addresses or by logging in. For IP control, RSA is working well. For the logged-in users, I want to assign them various profiles and use those profiles to control which pages they can see. For that, I have the Simple Restrict Content plugin installed.

    The problem, of course, is that the content restriction plugin blocks anyone who is not logged in, including anyone visiting from an IP address approved by RSA. So I thought I’d write a function to detect when that happens, and log these visitors in automatically with a generic profile. I’ve tested wp_signon() for the auto-login and it seems to work.

    As I see it, I can’t use is_user_logged_in() because that will simply log everyone in automatically, which is not what we want. Instead, I really do want to detect visitors who’ve passed RSA’s IP check.

    I am not a developer and I know this is all a big fudge. Nevertheless, suggestions welcome.

    • This reply was modified 4 years, 1 month ago by chazzo.

    So I thought I’d write a function to detect when that happens, and log these visitors in automatically with a generic profile. I’ve tested wp_signon() for the auto-login and it seems to work.

    @chazzo you can hook to restrict_site_access_ip_match action. This action fires when an IP address match occurs, so you can use it to log visitors (who passed RSA checks) in.

    Thread Starter chazzo

    (@chazzo)

    Excellent, thank you. I’ll try that.

    Thread Starter chazzo

    (@chazzo)

    Working perfectly. You’re a star. This is a massive kludge, but for anyone who could use it:

    
    function my_auto_login() {
        if ( ! is_user_logged_in() ) {
            $creds = array(
                'user_login'    => 'Subscriber',
                'user_password' => 'xxxxxxxxxxxxxxxxx',
                'remember'      => false
            );
            $user = wp_signon( $creds, is_ssl() );
            if ( is_wp_error( $user ) ) {
                echo $user->get_error_message();
            }
        }
    }
    
    add_action( 'restrict_site_access_ip_match', 'my_auto_login' );
    
    • This reply was modified 4 years, 1 month ago by chazzo.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Create an Action to check restriction status’ is closed to new replies.