2011-07-30 30 views

回答

2

您需要使用過濾器media_send_to_editor

add_filter('media_send_to_editor', 'so_6884350_send_to_editor', 10, 3); 

function so_6884350_send_to_editor($html, $send_id, $attachment) 
{ 
    /* Manipulate $html result */ 
    return $html; 
} 

$html是將在您的帖子中插入的代碼。類似於<a href='http://example.com/wp-content/uploads/2012/11/README.rtf'>README</a>

$send_id是正在插入的附件的ID。用它來獲取有關附件的信息,即get_post_mime_type($send_id);

$attachment是具有以下結構的陣列:

array(
    ['menu_order'] => 
    ['post_title'] => 'README' 
    ['post_excerpt'] => 
    ['post_content'] => 
    ['url'] => 'http://example.com/wp-content/uploads/2012/11/README.rtf' 
)