我想在以下过滤器中修改$路径。它有1个输入和2个参数。
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;
}
}