• Hello,

    I am using your plugin (v2.0) and I wanted to submit an improvement. I edited a few lines of code in your plugin’s password-protected.php file.

    I changed:

    function allow_ip_addresses( $bool ) {
    
    		$ip_addresses = $this->get_allowed_ip_addresses();
    
    		if ( in_array( $_SERVER['REMOTE_ADDR'], $ip_addresses ) ) {
    			$bool = false;
    		}
    
    		return $bool;
    
    	}

    to this:

    function allow_ip_addresses( $bool ) {
    
    		$ip_addresses = $this->get_allowed_ip_addresses();
    
    		foreach($ip_addresses as $ip){
    			if ( $_SERVER['REMOTE_ADDR'] === gethostbyname($ip) ) {
    				$bool = false; break;
    			}
    		}
    
    		return $bool;
    
    	}

    What this does, is it allows users to whitelist not only IPs but also other strings. For example, I am using No-IP for Dynamic DNS, in other words, my routers IP address may change, due to ISP, and I have a DynDNS set up so that xys.ddns.net will end up at my IP. So gethostbyname() will check if it’s a domain name or something that resolves an IP, and work if it is and returns an IP that matches users IP.

    https://ww.wp.xz.cn/plugins/password-protected/

Viewing 1 replies (of 1 total)
  • Hi, I added an issue to work on this functionality.

    Please view the issue on GitHub – I have added a version of the plugin for you to download and test that adds this functionality.

    Please let me know (via the GitHub issue) if that works for you or if you find any problems.

    Thanks

    Ben

Viewing 1 replies (of 1 total)

The topic ‘Copy and paste this code into your plugin please.’ is closed to new replies.