Support » Plugin: Dynamic Widgets » Referencing REMOTE_ADDR directly messes command line wp-cron.php

  • Running wp-cron.php through shell with php -f /PATH/TO/WP/wp-cron.php as instructed for example in resulted in a number of error messages starting with these by Dynamic Widgets:

    PHP Notice:  Undefined index: REMOTE_ADDR in /PATH/TO/WP/wp-content/plugins/dynamic-widgets/classes/dynwid_class.php on line 615
    Notice: Undefined index: REMOTE_ADDR in /PATH/TO/WP/wp-content/plugins/dynamic-widgets/classes/dynwid_class.php on line 615

    The rest of the messages were similarly caused by Dynamic Widgets having sent the headers already. It’s likely related to the server having PHP notices enabled and a reference to undefined REMOTE_ADDR thus causing the output to start.

    Also, the check with strstr() when returning the IP currently limits the support to only IPv4 addresses. The whole check seems a bit odd but perhaps there’s a reason for it I haven’t thought of. In any case it’s easy to expand it to support IPv6 as well.

    Both fixes can be applied by changing in classes/dynwid_class.php lines 615-618 from

    $ip = $_SERVER['REMOTE_ADDR'];
    			$this->message( 'Raw IP: ' . $ip );
    			return ( strstr($ip, '.') !== FALSE ) ? $ip : NULL;


    if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
    				$ip = $_SERVER['REMOTE_ADDR'];
    			} else {
    				$ip = NULL;
    			$this->message( 'Raw IP: ' . $ip );
    			return ( strstr($ip, '.') !== FALSE || strstr($ip, ':') !== FALSE ) ? $ip : NULL;

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Qurl


    The dynWid::getIP() method is just a very simple helper to retrieve the IPv4 address. Yes, it’s correct, only IPv4 is supported. The real deal for IP checking is done in method dynWid::IPinRange()

    I’ll add a test to see if $_SERVER[‘REMOTE_ADDR’] is available. That will solve the issue.

    Great, thanks!

    Hi, wanted to ask how is it going with this?

    Bumped into this issue again while having PHP notices turned on for plugin development. As a result cron started spewing unexpected emails with the PHP notices from cron as above. Checked also the development snapshot at and didn’t notice any changes in function getIP(). Thanks for looking into this.

    Plugin Author Qurl


    Thanks for the reminder. It’s on the wishlist to have it changed. It will be incorporated when I release a new version. Hopefully I have some time soon to do that.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Referencing REMOTE_ADDR directly messes command line wp-cron.php’ is closed to new replies.