1

I need help with removing the Content Filter from a Plugin:

add_filter( 'the_content', array( &$this, 'addContentAds' ), 8 );

Do someone could help me please?

Thank you and best regards

1
  • what have you tried? Did you look at remove_filter manual? Is it a feature you don't need or are you abusing a free plugin?
    – RST
    Commented May 28, 2017 at 8:52

2 Answers 2

1

As the filter occurs within a class you must remove it by replacing $this (as you don't run the remove_filter on the class, $this is not available) with the name of the class where it is declared.

An example with a class called: Wecba, you will remove it like this:

remove_filter('the_content', array('Wecba', 'add_Content_Ads'), 8);

It's nos only depends on the class name.

Hope it helps

2
0

WordPress 4.7 introduced WP_Hook class. The global variable $wp_filter is now an array of WP_Hook objects, one for every 'hook', which has filters attached to it. That makes removing filters quite easy.

You can still use remove_filter function, to handle filters with callback function not being declared within a class.

The code below, which you paste into functions.php of your current theme, will allow to remove any filter:

function remove_the_content_filter() {
    global $wp_filter;

    $hook = 'the_content';
    $callback = 'addContentAds';
    $priority = 8;

    if ( !is_object( $wp_filter[ $hook ] ) )
        // no filters for this $hook
        return;

    $prts = $wp_filter[ $hook ]->callbacks; // array
    $prts_cnt = count( $prts );
    $prty = $wp_filter[ $hook ]->callbacks[ $priority ]; // array

    if ( !is_array( $prty ) )
        // no filters with this $priority
        return;

    $prty_cnt = count( $prty );

    foreach ( $prty as $key => $val ) {
        if ( false != stripos( $key, $callback ) ) {
            if ( ( 1 == $prts_cnt ) && ( 1 == $prty_cnt ) ) {
                // our filter the one only
                unset( $wp_filter[ $hook ] );
                return;
            } else {
                if ( 1 == $prty_cnt ) {
                    // our filter the only one with this $priority
                    unset( $wp_filter[ $hook ]->callbacks[ $priority ] );
                    return;
                } else {
                    // there are more filters with this $priority, remove our filter
                    unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $key ] );
                    return;
                }
            } 
        }
    }
}
add_action( 'wp_head', 'remove_the_content_filter' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.