apply\\u filters调用如下:
apply_filters( \'wp_mime_type_icon\', $icon, $mime, $post_id ); // Last arg is 0 if function pass mime type.
看起来这是直接传递post\\u id,而不是post对象。那当然可以!请尝试此代码(注意,我没有尝试,我们只是从臀部开始拍摄)
function set_attachments_icon($icon, $mime, $post_id){
if (!$post_id) return $icon;
$thumb_id = get_post_meta($post_id,\'dsv_thumbnail_id\', true);
if($thumb_id){
$image_attributes = wp_get_attachment_image_src( $thumb_id );
$icon = $image_attributes[0];
}
return $icon;
}
add_filter(\'wp_mime_type_icon\', \'set_attachments_icon\', 10, 3);
然而,对我来说,这并没有因为
image_downsize
wp中包括/介质。php第607行。你也可以拦截它来做你需要做的事情。
function set_attachments_downsize($return, $attachment_id, $size){
if ( $size == \'thumbnail\' && $thumb_id = get_post_meta($attachment_id,\'dsv_thumbnail_id\', true) ) {
$image_attributes = wp_get_attachment_image_src( $thumb_id );
return $image_attributes[0];
}
return $return;
}
add_filter(\'image_downsize\', \'set_attachments_downsize\', 10, 3);
干杯~