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:

<?php
/**
 * Plugin Name: Some Custom Plugin
 * Plugin URI:  ...
 * Description: Another custom plugin
 * Author:      ...
 * Author URI:  ...
 * Version:     ...
 * Text Domain: ...
 */

remove_action( 'edd_purchase_form_after_user_info', 'edd_user_info_fields' );
remove_action( 'edd_register_fields_before', 'edd_user_info_fields' );

function new_edd_user_info_fields() {
 // Replace the checkout form user fields
}
add_action( 'edd_purchase_form_after_user_info', 'new_edd_user_info_fields' );
add_action( 'edd_register_fields_before', 'new_edd_user_info_fields' );

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…

add_action( 'plugins_loaded', 'ck_edd_remove_personal_info', 99 );
function ck_edd_remove_personal_info() {
	remove_action( 'edd_purchase_form_after_user_info', 'edd_user_info_fields' );
	remove_action( 'edd_register_fields_before', 'edd_user_info_fields' );
}

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.

Posted by Chris Klosowski

Chris Klosowski is the Director of Technology at Sandhills Development, LLC, creators of fine WordPress plugins, and ecommerce solutions.

16 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

  2. Hello there! Would you mind if I share your blog
    with my myspace group? There’s a lot of people that I think would really appreciate your content.
    Please let me know. Thanks

    Reply

  3. I read this piece of writing fully concerning the
    difference of latest and preceding technologies, it’s awesome article.

    Reply

  4. bu viagra online viagra price comparison – cialis viagra online

    Reply

  5. zithromax cost cheap azitromycin – zithromax 600 mg tablets

    Reply

  6. how much is ivermectin stromectol tablets – generic ivermectin

    Reply

  7. buy ed drugs ed meds online without doctor prescription – pet meds without vet prescription

    Reply

  8. lexapro prescription lexapro 15mg – buy generic lexapro online

    Reply

  9. Every weekend i used to pay a quick visit this site, because i want enjoyment, for the reason that this this website conations in fact nice funny information too.

    Reply

  10. ivermectin 200mg stromectol – ivermectin 500ml

    Reply

  11. Hey! I understand this is somewhat off-topic but I had to ask.
    Does building a well-established website such as yours take a massive amount work?
    I am brand new to blogging but I do write
    in my diary everyday. I’d like to start a blog so I can share my experience
    and views online. Please let me know if you have any recommendations or tips for
    new aspiring bloggers. Appreciate it!

    Reply

  12. Excellent post. I was checking constantly this blog and
    I am impressed! Extremely useful information particularly the last part :
    ) I care for such information a lot. I was seeking this particular information for
    a very long time. Thank you and good luck.

    Reply

  13. 36 hour cialis online cialis discounts – cialis without prescription

    Reply

Leave a reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.