我有一个很新的问题,但我对WordPress的开发还很陌生。我正在使用的插件中使用了这个过滤器。
if ( true === apply_filters( \'some_custom_filter\', false ) ) {
return $something;
}
现在我想
add_filter
所以它会回来
true
我如何做到这一点?
这是我正在尝试但不起作用的,它总是会回来false
public function setup_filters() {
add_filter( \'some_custom_filter\', array( $this, \'filter_suppress_the_content\' ), 10, 3 );
}
public function filter_suppress_the_content() {
return true;
}
这就是课堂。
private static $instance;
private static $wpcom_related_posts;
public static function get_instance() {
if( ! isset( self::$instance ) ) {
self::$instance = new Klazz;
self::$instance->setup_filters();
}
return self::$instance;
}
public function setup_filters() {
add_filter( \'some_custom_filter\', array( $this, \'filter_suppress_the_content\' ), 10, 1 );
}
public function filter_suppress_the_content( $false) {
return true;
}
最合适的回答,由SO网友:Shazzad 整理而成
你几乎接近了。
add_filter( \'some_custom_filter\', array( $this, \'filter_suppress_the_content\' ), 10, 3 );
// the above line states that, the method `filter_suppress_the_content` should have three arguments, where you have used nothing.
public function filter_suppress_the_content() {
return true;
}
// comparing your code, this method should have one argument
解决方案:
public function setup_filters() {
add_filter( \'some_custom_filter\', array( $this, \'filter_suppress_the_content\' ), 10, 1 );
}
public function filter_suppress_the_content( $false ){
return true;
}