Are you trying to modify the functionality of a 3rd party plugin without actually editing the code of their plugin (which would result in losing your customization upon the next update)?  Having trouble with it because that plugin is object oriented or class-based?

I have run into this situation multiple times, and finally found a really good fix for it.

In this post, I’ll show you how to remove an action or filter hook from another plugin even though that plugin is class-based.

Basic Removing of Actions and Filters

You probably already know that you can remove someone’s add_action()  using a remove_action()  and you can remove someone’s add_filter()  using remove_filter() .

So, in normal circumstances, it’s very simple.  In someone’s plugin, they have something like…

… and you just remove them using…

Class-based Plugins are a bit more Complicated

A plugin that uses classes looks something like this…

Notice that add_action doesn’t just have a simple string of the function callback, but instead it has an array with $this and then that function callback string.  This allow plugin developers to use simple function names without the worry of conflicting with other plugins because they are limited to the scope of that class.

So, how do you remove that?

How to Remove a Hook from Within the Class-based Plugin

If you can hook into that plugin, then you should be able to use this method to gain access to the class object instance in order to remove the hook.

How to Remove a Hook from Outside the Class-based Plugin

If you are not able to hook into the class-based plugin, then try to use the class name as a string in the first part of the callback array, like this…

If None of Those Methods Work, Use These Functions

Sometimes, it just won’t work.  But, here’s a couple nice helper functions that work great.

Credit to tripflex.

With these functions available in your code, you can use them like this…

Questions?  Help?

Hopefully, this post solved your problem.  If so, hit me up in the comments below.

Run into any issues?  Let me know in the comments, and I’d love to help.

Leave a Reply

avatar
  Subscribe  
Notify of