다음 필터에서 $ path를 수정하고 싶습니다. 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;
}
}