目前还没有相关文档,但您可能可以通过attachment_fields_to_save
筛选并在此处插入默认标题。
From the Codex:
attachment_fields_to_save
在将附件保存到数据库之前,应用于与附件关联的字段。在media\\u upload\\u form\\u处理程序函数中调用。过滤器函数参数:一个post属性数组,一个附件字段数组,包括从表单提交的更改
定义于wp-admin/includes/media.php:
// TESTED :)
function wpse300512_image_attachment_fields_to_save($post, $attachment) {
if ( substr($post[\'post_mime_type\'], 0, 5) == \'image\' ) {
if ( \'\' === trim( $post[\'post_title\'] ) ) {
$post[\'post_title\'] = preg_replace(\'/\\.\\w+$/\', \'\', basename($post[\'guid\']));
$post[\'errors\'][\'post_title\'][\'errors\'][] = __(\'Empty Title filled from filename.\');
}
// captions are saved as the post_excerpt, so we check for it before overwriting
if ( \'\' === trim( $post[\'post_excerpt\'] ) ) {
$post[\'post_excerpt\'] = \'default caption\';
}
}
return $post;
}
add_filter(\'attachment_fields_to_save\', \'wpse300512_image_attachment_fields_to_save\', 10, 2);
UPDATE: 我设法对它进行了测试,它按原样工作。把它放在你的函数上就行了。php:)