SO网友:Frank P. Walentynowicz
WordPress 4.7简介WP_Hook
班全局变量$wp_filter
现在是WP_Hook
对象,每个“钩子”对应一个,钩子上附加了过滤器。这使得移除过滤器非常容易。
您仍然可以使用remove_filter
函数,以处理回调函数未在类中声明的筛选器。
下面的代码,您可以粘贴到其中functions.php
将允许删除任何筛选器:
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\' );