给你。如果我理解正确,您希望在上传附件后获取信息。
所以把这个代码放进去functions.php
文件这里有两个功能-一个是在上传图像并显示以编辑信息后启动的(或总是在编辑附件时启动),另一个是在用户单击附件上的保存时启动的。
使用这两个函数,您可以制作任何您想要的内容:)
add_filter("attachment_fields_to_edit", "wpse_54409_image_details_on_edit", null, 2);
add_filter("attachment_fields_to_save", "wpse_54409_image_details_on_save", null , 2);
function wpse_54409_image_details_on_edit($form_fields, $post) {
//we interested only in images so ->
if( substr($post->post_mime_type, 0, 5) == \'image\' ){
$meta = get_post_custom($post->ID);
echo \'This attachment ID: \'.$post->ID;
echo \'<br>\';
echo \'This attachment title: \'.$post->post_title;
echo \'<br>\';
echo \'This attachment post name: \'.$post->post_name;
echo \'<br>\';
echo \'Alt. text: \'.$meta[\'_wp_attachment_image_alt\'][0];
echo \'<br>\';
echo \'File name: \'.$meta[\'_wp_attached_file\'][0];
}
return $form_fields;
}
function wpse_54409_image_details_on_save($post, $attachment) {
//we interested only in images so ->
if( substr($post->post_mime_type, 0, 5) == \'image\' ){
/*
HERE YOU CAN GET ALL INFO UPPON ATTACHMENT IS SAVED
AND DO WITH THAT INFO WHATEVER YOU WANT
EVEN ALTER IT TO MAKE CHANGES TO IT
*/
}
return $post;
}