syntax for remove_filter in parent theme with class

I’m trying to remove a filter on the register_url hook a parent theme added, that seems to have a class nomenclature I can’t figure out.

Ordinarily, a filter for this hook would be easily added like so:

    add_filter( 'register_url', 'custom_register_url' );
    function custom_register_url( $register_url )
    {
        $register_url = "YOUR_PAGE_URL";
        return $register_url;
    }

However, the parent theme has added its own filter to this hook, and due to loading sequence, my child theme can’t overwrite that filter (this issue is discussed here and demonstrated here and in detail here).

That process is relatively straightforward, but the parent theme I am working from has placed this filter and function within object oriented programming, which has my brain aching. WordPress Codex says

If a filter has been added from within a class, for example by a plugin, removing it will require accessing the class variable.

   global $my_class;
   remove_filter( 'the_content', array($my_class, 'class_filter_function') );

But I can’t figure out the correct nomenclature to access this function. Here is a snippet of the parent theme:

    class APP_Registration extends APP_Login_Base {

        private static $_template;

        private $error;

        function get_action() {
            return 'register';
        }

        function __construct( $template ) {
            self::$_template = $template;
            parent::__construct( $template, __( 'Register', APP_TD ) );

            add_action( 'appthemes_after_registration', 'wp_new_user_notification', 10, 2 );
            add_filter( 'register_url', array( $this, '_change_register_url' ), 10, 1 );
        }

        function _change_register_url( $url ) {
            return self::get_url( 'raw' );
        }

    . . .

Trying to remove the filter just listing the function (_change_register_url) doesn’t work:

    function custom_register_url( $register_url )
    {
        $register_url = "YOUR_PAGE_URL";
        return $register_url;
    }
    add_filter( 'register_url', 'custom_register_url' );

    function remove_parent_filters() {
        remove_filter( 'register_url', '_change_register_url' );
        add_filter( 'register_url', 'custom_register_url' );
    }
    add_action( 'after_setup_theme', 'remove_parent_filters' );

Because I assume, I need to indicate the function hooked by it’s correct class name.

Can anyone help me figure out the proper remove filter syntax for this line?

        remove_filter( 'register_url', '_change_register_url' );

2 Answers
2

It looks like the plugin doesn’t want you do access the APP_Registration instance, so you can try this:

add_filter( 'register_url', function( $url )
{
    // Adjust this to your needs
    $url = site_url( 'wp-login.php?action=register', 'login' );

    return $url;
}, 11 );

to override the plugin’s modifications, where we use a priority > 10.

Leave a Comment