WordPress.org

Ready to get started?Download WordPress

Forums

Minimum upload size but for post types (1 post)

  1. crismdq
    Member
    Posted 1 year ago #

    Hello!

    I use a php code in my functions.php to enforce minimum upload size on images. I like to limit this feature only on a specific post type. Do you know how to do it?

    This is the code that limit the upload size of images.

    /**
     * Enforce minimum image upload size.
     */
    add_filter('wp_handle_upload_prefilter','handle_upload_prefilter');
    
    function handle_upload_prefilter($file) {
            $img=getimagesize($file['tmp_name']);
            $minimum = array('width' => '760', 'height' => '100');
            $width= $img[0];
            $height =$img[1];
    
            if ($width < $minimum['width'] ){
                    return array("error"=>"No subas imágenes chicas! El mínimo es {$minimum['width']}px de ancho. La que subiste tiene $width px.");
            } elseif ($height <  $minimum['height']){
                    return array("error"=>"No subas imágenes chicas! El mínimo es {$minimum['height']}px de alto. La que subiste tiene $width px.");
            } else {
                    return $file;
            }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic