我正在尝试删除一些页面的SEO ultimate插件添加的操作挂钩。它添加到插件类中的方式是
//Hook to output all <head> code i changed the priority to 2
add_action(\'wp_head\', array(&$this, \'template_head\'), 2);
SEO插件创建如下全局变量
global $seo_ultimate;
$seo_ultimate =& new SEO_Ultimate(__FILE__);
在我的插件中,我尝试通过
add_action(\'wp_head\',array($this, \'remove_seo_header\'),1);
}
function remove_seo_header() {
remove_action(\'wp_head\', array($seo_ultimate,\'template_head\'));
}
但它并没有删除该操作。有人能指出我错在哪里吗?
SO网友:Luke Gedeon
您还可以通过注册的钩子进行foreach,如下所示:
function remove_filter_in_class( $tag, $function_to_remove, $priority, $class ) {
if ( isset( $GLOBALS[\'wp_filter\'][ $tag ][ $priority ] ) ) {
foreach ( $GLOBALS[\'wp_filter\'][ $tag ][ $priority ] as $key => $function ) {
if ( is_array( $function[\'function\'] )
&& $function_to_remove === array_pop( $function[\'function\'] )
&& $class === get_class( array_pop( $function[\'function\'] ) )
) {
return remove_filter( $tag, $key, $priority );
}
}
}
}
资料来源:
https://gist.github.com/lgedeon/7806513f47b6466fc2cb