A powerful membership solution for WordPress

The Problem

Recently, I was working on a support thread where the user was attempting to override the default functionality of Easy Digital Downloads by using the remove_action() function. This was being done in a custom plugin. This function allows you to negate any add_action() created by another plugin, theme, or WordPress core. Their code, at a basic level, looked like this:

In short, they were trying to write a custom set of customer info fields on the checkout screen, by overriding the defaults using remove_action. This wasn’t working for them however…I’ll give you a second to think about why. Go ahead, get your thoughts in order.

The Explanation

The issue at hand, is plugin load order. WordPress loads the code for plugins in the following order:

  1. Must Use Plugins (or mu-plugins)
  2. Network Activated Plugins (if it’s a multisite install)
  3. Plugins in the ‘plugins_activated’ option in alphabetical order

What was basically happening, is this custom plugin was loading before Easy Digital Downloads, resulting in the remove_action() was being called before the add_action() that EDD was using.

The Solution

So how did we solve it? Pretty easily actually…

What this allowed us to do is wait until the last possible moment of the plugins_loaded hook using the ’99’ parameter for order, and then tell WordPress to remove the hooks run by EDD. Then we were free to add our own hooks to make a personalized checkout screen.

Any gotchas?

As with all software development, there’s probably a few edge cases where this won’t work. If the hooks and filters are determining anything before the end of plugins loaded, you might have an issue, but for most general use cases, this should do the trick.

Post Promoter Pro

Posted by Chris Klosowski

Hi, I'm Chris Klosowski. Currently I am a Lead Developer of Easy Digital Downloads, where we build the easiest way to sell digital products with WordPress.

I am also the person behind Post Promoter Pro, the most effective way to promote your WordPress Content.

3 Comments

  1. Man. Useful snippet. I’ve run into this many times. Saved!

    Reply

    1. Sweet, glad it helped someone out. Getting compatibility with other plugins can be tricky, but if we all play nice and think of the ‘what if’ scenarios, we can make it easier on each other as developers.

      Reply

      1. For sure. And I very much appreciate you using a drunk octopus as the featured image on this post 😛

        Reply

Leave a Reply to Chris Cancel reply

Your email address will not be published. Required fields are marked *