2016-04-28 15 views
2

Ich versuche, Einschränkungen hinzuzufügen, wenn meine Nutzer das Bild hochladen. Ich habe versucht, diese Funktion in der Datei function.php zu verwenden, aber es fügt Einschränkungen für das Hochladen von Bildern für Benutzer und Administratoren hinzu.Wordpress Bildeinschränkungen für Funktionen beim Hochladen

add_filter('wp_handle_upload_prefilter','mdu_validate_image_size'); 
function mdu_validate_image_size($file) { 
$image = getimagesize($file['tmp_name']); 
$minimum = array(
    'width' => '1000', 
    'height' => '1000' 
); 
$maximum = array(
    'width' => '1000', 
    'height' => '1000' 
); 
$image_width = $image[0]; 
$image_height = $image[1]; 

$too_small = "Image dimensions are too small. Minimum size is {$minimum['width']} x {$minimum['height']} pixels. Uploaded image is $image_width x $image_height pixels."; 
$too_large = "Image dimensions are too large. Maximum size is {$maximum['width']} x {$maximum['height']} pixels. Uploaded image is $image_width x $image_height pixels."; 

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; 

}

Wie kann ich diese Funktion ändern, dass nur Feature Bildgröße zu erhalten oder welche Filter muss ich verwenden?

+0

https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ – TheGameiswar

Antwort

0
add_filter('post_thumbnail_html', 'my_post_image_html', 10, 3); 
function my_post_image_html($html, $post_id, $post_image_id) { 
    $html = '<a href="'.get_permalink($post_id).'"title="'.esc_attr(get_the_title($post_id)).'">'.$html.'</a>'; 
    return $html; 
} 

Kann dies helfen.