我想在以下过滤器中修改$ path。它具有1个输入和2个args。
function documents_template( $template = '' ) {
$path = DOCUMENTS_INCLUDES_DIR . '/document/' . $template;
return apply_filters( 'document_template', $path, $template );
}
这是我添加过滤器的功能,它得到错误消息,如何正确处理?
function my_template( $template = '' ){
$path = MY_INCLUDES_DIR . '/document/'. $template;
return $path;
}
add_filter( 'document_template','my_template', 10, 2 );
我试图按以下方式更改返回值,但它也不起作用:
return apply_filters( 'my_template', $path, $template);
有了下面的答案,我的新过滤器仍然无法正常工作,所以,也许是因为我的过滤器在一个类中吗?这是全新的代码:
Class My_Class{
function __construct() {
add_filter( 'document_template', array( $this, 'my_template',10, 2 ) );
}
function my_template( $path, $template ){
$path = MY_INCLUDES_DIR . '/document/'. $template;
return $path;
}
}