admin管理员组文章数量:1328378
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)
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)
Share Improve this question asked Jul 16, 2020 at 14:49 Álvaro FranzÁlvaro Franz 1,1001 gold badge9 silver badges31 bronze badges 2 |1 Answer
Reset to default 3It 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.
本文标签: What is the global wp object used for
版权声明:本文标题:What is the global $wp object used for? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742257613a2441917.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
WP
environment setup class and listed among the other global variables under the link you provided. – Ivan Shatsky Commented Jul 16, 2020 at 14:57$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 ♦ Commented Jul 16, 2020 at 15:17