0

In the wordpress documentation for Global Variables, I did not find information about the $wp global variable.

I found a plugin which declares the global $wp variable as follows:

public function login_form(){
   global $wp;
   ...
}

But this variable is never used inside the declared function, so I wonder what is going on.

The entire function can be found here (links to the exact line in the GitHub WordPress Frontend Profile plugin)

  • It is a global instance of WP environment setup class and listed among the other global variables under the link you provided. – Ivan Shatsky Jul 16 at 14:57
  • 1
    Use of the main $wp object in plugins and themes is extremely rare, and is usually a bad sign of code quality. In the example you linked to, it isn't even used, the line could be deleted and it would make no difference – Tom J Nowell Jul 16 at 15:17
1

It contains the main instance of the WP class, which is primarily responsible for parsing the request URL and querying the appropriate posts, as well as sending headers and handling 404s. It can be used for things like getting the current request URL.

If it's declared in a function but not used, it's likely a mistake, or left over from a previous version of the function that did use it. You would need to ask the plugin developer why.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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