Removing an action from wp_footer called in a class that’s inside a bigger class

Because of the way the plugin is structured, the hooked function appears to be ultimately exist on the gallery property of the instance property of the DGWT_JG_Core class.

When an instance of DGWT_JG_Core is created, a DGWT_JG_Gallery class is instantiated and added to the gallery property of the DGWT_JG_Core instance. So we need to remove the action from the gallery property of the instance of DGWT_JG_Core that was created when the plugin was run.

Since DGWT_JG_Core is a singleton there is only ever one instance of DGWT_JG_Core and we can access it with the get_instance() method. Helpfully for us, the plugin defines a function that calls this method for us. It’s that DGWT_JG() function at the end.

So to be able to remove the action we use DGWT_JG() to get the instance of DGWT_JG_Core, and access the DGWT_JG_Gallery class through the gallery property:

function wpse_284486_remove_justified_gallery() {
    $instance = DGWT_JG();

    remove_action( 'wp_footer', array( $instance->gallery, 'init_gallery' ), 90 );
}
add_action( 'wp_head', 'wpse_284486_remove_justified_gallery', 0 );

I tested this on a fake version of the classes that just implemented a single hook and it worked. I’ll post it here so you can maybe see what’s going on:

class My_Test_Gallery {
    function __construct() {
        add_action( 'wp_footer', array( $this, 'init_gallery' ), 90 );
    }

    function init_gallery() {
        echo 'Hello world!';
    }
}

class My_Test_Plugin {
    private static $instance;

    public static function get_instance() {
        if ( ! isset( self::$instance ) && ! ( self::$instance instanceof My_Test_Plugin ) ) {
            self::$instance = new My_Test_Plugin;
            self::$instance->gallery = new My_Test_Gallery;
        }

        return self::$instance;
    }

    private function __construct() {
        self::$instance = $this;
    }
}

function My_TP() {
    return My_Test_Plugin::get_instance();
}

My_TP();

function wpse_284486_remove_justified_gallery() {
    $instance = My_TP();

    remove_action( 'wp_footer', array( $instance->gallery, 'init_gallery' ), 90 );
}
add_action( 'wp_head', 'wpse_284486_remove_justified_gallery', 0 );