Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › Add_filter on image upload only for product image
- This topic has 10 replies, 2 voices, and was last updated 4 years, 8 months ago by catou67.
- AuthorPosts
- April 28, 2020 at 3:08 am #123947catou67Participant
I have written a filter with the hoock ‘wp_handle_upload’ .
I would like to apply this filter only on product image
If I can identify which collaspe-content is displayed may be it could be sufficientThank’s for help
- April 28, 2020 at 11:21 am #124051SushobhanKeymaster
Hi,
Thanks for getting in touch with us!
Are you talking about the vendor ‘add product’ screen? Also I’ll need to know the purpose of your code otherwise it would be difficult for me to guide you.
If you want to locate the portion of code responsible for displaying the image section in Add/edit product page, open the filewc-frontend-manager\views\products-manager\wcfm-view-products-manage.php
and search for the filterwcfm_product_manage_fields_images
.
Looking forward to helping you.
Thank You! - April 28, 2020 at 12:53 pm #124095catou67Participant
Hi,
Thanks for your answer.My target is to build a square image for each product, including the FULL ORIGINAL image, that with adding blanck part on width or height.
No problem to write this code, my problem is to not apply this code to any uploaded image, but only for products image.I add add_filter on ‘wp_handle_upload’ : that is ok
add_filter(‘wp_handle_upload’, ‘cdpro_resize_image’, 10, 2 );
function cdpro_resize_image( $array, $context ) {
if ( I would like to apply this filter only on product image upload ) {
$ok = array( ‘image/jpeg’, ‘image/gif’, ‘image/png’ );
if ( ! in_array( $array[‘type’], $ok ) ) return $array;$im = imagecreatefromjpeg($array[‘file’]);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 4, 5, 5, ‘Some text’ , $text_color);
imagejpeg($im, $array[‘file’]);// Libération de la mémoire
imagedestroy($im);}
return $array;}
Thank’s for help
- April 29, 2020 at 4:04 pm #124605SushobhanKeymaster
Hello,
Thanks for the clarification. You can use the following logic to determine if it’s product edit page or not-$referrer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ''; $wcfm_edit_product_url = get_wcfm_edit_product_url(); if( $referrer && strpos($referrer, $wcfm_edit_product_url) !== false ){ //your code goes here }
Let me know how it goes.
Thank You! - April 30, 2020 at 2:11 am #124830catou67Participant
Hi,
Thanks for your quick answer. It work’s “quite” well,
I would like to apply my filter only when I load a product image not when I add a media to a post.
How can I distinguish this 2 ways ?
There is certainly a way to do it : into the view select image the button to select the picture is
For a product image : “select”
For a media : “insert into product”Thank’s for help
Attachments:
You must be logged in to view attached files. - May 3, 2020 at 11:18 pm #126226catou67Participant
Hi,
I still search a solution to my problem. With no success after few hours !
I have written a filter (added to wp_handle_upload) which modify the uploaded image to keep the full original image into a square 500*500.
It’s work fine, image is not streched but blank area is added on top/buttom or left/right if the original imag is not a square image.
The filter is applied only in wcfm_edit_product
BUT
It is fine when I load the picture of the product but the same filter is done whe an image is uplaoded in the short or long descriptionI don’t find how to distinguish these 2 ways
Any idea ??
Thank’s for help I am near the target
- May 4, 2020 at 1:14 pm #126362SushobhanKeymaster
Hi,
There is no ready-made option to distinguish between these two case. Give me sometime to look for all the possibilities.
I’ll keep you posted, please be patient.
Thank You! - May 4, 2020 at 2:15 pm #126407catou67Participant
Thank’s for your response, I understand that this subject is not simple, I have spent somme hours with no success
Sorry to have disturbed you.
Bravo for the great job you do to help us
Regards - May 7, 2020 at 11:03 pm #128130catou67Participant
Hi,
I have solved my problem.
In fact I have written a java/php function associated to each “load media” instance (onclick). This function stores a flag in the database.
Flag which is tested when an upload image is done. So I know if the filter has to be applied.
It’s work fine .Regards
- May 8, 2020 at 3:29 pm #128365SushobhanKeymaster
Are you are storing a single key in options or user meta table? How it handles concurrent requests of uploads? There might be a race condition even from a single vendor, if she/he uses multiple tabs at once. Say, the vendor clicks on the image to open the WP media uploader, switch tabs, then click on media button above description field (More than one add product pages open in tabs). Again go back to previous tab and complete the product image upload. Will not that cause an issue?
I don’t know your implementation but this thing first comes to my mind, so I ask!
Thank you for keeping me updated. - May 8, 2020 at 11:06 pm #128538catou67Participant
Hi,
I add a meta_key to user meta table. I know that my solution has limits, but considering my vendors it’s suffisant at this time.
I will try to do better if the need arises.Thank you for your help
- AuthorPosts
- You must be logged in to reply to this topic.