如果我们看看wp_insert_attachment()
我们找到了钩子edit_attachment
和add_attachment
. 在你的情况下,我们可以使用add_attachment
钩回调将附件的ID作为参数。通过查看数据库表wp_posts
我们看到描述保存为post_content
标题为post_excerpt
:
然后您可以尝试以下代码段:
/**
* Default title, caption and description to uploaded attachments
*
* @param integer $post_ID The attachment\'s ID
* @return void
*/
function wpse_121709_upload_defaults( $post_ID )
{
$args = array(
\'ID\' => $post_ID,
\'post_title\' => \'My default title ...\',
\'post_excerpt\' => \'My default caption ...\',
\'post_content\' => \'My default description ...\',
);
wp_update_post( $args );
}
add_action( \'add_attachment\', \'wpse_121709_upload_defaults\' );
当您在媒体上载程序中上载文件时,应该会得到以下结果: