• Resolved crodrigl

    (@crodrigl)


    Hi,
    I’m having some trouble granting access to logged in users to a site restricted by IP.

    I’m using WP 5.3.2 multisite setup and Restricted Site Access 7.2.0.

    Initially one of the sites were restricted by IP, and restricted users are redirected to another URL. That’s working fine.

    Now a set of network users need to access the site even from non-whitelisted IPs; since they are network users but may not be site users, I implemented the restricted_site_access_user_can_access filter shown in the FAQ (in a tiny mu-plugin), but it’s not working because the user ID when the filter is executed is always 0! (and yes, the user I’m testing with is already logged in beforehand).

    I have then tried the same but with an equivalent restricted_site_access_is_restricted filter; didn’t work either, but also, when logged in as super-admin, plugin settings are not shown correctly (none of the Site Visibility radio buttons is selected, so no other plugin options are shown). So finally I removed this filter.

    Then tried to change the Handle restricted visitors action to Send them to login page, but… they’re still redirected to the same URL I had setup earlier (I have also tried deleting the redirection URL before changing the action, but I’m getting always the same result).

    I’m getting out of ideas, except, maybe, disable the plugin and just require all users to login, wherever they come from.

    Regards,
    Carlos

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter crodrigl

    (@crodrigl)

    Well, half-solved…
    network users are now allowed to access (the login page is displayed); the problem seemed to be an old plugin interfering (More Privacy Options).

    But the strange behaviour of restricted_site_access_is_restricted filter is still present (although I don’t need it at this time).

    Hi @crodrigl, how did you use restricted_site_access_is_restricted filter, can you give me an example. I’m trying to understand the problem with it but I don’t think I get your idea.

    I can’t reproduce the issue either:

    when logged in as super-admin, plugin settings are not shown correctly (none of the Site Visibility radio buttons is selected, so no other plugin options are shown)

    Thread Starter crodrigl

    (@crodrigl)

    Hi @dinhtungdu, this is a screenshot of the plugin settings as they are right now:

    View post on imgur.com

    But as soon as I put this code fragment (in a mu-plugin):

    function neb_rsa_user_restricted ($is_restricted, $wp)
    {
    $log = realpath (dirname (__FILE__)).'/rsa_log.txt';
    $user = wp_get_current_user ();

    if (!did_action ('init')) {
    $txt = "Didn't init";
    } else if ($user->exists ()) {
    $txt = "Access ok user ".$user->user_login;
    $is_restricted = false;
    } else {
    $txt = "No access.";
    }
    file_put_contents ($log, "$txt (user ID = ".$user->ID.")\n", FILE_APPEND | LOCK_EX);

    return $is_restricted;
    }
    add_filter( 'restricted_site_access_is_restricted', 'neb_rsa_user_restricted', 10, 2 );

    Then, settings page is displayed this way:

    View post on imgur.com

    Hi @crodrigl, for the current code base, you need to exclude admin screens in your filter callback to avoid the strange behavior of the setting page. Put this on top of your callback:

    
    	if ( is_admin() ) {
    		return $is_restricted;
    	}
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem allowing logged in users’ is closed to new replies.