Opened 4 years ago
Last modified 23 months ago
#51133 new defect (bug)
Image uploaded through third party plugin showing in media but not showing up in post
Reported by: | ujw0l | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Media | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
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)
Change History (5)
#2
@
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
@
4 years ago
first install plugin
https://wordpress.org/plugins/js-crop/
and upload image
the install plugin
https://wordpress.org/plugins/ct-commerce/
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 );
if(is_numeric($attach_id)):
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' ] ) );
if($productInfoproductPostId?>=1):
$postUrl = get_post_permalink($productInfoproductPostId?);
endif;
$updatedReturn = array(
'updatedRow' => $result,
'productInventory' =>$productInfoproductInventory?,
'postLink'=> $postUrl,
'productDimension'=>$productInfoproductDimension?,
'subCategory'=>$productInfosubCategory?,
'primaryPicDir'=>$imgUrl,
'primaryPic'=>wp_get_attachment_image($productInfoprimaryImage?,array('50', '50'), true),
'preOrder'=> $productInfopreOrder?,
'featureProduct'=>$productInfofeatureProduct?
);
Let me know if your need more information
Thanks
File name not showing on media section