php 用于在任何操作或页面加载之前执行的 WordPress 挂钩
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15948162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WordPress hooks for executing right before any action or page loading
提问by Factory Girl
I'm quite new to WP. Task is to develop a plugin for oauth authentication on one of not popular openID providers. I did the same for CodeIgniter project, but WP is a CMS and is little bit complex for me to understand. In Codeigniter i check authorisation before each action. In WP i need a hook which uses for it... before each page printing, or maybe.. it would be right to say before each action in terms of frameworks. What is this hook's name?
我对 WP 很陌生。任务是在一个不受欢迎的 openID 提供程序上开发一个用于 oauth 身份验证的插件。我为 CodeIgniter 项目做了同样的事情,但 WP 是一个 CMS,我理解起来有点复杂。在 Codeigniter 中,我会在每次操作前检查授权。在 WP 中,我需要一个用于它的钩子......在每页打印之前,或者......在框架方面的每个操作之前说是正确的。这个钩子叫什么名字?
采纳答案by Xavjer
A list of all available hooks can be found here: https://codex.wordpress.org/Plugin_API/Action_Reference
可以在此处找到所有可用挂钩的列表:https: //codex.wordpress.org/Plugin_API/Action_Reference
Information about Hooks: https://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
关于钩子的信息:https: //codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
Other hooks must be suggested and will be added in a future release if is a good suggestion. Or you'd have to edit the core files ;)
必须建议其他钩子,如果是一个好的建议,将在未来的版本中添加。或者你必须编辑核心文件;)
回答by Domenico Citrangulo
You can use 'init' hook. It will be performed before element or html code. It`s also useful to manage POST and GET variables. The syntax is something like this:
您可以使用 'init' 钩子。它将在元素或 html 代码之前执行。管理 POST 和 GET 变量也很有用。语法是这样的:
function yourfunction() {
dosomething();
}
add_action('init', yourfunction);
回答by Marc van Nieuwenhuijzen
Last hook before loading the template is template_redirect
加载模板前的最后一个钩子是 template_redirect
You can use it like this:
你可以这样使用它:
function my_function(){
// your code goes here
}
add_action( "template_redirect", "my_function" );
回答by Factory Girl
You mean a hook when all wordpress function will available but before any output including headers sent?
您的意思是在所有 wordpress 功能都可用但在任何输出(包括发送的标头)之前使用钩子?
Well hook your function on init
. That will call when visiting site. If you want this hook only for admin area then it is admin_init
.
以及挂钩您的功能init
。这将在访问站点时调用。如果您只希望此挂钩用于管理区域,那么它是admin_init
.