ฉันต้องการแก้ไข $ path ในตัวกรองต่อไปนี้ มันมี 1 อินพุตและ 2 args
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;
}
}