Yazı veya sayfaya resim yüklerken çok küçük ya da çok büyük olmasını engellemek için genişlik ve yükseklik değerlerine sınır getirebiliriz. function.php dosyasına ekleyeceğimiz bir fonksiyon bunu sağlayabilir.
add_filter('wp_handle_upload_prefilter','mdu_validate_image_size'); function mdu_validate_image_size( $file ) { $image = getimagesize($file['tmp_name']); $minimum = array( 'width' => '320', 'height' => '500' ); $maximum = array( 'width' => '1500', 'height' => '1000' ); $image_width = $image[0]; $image_height = $image[1]; $too_small = "Yüklenen görüntünün boyutu çok küçük. Genişlik minimum {$minimum['width']}px ve yükseklik minimum {$minimum['height']}px olmalı. Yüklenen dosya $image_width x $image_height piksel."; $too_large = "Yüklenen görüntünün boyutu çok büyük. Genişlik maksimum {$maximum['width']}px ve yükseklik maksimum {$maximum['height']}px olmalı. Yüklenen dosya $image_width x $image_height piksel."; if ( $image_width < $minimum['width'] || $image_height < $minimum['height'] ) { // add in the field 'error' of the $file array the message $file['error'] = $too_small; return $file; } elseif ( $image_width > $maximum['width'] || $image_height > $maximum['height'] ) { //add in the field 'error' of the $file array the message $file['error'] = $too_large; return $file; } else return $file; }