Checking page before applying image restrictions while uploading

Question

so users can upload images on my website and I want to put some restrictions on these images while they are uploading. The catch is that these image restriction can only apply on one page, being the edit product page and also the user has to be a vendor.

I already tried checking by template and ID of the page but this page lives below a parent page and that did not work, meaning that the function could not check the current page.

I currently have the code below but now it is rejecting all images and not displaying the correct message, just a general message that uploading the image failed. Anyone that can help me out?

if (is_user_wcmp_vendor(get_current_user_id()) && isset($_SERVER['REQUEST_URI']) && false !== strpos( $_SERVER['REQUEST_URI'], 'edit-product' ) ) {
    $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;
    }
  }
} 
add_filter('wp_handle_upload_prefilter', 'resize_image_resolution')
0
timkerrem 2 months 2022-06-20T05:01:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse