WordPress.org

Forums

Password Protected
[resolved] Can one auto-authorize based on visited IP? (4 posts)

  1. Taylor Baybutt
    Member
    Posted 1 year ago #

    We are building a site for our office. We want to have one password for all but also want to auto login people who are on-site by recognizing the IP.

    Similar to how http://wordpress.org/plugins/restricted-site-access/ functions.

    https://wordpress.org/plugins/password-protected/

  2. Ben Huson
    Member
    Plugin Author

    Posted 1 year ago #

    This plugin doesn't do it out of the box.
    However you can use a filter to do this.

    Something along the lines of:

    function password_protected_check_ip( $bool ) {
    	// Check the IP address here and return 0 (ie disabled) if you want to allow the IP address
    	return $bool;
    }
    add_filter( 'pre_option_password_protected_status', 'password_protected_check_ip' );
  3. Taylor Baybutt
    Member
    Posted 1 year ago #

    Awesome!! Thanks very much Ben. Will try to implement now.

  4. Taylor Baybutt
    Member
    Posted 1 year ago #

    AND, it works!

    In case anyone comes across this looking for the solution, it is as simple as this;

    function password_protected_check_ip( $bool ) {
    	// Check the IP address here and return 0 (ie disabled) if you want to allow the IP address
    	if($_SERVER['REMOTE_ADDR'] == "160.79.66.166") {
    	$bool = 0;
    	}
    	return $bool;
    }
    add_filter( 'pre_option_password_protected_status', 'password_protected_check_ip' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic