Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards!

Set min and max image resolution only on edit-product page

WCMp Advanced Frontend Manager

Resolved
Viewing 34 reply threads
  • Author
    Posts
    • #136424
      Tim Kerremans
      Participant

      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

    • #136456

      Hi, thanks for getting in touch with us.
      Our team is looking into it and will get back to you.

    • #136485

      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
    • #136497
      Tim Kerremans
      Participant

      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.

    • #136498

      Hi,
      Set restriction for only vendor storefont page you can use this hook

      do_action('wcmp_before_shop_front');
      Copy
    • #136503
      Tim Kerremans
      Participant

      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?

    • #136574

      @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.

    • #136689
      Tim Kerremans
      Participant

      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’);
      }

    • #136719

      Hi,
      use

      wcmp_is_store_page()
      Copy

      this funtion to check vendor shop page.

    • #137661
      Tim Kerremans
      Participant

      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!

    • #137673

      hi,
      You can modify logo ratio by using

      wcmp_frontend_dash_upload_script_params
      Copy

      this filter. You will find the explanation here – https://github.com/wcmarketplace/dc-woocommerce-multi-vendor/blob/master/classes/class-wcmp-library.php#L107
      Thanks

    • #137677
      Tim Kerremans
      Participant

      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

    • #137751

      @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?

    • #137752
      Tim Kerremans
      Participant

      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/

    • #137753
      Tim Kerremans
      Participant

      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/

    • #137795

      @Tim Kerremans, thanks for the confirmation. Our team will assist you accordingly.

    • #137813
      Tim Kerremans
      Participant

      Great, thank you!

    • #137824

      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.

    • #137836
      Tim Kerremans
      Participant

      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

    • #137875
      Tim Kerremans
      Participant

      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

    • #137916

      Hi,
      you can chnage the checking by replacing with

      if (is_user_wcmp_vendor(get_current_user_id()) && isset($_SERVER['REQUEST_URI']) && false !== strpos( $_SERVER['REQUEST_URI'], 'edit-product' ) ) {
      Copy

      Thanks

    • #137917
      Tim Kerremans
      Participant

      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

    • #137947

      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

    • #138126
      Tim Kerremans
      Participant

      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

    • #138163

      @Tim Kerremans, first check with WordPress team whether there is any solution from WordPress team and share that with us.

    • #138230
      Tim Kerremans
      Participant

      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 408

      And 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.

    • #138252

      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.

    • #138280
      Tim Kerremans
      Participant

      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.

    • #138291

      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.

    • #138293
      Tim Kerremans
      Participant

      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 template

      As 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

    • #138314

      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.

    • #139028
      kuchlog25
      Participant

      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.

    • #140031

      @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.

    • #140109
      kuchlog25
      Participant

      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]

    • #142364

      Hi kuchlog25, any update on this?

Viewing 34 reply threads

The topic ‘Set min and max image resolution only on edit-product page’ is closed to new replies.