admin管理员组文章数量:1122832
I don't think there is, but I was wondering whether anyone ran into this issue before.
Is there a function (or variable) call to get all registered WP Actions and all registered WP Filters?
My current way of doing so would be to have something like this:
static private $wp_actions = array(
'muplugins_loaded',
'registered_taxonomy',
'registered_post_type',
'plugins_loaded',
'setup_theme',
'load_textdomain',
'after_theme_setup',
'init',
'widgets_init',
'register_sidebar',
'wp_register_sidebar_widget',
'wp_default_scripts',
'wp_default_styles',
'admin_bar_init',
'add_admin_bar_menus',
'wp_loaded',
'parse_request',
'send_headers',
'parse_query',
'pre_get_posts',
'wp',
'template_redirect',
'get_header',
'wp_head',
'wp_enqueue_scripts',
'wp_print_styles',
'wp_print_scripts',
'loop_start',
'the_post',
'loop_end',
'get_sidebar',
'wp_footer',
'wp_print_footer_scripts',
'admin_bar_menu',
'shutdown'
);
Except that's undesirable because, what if...WP adds more actions, or deprecates some? I'd feel safer getting an already in-memory solution.
The above list was translated by hand from this link.
EDIT: I'm trying to write a somewhat decent plugin system using classes. Here's implementation I'm looking for:
abstract class AtlantisPlugin {
static private $atlantis_actions = array( );
static private $atlantis_filters = array( 'atlantis_plugin_init' );
//
static private $wp_actions = /* see above */;
static private $wp_filters = array();
protected $atlantis;
private $class;
public function __construct(Atlantis $atlantis) {
$this->class = strtolower(get_class($this));
$this->atlantis =& $atlantis;
$this->atlantis->registerPlugin($this->class, $this);
$actions = array_intersect(self::$wp_actions, get_class_methods($this->class));
foreach($actions as $action) {
add_action($action, array(&$this, $action), 2);
}
$filters = array_intersect(self::$wp_filters, get_class_methods($this->class));
foreach($filters as $filter) {
add_filter($filter, array(&$this, $filter), 2);
}
}
}
Thanks.
:)
I don't think there is, but I was wondering whether anyone ran into this issue before.
Is there a function (or variable) call to get all registered WP Actions and all registered WP Filters?
My current way of doing so would be to have something like this:
static private $wp_actions = array(
'muplugins_loaded',
'registered_taxonomy',
'registered_post_type',
'plugins_loaded',
'setup_theme',
'load_textdomain',
'after_theme_setup',
'init',
'widgets_init',
'register_sidebar',
'wp_register_sidebar_widget',
'wp_default_scripts',
'wp_default_styles',
'admin_bar_init',
'add_admin_bar_menus',
'wp_loaded',
'parse_request',
'send_headers',
'parse_query',
'pre_get_posts',
'wp',
'template_redirect',
'get_header',
'wp_head',
'wp_enqueue_scripts',
'wp_print_styles',
'wp_print_scripts',
'loop_start',
'the_post',
'loop_end',
'get_sidebar',
'wp_footer',
'wp_print_footer_scripts',
'admin_bar_menu',
'shutdown'
);
Except that's undesirable because, what if...WP adds more actions, or deprecates some? I'd feel safer getting an already in-memory solution.
The above list was translated by hand from this link.
EDIT: I'm trying to write a somewhat decent plugin system using classes. Here's implementation I'm looking for:
abstract class AtlantisPlugin {
static private $atlantis_actions = array( );
static private $atlantis_filters = array( 'atlantis_plugin_init' );
// http://codex.wordpress.org/Plugin_API/Action_Reference
static private $wp_actions = /* see above */;
static private $wp_filters = array();
protected $atlantis;
private $class;
public function __construct(Atlantis $atlantis) {
$this->class = strtolower(get_class($this));
$this->atlantis =& $atlantis;
$this->atlantis->registerPlugin($this->class, $this);
$actions = array_intersect(self::$wp_actions, get_class_methods($this->class));
foreach($actions as $action) {
add_action($action, array(&$this, $action), 2);
}
$filters = array_intersect(self::$wp_filters, get_class_methods($this->class));
foreach($filters as $filter) {
add_filter($filter, array(&$this, $filter), 2);
}
}
}
Thanks.
:)
Share Improve this question edited Feb 12, 2012 at 22:05 Zack asked Feb 12, 2012 at 20:48 ZackZack 1,5442 gold badges19 silver badges30 bronze badges 1 |4 Answers
Reset to default 5I'd just like to point out that that is, by no means, anywhere NEAR a complete list. According to adambrown.info, there are 595 actions and 970 filters in wordpress 3.3...and that's just by default, not including hooks added by your plugins.
You might be able to do something with global $wp_actions
or global $wp_filters
, depending on what you're trying to do, but those are dynamically generated and only contain the actions done for the page that was loaded (as best I can tell).
Short answer: probably not.
There is no way to get such list from one place, because hooks essentially don't exist until either:
- Hook is executed.
- Something is added to the hook.
Note that former doesn't require latter, just as latter doesn't guarantee former will occur.
While it's probably possible to scan source for all static hook names, there are quite a few dynamic hooks like:
do_action("{$old_status}_to_{$new_status}", $post);
which are not meaningful up to the moment they are executed for specific values of variables.
You'll have to provide more specific example of what you need this for to get better ideas on how to get what is possible for your needs.
you can use the global vars $wp_actions
or $wp_filters
or go about the Filter all
; an better alternative you use an exist solution; an example is the plugin Debug Objecs; list all Filter adn Action Hooks and help you to find the right hooks. Also it is possible to use the function from Mike, but the plugin has the same solution optional inside.
check this repository, all hook as json:
https://github.com/wp-hooks/wordpress-core-hooks
本文标签: plugin developmentGet list of available wordpress actions
版权声明:本文标题:plugin development - Get list of available wordpress actions 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309079a1933890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_method()
function if it's my own code. – Rarst Commented Feb 12, 2012 at 22:12