Support » Plugin: MailChimp List Subscribe Form » Undefined variable: query_params on form submit

  • Resolved kellybleck

    (@kellybleck)


    In addition to the error talked about in previous threads, I’m also getting
    Notice: Undefined variable: query_params in /home/alexiusllc/public_html/wp-content/plugins/mailchimp/lib/mailchimp/mailchimp.php on line 34

    I just set $query_params = ''; on Line 1, but am not sure if that’s the correct solution.

    Help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author mcsupport

    (@mcsupport)

    Hey there @kellybleck,

    Thanks for getting in touch and providing those specifics. Just to make sure we’re digging into this thoroughly, would you mind providing a few specific details so we’re fully up to speed on the situation?

    – Would you be able to provide the URL of where this form is currently accessible for testing?
    – What theme is being used on the site?
    – What other plugins are currently active on the site?
    – What version of PHP is running on the site?
    – In addition to this error’s text, would it be possible to share a screenshot of how this error appears within the context of the site?

    Thanks so much in advance for these details. We’ll keep an eye out for your response.

    Best,
    Malachite

    Hey @mcsupport, did you look at the code Kelly was talking about? There’s an obvious PHP error that anyone who uses WP_DEBUG would understand immediately.

    You don’t have to ask for more information, just look at the code, then fix the problem on your end! She even provided the solution for you!

    Here’s the code ([…] stands in for other stuff that wasn’t important to the problem):

    public function get($endpoint, $count = 10, $fields = array())
        {
            $url = $this->api_url . $endpoint;
    			
            if ($count) {
                $query_params = 'count=' . $count . '&';
            }
    [...]
            $query_params .= $field . '=' . $value . '&';

    Why do we get the error?:

    Notice: Undefined variable: query_params in …/plugins/mailchimp/lib/mailchimp/mailchimp.php on line 34

    We get it because you never initialize the variable safely. The first use, with a bare “=” is inside an IF statement, so if there’s no $count value, then it doesn’t get run. Then when you subsequently add to $query_params with “.=” the error shows up, because “.=” means “add to this variable” and PHP gets made if the variable doesn’t exist.

    This should have been obvious from the bug report above. It’s a common mistake that’s easy to fix.

    This bug is directly related to the WP_DEBUG stuff I explained in detail in this thread:

    https://wordpress.org/support/topic/mailchimp_widgetphp-littered-with-php-undefined-index-notices/

    If you can find MC_Nate and have him take a look at this issue that would be great, it seems your goal of increasing testing quality isn’t going exactly to plan.

    Please fix this by adding a line with

    $query_params = '';

    Above the line with if ($count)

    • This reply was modified 8 months, 1 week ago by  Jer Clarke.
    Plugin Author mcsupport

    (@mcsupport)

    Hey @kellybleck and @jeremyclarke,

    We appreciate you guys chiming in here with those details. I apologize for the frustration here and I’m happy to let everyone know that a fix was pushed for this issue today. Please update your plugin version to 1.5.7 and let us know if you run into any issues after the update.

    Thanks again!

    Pearl

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Undefined variable: query_params on form submit’ is closed to new replies.