[英]Override Wordpress admin function?
我想覆蓋get_sample_permalink_html
從可濕性粉劑管理員/ post.php中。 如果我直接修改文件,則更改有效。 但是,我想以一種更簡潔的方式來執行此操作,這意味着在插件內進行操作,以確保其面向未來。 這是我在PHP插件文件中嘗試過的方法:
add_filter('get_sample_permalink_html', 'custom_get_sample_permalink_html', 1, 3);
function custom_get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
(...)
}
它在不顯示錯誤的情況下中斷了頁面,我該怎么辦?
好吧,該函數具有一個過濾器,您可以使用它,而不是“覆蓋”該函數,而是操縱其輸出:
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
因此,您需要以下內容:
add_filter( 'get_sample_permalink_html', 'custom_get_sample_permalink_html', 15, 4 );
function custom_get_sample_permalink_html( $return, $id, $new_title, $new_slug )
{
// Manipulate the $return as you wish, using your own stuff and the passed variables:
// $id, $new_title, $new_slug
return $return;
}
15
是優先級,表示:“將其放在最后一個可能的位置”,如有必要,可以增加它。
4
是函數接收的參數數量,已在原始apply_filters
調用中檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.