Removing action added from constructor

If that class works as a singleton and has a getInstance() method (or similar) to retrieve the instance, you can remove the action pretty much the same way it was added:

remove_action('wp_travel_engine_enquiry_form', array( $instance, 'wpte_enquiry_form' ));

Edit: I’ve looked into this some more, and you find the necessary information by looking into $wp_filters (global variable, so use global $wp_filters; before working with it in a function).

add_action("init", function() {
    global $wp_filter;
    foreach($wp_filter["wp_travel_engine_enquiry_form"][10] as $id => $filter) {
    if(is_array($filter["function"]) && && count($filter["function"]) == 2 &&
        get_class($filter["function"][0]) == "WP_Travel_Engine_Enquiry_Form_Shortcodes" &&
        $filter["function"][1] == "wpte_enquiry_form") {
            remove_action("wp_travel_engine_enquiry_form", $id);
        }
    }
}, 99);

This code is looking at the filters/actions (they are the same thing, but filters are generally expected to return something; internally, add_action is an alias for add_filter) for the wp_travel_engine_enquiry_form hook. 10 is the default priority, but you could easily iterate of the other priorities as well.

It then looks at each individual filter whether it is a callable with an object and a method, and whether that object is of the right type and the right method we want to remove. As the ID is known then, remove_action is used to manipulate $wp_filter.

It’s not the cleanest of ways, but drastic times call for drastic measures.

Leave a Comment