admin管理员组文章数量:1122846
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
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
Share Improve this question asked May 28, 2017 at 7:21 mr_edmr_ed 112 bronze badges 1 |2 Answers
Reset to default 1As 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
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' );
本文标签: Remove Content Filter
版权声明:本文标题:Remove Content Filter 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300120a1930703.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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