WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Warning: Invalid argument supplied for foreach() in /.../ipn_res.php on line 28

Warning: Invalid argument supplied for foreach() in /.../ipn_cls.php on line 30

From line 28 is a foreach loop:

foreach ($paypal_ipn->paypal_post_vars as $key=>$value) {
    if (getType($key)=="string") {

From line 30 is also a foreach loop:

foreach($this->paypal_post_vars AS $key => $value) {
    if (@get_magic_quotes_gpc()) {
        $value = stripslashes($value);
    $values[] = "$key" . "=" . urlencode($value);

And I think the root cause of the errors is this:

//This is located before foreach loop in ipn_res.php

$paypal_info = $HTTP_POST_VARS;
$paypal_ipn = new paypal_ipn($paypal_info);

The constructor of class paypal_ipn is passed with a non-array var because nothing has been sent yet that would fill out $HTTP_POST_VARS. Wordpress runs the code which is not the case when not in it. How do I get away from this?

share|improve this question
up vote 1 down vote accepted

Contact plugin's developer and ask him to fix?.. But I guess that is probably not an option if plugin is broken badly and remains that way.

For a quick band-aid try this right after object is created, to handle case of constructor not setting up field properly:

if( !isset( $paypal_ipn->paypal_post_vars ) )
    $paypal_ipn->paypal_post_vars = array();
share|improve this answer
Actually I am the developer, a noob one. :-) – Joann Nov 27 '10 at 18:46
Ah. :) Then you probably need to handle the case when there is nothing to write into field. Either init field to empty array in constructor or do not run your loops if there is no data to process. – Rarst Nov 27 '10 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.