Я хочу змінити $ 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;
}
}