This question already has an answer here:

I'm in the process of writing a CDN plugin for WordPress and am trying to integrate it with the Advanced Custom Fields plugin. I need to filter the output of the "File" field type on the edit post screen so I can display the correct file size for an attachment not hosted locally.

Unfortunately, ACF doesn't provide a way to filter the output so I'm having to resort to completely overriding the ACF callback which outputs the field

To do this, I need to first remove the ACF callback from the action, then add my own. I'm not able to use remove_action() because the ACF callback is an object method and I cannot access the object variable

I don't want to use remove_all_actions() because it could potentially break other plugins hooking on to the action so I have come up with the following:

    global $wp_filter;

    if(isset($wp_filter['acf/create_field/type=file'])) {
        foreach($wp_filter['acf/create_field/type=file'] as $priority => $filters) {
            foreach($filters as $key => $filter) {
                if(is_array($filter['function']) && ($filter['function'][0] instanceof acf_field_file)) {

                    // If the function is an array, and the first part is an instance of the acf_field_file we have found what we're looking for

                    break 2;

    // Now add our own callback
    add_action('acf/create_field/type=file', array($this, 'create_file_field'));

There's just something about looping through the wp_filters global that I don't like. Is there a better way of doing this or am I going to have to stick with this ugly bit of code?

EDIT: I'd like to stress that this is NOT a support request/question for a 3rd party plugin (ACF). The plugin being used is not relevant to the question. The question, in it's most basic form, is how to remove a callback from an action which happens to be an object method where the object variable cannot be accessed

marked as duplicate by Pieter Goosen, Milo, fuxia Oct 29 '14 at 17:55

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.

  • this would be a good question for ACF support, 3rd party plugins are off-topic here. – Milo Oct 29 '14 at 17:24
  • 1
    This isn't a support request for ACF. It's a general WordPress actions/filters question - The fact the plugin is ACF is completely irrelevant – Andy Oct 29 '14 at 17:27
  • have you tried remove_action with the classname in place of the object var? – Milo Oct 29 '14 at 17:43
  • It needs a variable to an object instance of a class rather than a class name. I did try just to be sure, but it didn't work – Andy Oct 29 '14 at 20:49