0

Ok So I am lost this code snippit is from a word-press plug in I downloaded. I emailed the creator but no response. The sad thing is it was just updated a week ago so not sure what they did to it. I had it working and suddenly now getting this error when i try and upload through it.

 // Add the known elements css.
    foreach ($this->elements_options as $key => $value) {
        if(strpos($key, 'important') || !$value)
            continue;

This is the line that wordpress is saying the error is on. To me it looks right But php is calling it invalid.

Any help would be appreciated

  • Possible duplicate of [Invalid argument supplied for foreach()](http://stackoverflow.com/questions/2630013/invalid-argument-supplied-for-foreach) – Johan Feb 13 '17 at 16:55
  • 1
    This error simply mean that the variable `$this->elements_options` is not an array or a `stdObject` so it cannot be iterate through using a foreach. You should place a `die(var_dump($this->elements_options));` before the foreach to check what is in the variable. Maybe post it here so we can help you a little bit more. – Nicolas Feb 13 '17 at 16:55
  • I actually got it fixed turns out it is a wordpress issue that will be fixed in the next version I had to download another plug in to counter act the core issues – Kirk Sturgulewski Feb 13 '17 at 17:11

1 Answers1

0

You are not using strpos() function correctly.

i.e, if(strpos($key, 'important') || !$value) // Incorrect way

strpos() function in this condition returns the numeric position (or value). But you are looking for boolean true/false. so you need to explicitly check.

Also, you might want to change your condition to something like :

if(strpos($key, 'important') !== false || !$value)  
ishwor kafley
  • 938
  • 14
  • 32