Get list of available wordpress actions

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?

Read More

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.

🙂

Related posts

Leave a Reply

3 comments

  1. 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.

  2. 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.

  3. 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.