[wp-trac] [WordPress Trac] #51133: Image uploaded through third party plugin showing in media but not showing up in post
WordPress Trac
noreply at wordpress.org
Tue Aug 25 14:26:23 UTC 2020
#51133: Image uploaded through third party plugin showing in media but not showing
up in post
-------------------------------------------+------------------------------
Reporter: ujw0l | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 5.5
Severity: normal | Resolution:
Keywords: needs-patch reporter-feedback | Focuses:
-------------------------------------------+------------------------------
Comment (by ujw0l):
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,',
'',$_POST['blob']))));
$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($productInfo['primaryImage']));
$imgUrl = dirname( $parsed [ 'path' ] ) . '/' .
rawurlencode( basename( $parsed[ 'path' ] ) );
if($productInfo['productPostId']>=1):
$postUrl =
get_post_permalink($productInfo['productPostId']);
endif;
$updatedReturn = array(
'updatedRow' => $result,
'productInventory'
=>$productInfo['productInventory'],
'postLink'=> $postUrl,
'productDimension'=>$productInfo['productDimension'],
'subCategory'=>$productInfo['subCategory'],
'primaryPicDir'=>$imgUrl,
'primaryPic'=>wp_get_attachment_image($productInfo['primaryImage'],array('50',
'50'), true),
'preOrder'=>
$productInfo['preOrder'],
'featureProduct'=>$productInfo['featureProduct']
);
Let me know if your need more information
Thanks
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51133#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list