问题
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?
回答1:
A list of all available hooks can be found here: https://codex.wordpress.org/Plugin_API/Action_Reference
Information about Hooks: 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 ;)
回答2:
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:
function yourfunction() {
dosomething();
}
add_action('init', yourfunction);
回答3:
Last hook before loading the template is template_redirect
You can use it like this:
function my_function(){
// your code goes here
}
add_action( "template_redirect", "my_function" );
回答4:
You mean a hook when all wordpress function will available but before any output including headers sent?
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
.
来源:https://stackoverflow.com/questions/15948162/wordpress-hooks-for-executing-right-before-any-action-or-page-loading