0

This question already has an answer here:

So one of the functions in my theme is:

public function job_manager_job_filters_distance() {
   //Show some HTML
}

And somewhere else in the document lies:

add_action( 'job_manager_job_filters_search_jobs_end', array( $this, 'job_manager_job_filters_distance' ), 0 );

I want to disable this function.

So naturally I went to my child theme's functions.php and added remove_action:

remove_action( 'job_manager_job_filters_search_jobs_end', 'job_manager_job_filters_distance' );

It didn't work. Then I tried different priorities for the removal:

remove_action( 'job_manager_job_filters_search_jobs_end', 'job_manager_job_filters_distance', 20 );

Still no go. Then I tried to wrap it in a function that triggers after theme load:

function remove_listify_junk() {
    remove_action( 'job_manager_job_filters_search_jobs_end', 'job_manager_job_filters_distance' );
}
add_action( 'after_setup_theme', 'remove_listify_junk', 999 );

And the function is still doing it's thing =[...

What am I missing here?

marked as duplicate by Howdy_McGee, kaiser Mar 14 '16 at 21:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You are trying to unhook a PHP function as opposed to a (class) instance method - see here:

array( $this, 'job_manager_job_filters_distance' )

...that's the actual callback registered to the hook. To unhook you need the same (a reference to the instance).

If you are trying to unhook from within the class, it's as easy as using the above. Otherwise you need a reference to the instance - look for something like the following in your code:

$my_class = new Name_Of_Class;

...then you'd run:

remove_action( 'job_manager_job_filters_search_jobs_end', array( $my_class, 'job_manager_job_filters_distance' ) , 0 );
  • Hi, thanks for the clarification. I get it now. As for your suggestion, the class is not declared within a variable, so thats a bummer. I tried doing: $myvar = new Listify_WP_Job_Manager_Map; class Listify_WP_Job_Manager_Map extends listify_Integration {...} and then on functions.php remove_action( 'job_manager_job_filters_search_jobs_end', array( $myvar, 'job_manager_job_filters_distance' ) , 0 ); But still it's not working. Maybe because the variable is inaccessible? Anyway, thanks. – Django Feb 25 '16 at 16:14
  • Damn, I thought that might be the case. Trouble is, running another $x = new Y will not point to the original instance (it's a new one). When you say this class is in your theme, is it in functions.php? If not where is it defined (loosely describe your theme architecture) – TheDeadMedic Feb 25 '16 at 16:17
  • The architecture is quite complex. Listify integrates with a bunch of plugins via built-in integration files in the theme's folder -- in addition to the actual plugin files in wp-content\plugins. The file I was referring to is located in wp-content\themes\listify\inc\integrations\wp-job-manager\map\class-wp-job-manager-map-template.php. I'm sure it's very hard/nearly impossible to figure it out without access to the actual files... And maybe I can explain myself better, but I am not that familiar with OOP in PHP... So anyway I appriciate your effort =] – Django Feb 25 '16 at 19:58
  • Well since the file is in your theme, you could just comment out the add_action line - otherwise try this technique for "finding" & un-hooking anonymous instances – TheDeadMedic Feb 25 '16 at 21:17

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