WordPress widgets: Get rid of red on $before_widget

Good morning,

I'm using PS-138.379 and loving it. I'm not a programmer but learning PHP.  Currently $before_widget as well as $after_widget are red with the notice "undefined variable." In most cases, an isset or = '' prior to this line would fix PHP code but is this necessary for a WordPress widget?

Is there a way to get rid of the red to tell PhpStorm that the two variables are fine?

Thank you.

1 comment

Hi there,

Try this:

  • create brand new empty .php file anywhere in your project. This file will be used by IDE only so no need to deploy it anywhere etc (therefore it makes sense to place it somewhere in separate folder)
  • declare those variables there, e.g. $before_widget = null; (or whatever). Or even better -- /** @var ProperType $before_widget */ (where "ProperType" is correct class/type of that variable -- sorry, not a serious WordPress user myself so do not know all the details)
0

Please sign in to leave a comment.