Make WordPress Core

Opened 4 years ago

Last modified 16 months ago

#51133 new defect (bug)

Image uploaded through third party plugin showing in media but not showing up in post

Reported by: ujw0l's profile ujw0l Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Media Keywords: reporter-feedback
Focuses: Cc:


I created a plugin which uploads Image to upload folder. It sends blob through ajax and uses wp_insert_attachment insert as attachment, wp_generate_attachment_metadata to generate meta data and uses wp_update_attachment_metadata to update meta data of attachment. And it shows up in media without file name and when I pragmatically insert attachment to the post using wp_get_attachment_image , it only display's attachment's name not image file.

Attachments (1)

Screen Shot 2020-08-25 at 13.29.59.png (234.9 KB) - added by ujw0l 4 years ago.
File name not showing on media section

Download all attachments as: .zip

Change History (5)

4 years ago

File name not showing on media section

#1 @Presskopp
4 years ago

  • Component changed from General to Media

#2 @SergeyBiryukov
4 years ago

  • Keywords reporter-feedback added
  • Severity changed from critical to normal

Hi there, welcome to WordPress Trac! Thanks for the report.

Could you provide the code you're using and the steps to reproduce the issue on a clean install?

#3 @ujw0l
4 years ago

first install plugin

and upload image

the install plugin

and create product along with and use image uploaded as product image.

code I am using for uploading image is

$fileName = wp_get_current_user()->user_login.'_'.time().'.png';

$outPutFile = wp_upload_dir()path?.'/'. $fileName;
$upload_file = file_put_contents($outPutFile, base64_decode(str_replace(' ', '+',str_replace('data:image/png;base64,', ,$_POSTblob?))));

$attachment = array(

'guid' => wp_upload_dir()url? . '/' . $fileName,
'post_mime_type' => wp_check_filetype( basename( $fileName ), null )type?,
'post_title' => sanitize_file_name( pathinfo( basename( $outPutFile), PATHINFO_FILENAME ) ),
'post_content' => ,
'post_status' => 'inherit'


$attach_id = wp_insert_attachment( $attachment );

Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
require_once( ABSPATH . 'wp-admin/includes/image.php' );

Generate the metadata for the attachment, and update the database record.
$attach_data = wp_generate_attachment_metadata( $attach_id, $outPutFile);

wp_update_attachment_metadata( $attach_id, $attach_data );

I am using ajax to upload blob

Code i am using to programatically creating post with attachment is

data to be retuned on success

$parsed = parse_url(wp_get_attachment_url($productInfoprimaryImage?));
$imgUrl = dirname( $parsed [ 'path' ] ) . '/' . rawurlencode( basename( $parsed[ 'path' ] ) );


$postUrl = get_post_permalink($productInfoproductPostId?);


$updatedReturn = array(

'updatedRow' => $result,
'productInventory' =>$productInfoproductInventory?,
'postLink'=> $postUrl,
'primaryPic'=>wp_get_attachment_image($productInfoprimaryImage?,array('50', '50'), true),
'preOrder'=> $productInfopreOrder?,


Let me know if your need more information


#4 @Mista-Flo
16 months ago

  • Keywords needs-patch removed

Can you give more details please?

Is it still reproducible?

The PHP code you shared is not well formatted hence really hard to read

Note: See TracTickets for help on using tickets.