image_attachment_fields_to_save()
最后更新于:2021-11-27 06:15:04
image_attachment_fields_to_save( array$post, array$attachment)Filters input from media_upload_form_handler() and assigns a default post_title from the file name if none supplied.
参数
- $post
-
(array) (Required) The GC_Post attachment object converted to an array.
- $attachment
-
(array) (Required) An array of attachment metadata.
响应
(array) Filtered attachment post object.
源文件
文件: gc-admin/includes/media.php
function image_attachment_fields_to_save( $post, $attachment ) {
if ( 'image' === substr( $post['post_mime_type'], 0, 5 ) ) {
if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
$attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
$post['post_title'] = preg_replace( '/.w+$/', '', gc_basename( $attachment_url ) );
$post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
}
}
return $post;
}