Dallin Davis
Dallin Davis

Reputation: 571

I am doing remove_action before do_action but action is still fired?

I don't understand why this doesn't work. My understanding is that you must remove the action after it is added but before it is fired. That is what I'm doing here? Is there something here that I'm not understanding? Debugging wordpress really confuses me because you can't really step through it?

<?php
    /**
     * Functions hooked into storefront_header action
     *
     * @hooked storefront_header_container                 - 0
     * @hooked storefront_skip_links                       - 5
     * @hooked storefront_social_icons                     - 10
     * @hooked storefront_site_branding                    - 20
     * @hooked storefront_secondary_navigation             - 30
     * @hooked storefront_product_search                   - 40
     * @hooked storefront_header_container_close           - 41
     * @hooked storefront_primary_navigation_wrapper       - 42
     * @hooked storefront_primary_navigation               - 50
     * @hooked storefront_header_cart                      - 60
     * @hooked storefront_primary_navigation_wrapper_close - 68
     */
    remove_action('storefront_header', 'storefront_product_search', 40);
    do_action( 'storefront_header' );
    ?>

Upvotes: 2

Views: 565

Answers (1)

drnugent
drnugent

Reputation: 1545

Please see the contributed notes from the Wordpress documentation for remove_action:

If an action has been added from within a class, for example by a plugin, removing it will require accessing the class through a variable that holds the class instance.

...

To remove an action, the priority must match the priority with the function that was originally added.

Upvotes: 3

Related Questions