WCMp Advanced Frontend Manager
-
AuthorPosts
-
-
April 13, 2022 at 8:33 PM #136424Tim KerremansParticipant
Hi,
I would like to restrict image resolution on the edit-product page and not on the storefront page. I have found the topic below:
https://multivendorx.com/support-forum/topic/enforce-minimum-and-maximum-image-resolutions-on-vendor-upload/Unfortunately, the response where the two provided codes are combined properly is a private response. Can you please share this code?
Thanks in advance
-
April 14, 2022 at 9:26 PM #136456MVX Support NinjaKeymaster
Hi, thanks for getting in touch with us.
Our team is looking into it and will get back to you. -
April 15, 2022 at 10:27 AM #136485MVX Support NinjaKeymaster
Hi,
Use this modified code in your current themes functions.php file./** Upload image restriction ****/ function resize_image_resolution($file) { if(is_user_wcmp_vendor(get_current_user_id())){ $image = getimagesize($file['tmp_name']); $minimum = array( 'width' => '400', //set your minimum 'height' => '400' ); $maximum = array( 'width' => '1000', //set your maximum 'height' => '1000' ); $image_width = $image[0]; $image_height = $image[1]; $too_small = "Image dimensions are too small."; $too_large = "Image dimensions are too large."; if ( $image_width < $minimum['width'] || $image_height < $minimum['height'] ) { $file['error'] = $too_small; return $file; } elseif ( $image_width > $maximum['width'] || $image_height > $maximum['height'] ) { $file['error'] = $too_large; return $file; } else return $file; } else { return $file; } } add_filter('wp_handle_upload_prefilter', 'resize_image_resolution');
Copy -
April 15, 2022 at 5:40 PM #136497Tim KerremansParticipant
Hi, this is literally the same code as provided in the linked topic.
As I said above, I want to apply these restrictions ONLY on the edit product page, not on the whole vendor dashboard as I want them to be able to upload their logo and banner image.
-
April 15, 2022 at 5:53 PM #136498MVX Support NinjaKeymaster
Hi,
Set restriction for only vendor storefont page you can use this hookdo_action('wcmp_before_shop_front');
Copy -
April 15, 2022 at 6:26 PM #136503Tim KerremansParticipant
Yes thanks but where do I have to add this hook? Can you provide me the complete code with this hook already applied to it?
-
April 18, 2022 at 1:27 PM #136574NerdySupportExpert MoumitaKeymaster
@Tim Kerremans, we don’t have any readymade code for the product add page only.
You need to use the above action to modify the code by adding your own custom code and apply for add product page only.
-
April 21, 2022 at 3:26 PM #136689Tim KerremansParticipant
I figured that I could also check for page template to disable this funtion on shopfront page, however when I try following code it is still working on the shopfront page. Any idea what I’m doing wrong here?
if ( !is_page_template( ‘shop-front’ ) ) { // name of template you don’t want to run it on
function resize_image_resolution($file) {
if(is_user_wcmp_vendor(get_current_user_id())){
$image = getimagesize($file[‘tmp_name’]);
$minimum = array(
‘width’ => ‘1080’, //set your minimum
‘height’ => ‘1080’
);
$maximum = array(
‘width’ => ‘12000’, //set your maximum
‘height’ => ‘12000’
);
$image_width = $image[0];
$image_height = $image[1];$too_small = “Image dimensions are too small.”;
$too_large = “Image dimensions are too large.”;if ( $image_width < $minimum[‘width’] || $image_height < $minimum[‘height’] ) {
$file[‘error’] = $too_small;
return $file;
}
elseif ( $image_width > $maximum[‘width’] || $image_height > $maximum[‘height’] ) {
$file[‘error’] = $too_large;
return $file;
}
else
return $file;
} else {
return $file;
}
}add_filter(‘wp_handle_upload_prefilter’, ‘resize_image_resolution’);
} -
April 21, 2022 at 10:11 PM #136719Raju The Cool GuyKeymaster
Hi,
usewcmp_is_store_page()
Copythis funtion to check vendor shop page.
-
June 3, 2022 at 2:52 AM #137661Tim KerremansParticipant
Hi,
Thanks for helping me out, however I’m still not able to get it working. Can you include this function into the code I received earlier? Also, would it also be possible to prevent this code from working on the profile page as well? The vendors can upload their profile image so I don’t want to set the limitations over there. You would help me alot.
Thanks in advance!
-
June 3, 2022 at 9:00 PM #137673Raju The Cool GuyKeymaster
hi,
You can modify logo ratio by usingwcmp_frontend_dash_upload_script_params
Copythis filter. You will find the explanation here – https://github.com/wcmarketplace/dc-woocommerce-multi-vendor/blob/master/classes/class-wcmp-library.php#L107
Thanks -
June 4, 2022 at 12:02 AM #137677Tim KerremansParticipant
Hi,
Thanks for your response but I don’t want to modify the logo as the minimum resolution of the uploaded product files has to be 1080p, if I modify logo and banner picture to be 1080p on the shortest side it would make waaay to large files on my website. I just want to exlude the shopfront and profile page from the funtion so that they are not affected in any way
-
June 7, 2022 at 10:18 PM #137751NerdySupportExpert MoumitaKeymaster
@Tim Kerremans, please assit us whether we have understood your requirement properly.
You wanted to set image resolution for the products only but not for the vendor shop page.
Can you please confirm that?
-
June 8, 2022 at 8:01 PM #137752Tim KerremansParticipant
Thanks for getting back to me.
-> correct, but on top of that also not for the profile page if possible.
These are the urls of the vendor shop page and profile page:
https://myurl.com/dashboard/profile/
https://myurl.com/dashboard/storefront/ -
June 8, 2022 at 8:01 PM #137753Tim KerremansParticipant
Hi, thanks for getting back to me.
-> Correct, but on top of that also not on the profile page
These are the urls of the vendor shop page and profile page:
https://www.myurl.com/dashboard/profile/
https://www.myurl.com/dashboard/storefront/ -
June 8, 2022 at 8:03 PM #137795NerdySupportExpert MoumitaKeymaster
@Tim Kerremans, thanks for the confirmation. Our team will assist you accordingly.
-
June 9, 2022 at 12:49 PM #137813Tim KerremansParticipant
Great, thank you!
-
June 9, 2022 at 9:31 PM #137824NerdySupportExpert MoumitaKeymaster
Tim, the filter we use for media upload i.e. wp_handle_upload_prefilter, is a WordPress hook.
Now, our vendor page checking does not work here. I am afraid, this restriction will work on all the pages.
-
June 10, 2022 at 12:19 PM #137836Tim KerremansParticipant
So you’re telling there is no way to exclude 2 urls from this function? We’re not trying to change the world here.. I mean I’m just trying to exclude 2 pages from a basic function. We should find a solution to this
-
June 11, 2022 at 5:56 PM #137875Tim KerremansParticipant
Hi, thanks for digging deeper into this. I have tried but unfortunately it’s not working on my end. The vendors are uploading the file on the edit-product page and not on the add-product page. Could that be the issue here? I already tried changing add-product to edit-product in the code but it’s not working.I guess because there is always the product id attached at the end of the url?
I attached a screenshot of the error message I’m receiving
-
June 13, 2022 at 8:58 PM #137916Raju The Cool GuyKeymaster
Hi,
you can chnage the checking by replacing withif (is_user_wcmp_vendor(get_current_user_id()) && isset($_SERVER['REQUEST_URI']) && false !== strpos( $_SERVER['REQUEST_URI'], 'edit-product' ) ) {
CopyThanks
-
June 13, 2022 at 9:12 PM #137917Tim KerremansParticipant
Hi,
Like I said in my previous message, this is not working. Replacing add-product with edit-product does not work on my end. Please look at my previous message
-
June 14, 2022 at 9:46 PM #137947Raju The Cool GuyKeymaster
Hi,
There is the only way to check is by using a URL. You can do one thing. Do all these things on wp hook. And add checking there. If still not working, please get in touch with WordPress support with this hook. Thanks -
June 21, 2022 at 3:02 PM #138126Tim KerremansParticipant
Hi,
Have posted this question on multiple forums in the meantime without any success. How can I do all these things on a WP hook?
I’m definitely willing to reach out to WP support but not sure how to create this hook as I don’t have much experience with PHP -
June 22, 2022 at 2:45 PM #138163NerdySupportExpert MoumitaKeymaster
@Tim Kerremans, first check with WordPress team whether there is any solution from WordPress team and share that with us.
-
June 24, 2022 at 2:23 PM #138230Tim KerremansParticipant
Hi,
They recommended to try debugging REQUEST_URI so I logged this in the errorlog and got the following log:
[24-Jun-2022 08:28:02 UTC] PHP Warning: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ (this will throw an Error in a future version of PHP) in /home/customer/www/staging5.holymowly.com/public_html/wp-content/themes/rehub-theme-child/functions.php on line 408And they also also recommended the following: would it be better to use applicable WP is_* function for checking the current page (ie /edit-post/) ?
-> I already tried getting the page based on template / ID without success.Hope this gives you some additional information to make this work.
-
June 25, 2022 at 1:23 PM #138252NerdySupportExpert MoumitaKeymaster
Hi Tim, the error you shared is coming from our custom code.
Regarding the hook, yes wp page checking is not working. wp page checking works only on enqueue page. we have used with request URL.
So, please ask them that you are using this hook
add_filter(‘wp_handle_upload_prefilter’, ‘resize_image_resolution’);And you want to apply this function for certain pages.
-
June 27, 2022 at 12:53 PM #138280Tim KerremansParticipant
Hi,
I gave them the full explanation, they suggested to debug further so I logged the errors in debug.log file and when uploading I receive two logs in that file, I attached the log to this message.
Also this is what another guy from WP form told me:
You might be able to use data returned by get_current_screen() to check if the correct page is being vistited. Once that check is passed, you can perform your other checks such as is_user_wcmp_vendor(). Note that anything specific to is_user_wcmp_vendor() is out of scope here on WPSE as third-party plugins are not covered. Also, your code is going to cause problems because if the first condition is not met, $file is never returned. Filters should always return a value. -
June 28, 2022 at 12:46 AM #138291NerdySupportExpert MoumitaKeymaster
Tim, we can only assit you on this if the WordPress team can share a working code that will restrict this option for any WordPress custom PHP
Then we can look into that code and assist you to modify the same for our dashboard.
Please check with them and ask them to provide a working code.
-
June 28, 2022 at 2:03 AM #138293Tim KerremansParticipant
I, and you guys have shared a working code that will restrict this option on WP, did you read the previous messages?
This function works, the only problem is that I want to apply this on only ONE page, which happens to be on your dashboard.Wordpress guys gave me 2 options to filter the page:
-> Apply if function based on current page ID
-> Apply if function based on current page templateAs this is indeed a page on your dashboard, they do not want to help me further. They can only help me with code related to WordPress and to debug this which I also shared with you.
I have been asking about this for over 2 months and it seems like we’re just going in circles. I really don’t know what else I need to provide as I already provided a working code! We just need to add a filter that will apply this code on only one page
-
June 28, 2022 at 8:25 PM #138314NerdySupportExpert MoumitaKeymaster
Tim, I understand that they can only help me with code related to WordPress.
That is why we asked them to give a working code snippet for the WordPress end, Therefore set the same min and max image for the media page only and not for the woocommerce add product page.
if we can have that code snippet, we can modify the same for us.
-
July 1, 2022 at 1:49 PM #139028kuchlog25Participant
I want to apply these restrictions ONLY on the edit product page, not on the whole vendor dashboard as I want them to be able to upload their logo and banner image.
-
July 4, 2022 at 3:39 PM #140031NerdySupportExpert MoumitaKeymaster
@kuchlog25, as shared with Tim, we tried all possible solutions but were not able to restrict this functionality to a single page.
As per WordPress hook/filter, we were not able to find any coding flow to achieve this.
That is why we asked Tim, whether WordPress team can share such coding snippet for their backend.Let’s hope the WordPress team can share such code snippets with us.
-
July 9, 2022 at 12:10 AM #140109kuchlog25Participant
I understand that they can only help me with code related to WordPress.
[url=https://hellodear.in/]hellodear.in[/url]
[url=https://teatv.ltd/dl-now/]teatv.ltd[/url]
-
September 28, 2022 at 1:55 PM #142364NerdySupportExpert MoumitaKeymaster
Hi kuchlog25, any update on this?
-
-
AuthorPosts
The topic ‘Set min and max image resolution only on edit-product page’ is closed to new replies.