Ich möchte $ path im folgenden Filter ändern. Es hat 1 Eingang und 2 Argumente.
function documents_template( $template = '' ) {
$path = DOCUMENTS_INCLUDES_DIR . '/document/' . $template;
return apply_filters( 'document_template', $path, $template );
}
Dies ist meine Funktion, um Filter hinzuzufügen, es wird eine Fehlermeldung angezeigt, wie man es richtig macht?
function my_template( $template = '' ){
$path = MY_INCLUDES_DIR . '/document/'. $template;
return $path;
}
add_filter( 'document_template','my_template', 10, 2 );
Ich habe versucht, meinen Rückgabewert wie folgt zu ändern, es funktioniert auch nicht:
return apply_filters( 'my_template', $path, $template);
Mit den folgenden Antworten funktioniert mein neuer Filter immer noch nicht. Vielleicht liegt es daran, dass mein Filter in einer Klasse ist? Hier ist der völlig neue Code:
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;
}
}