Chcę zmodyfikować ścieżkę $ w następującym filtrze. Ma 1 wejście i 2 argumenty.
function documents_template( $template = '' ) {
$path = DOCUMENTS_INCLUDES_DIR . '/document/' . $template;
return apply_filters( 'document_template', $path, $template );
}
To jest moja funkcja dodawania filtra, pojawia się komunikat o błędzie, jak to zrobić poprawnie?
function my_template( $template = '' ){
$path = MY_INCLUDES_DIR . '/document/'. $template;
return $path;
}
add_filter( 'document_template','my_template', 10, 2 );
Próbowałem zmienić wartość zwracaną w następujący sposób, to też nie działa:
return apply_filters( 'my_template', $path, $template);
Biorąc pod uwagę poniższe odpowiedzi, mój nowy filtr nadal nie działa, więc może dlatego, że mój filtr jest w klasie? oto zupełnie nowy kod:
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;
}
}