How to fix the message “Undefined variable…” in WordPress

Solution:

that is not ERROR , this is just Notice messages, in general you can get various feedback about your scripts by PHP as mentions bellow :

  • E_ERROR
  • E_WARNING
  • E_PARSE
  • E_NOTICE
  • E_CORE_ERROR
  • E_CORE_WARNING
  • E_COMPILE_ERROR
  • E_COMPILE_WARNING
  • E_USER_ERROR
  • E_USER_WARNING
  • E_USER_NOTICE
  • E_STRICT
  • E_RECOVERABLE_ERROR
  • E_DEPRECATED
  • E_USER_DEPRECATED
  • E_ALL

this message is an E_NOTICE message that says:

A run-time notice indicating that the script encountered something that could possibly be an error, although the situation could also occur when running a script normally.

so the messages don’t report very serious problems that need emergency action. anyway, This error means that within your code, there is a variable or constant which is not set. But you may be trying to use that variable. The error can be avoided by using the isset() function or by setting a default value for it (if you know what property makes the notices triggered exactly).
if you don’t know, you can disable notice messages by PHP (keep that in mind: its better to disable error logs and same them in the log file when you are in production) :

for disableing all error messages :

error_reporting(0);

and for customizing them you can :

error_reporting(E_ALL & ~E_NOTICE);

with the above function, you will get all error levels except the notice ones.

if you are curious about what event can causes this problem Suddenly I can say that this may have a variety of reasons:

  • changing PHP version by you or host providers
  • adding new features or plugin
  • changing error level by other scripts
  • changing in host config and …