• Hello,

    I am using your plugin 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/

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