3

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.

:)

1
  • 1
    Ah, auto-hooking... What you are trying is somewhat beaten topic in community. Short version - there is no way to get it done that is both elegant and completely flexible. Myself I prefer to hook methods explicitly, using shorthand add_method() function if it's my own code.
    – Rarst
    Feb 12, 2012 at 22:12

3 Answers 3

5

I'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.

3

There is no way to get such list from one place, because hooks essentially don't exist until either:

  1. Hook is executed.
  2. 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.

1
  • Updated my original post.
    – Zack
    Feb 12, 2012 at 22:11
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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