2010-01-05 4 views
1

Wordpress에서 컨텐트 편집자가 이미지를 게시물에 업로드 할 때 "전체 크기"옵션을 선택하지 못하게 할 방법이 있습니까? "축소판", "중간"및 "큰"옵션 만 갖기를 바랍니다. 나는 이것을하기 위해 가위 플러그인을 사용했지만, Wordpress 2.9에서는이 플러그인이 더 이상 작동하지 않습니다.Wordpress 사용자가 전체 크기 이미지 업로드를 허용하지 못하도록

답변

4

WordPress에서 전체 크기 옵션을 표시하지 않아도이 결과를 얻을 수 있습니다. 크기 라디오 버튼을 만드는 함수는 wp-admin/includes/media.php이고 image_size_input_fields이라고합니다.

알고있는 함수에 대한 필터 또는 액션 훅은 없지만 필터를 호출하는 함수 (image_attachment_fields_to_edit)의 필터 훅은 attachment_fields_to_edit입니다.

기본적으로 필터 훅을 사용하여이 두 함수를 재정의 할 수 있습니다.

표준 functions.php 파일에서 작동하거나 플러그인에 통합 할 수 있다고 가정합니다. 우리는 우리의 두 가지 기능을 만들

add_filter('attachment_fields_to_edit', 'MY_image_attachment_fields_to_edit', 11, 2); 

다음 :

첫째, 새로운 필터를 추가 할 수 있습니다. 난 그냥이 사건에 대한 MY_로 이름을 접두어로했습니다

function MY_image_attachment_fields_to_edit($form_fields, $post) { 
if (substr($post->post_mime_type, 0, 5) == 'image') { 
    $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); 
    if (empty($alt)) 
    $alt = ''; 

    $form_fields['post_title']['required'] = true; 

    $form_fields['image_alt'] = array(
    'value' => $alt, 
    'label' => __('Alternate text'), 
    'helps' => __('Alt text for the image, e.g. “The Mona Lisa”') 
); 

    $form_fields['align'] = array(
    'label' => __('Alignment'), 
    'input' => 'html', 
    'html' => image_align_input_fields($post, get_option('image_default_align')), 
); 

    $form_fields['image-size'] = MY_image_size_input_fields($post, get_option('image_default_size', 'medium')); 


} else { 
    unset($form_fields['image_alt']); 
} 

return $form_fields; 
} 

일반 워드 프레스 함수에서 여기 변경된 유일한 것은 우리가 대신 image_size_input_fieldsMY_image_size_input_fields를 호출하고 있다는 점이다. 실제 숨어 않습니다

이제 기능 : 두 가지 변경이 마지막 기능에서

function MY_image_size_input_fields($post, $check = '') { 

    // get a list of the actual pixel dimensions of each possible intermediate version of this image 
    /* $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size')); */ 
    $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large')); 

    if (empty($check)) 
    $check = get_user_setting('imgsize', 'medium'); 

    echo '<pre>'; print_r($check); echo '</pre>'; 


    foreach ($size_names as $size => $label) { 

    $downsize = image_downsize($post->ID, $size); 
    $checked = ''; 

    // is this size selectable? 
    $enabled = ($downsize[3] || 'large' == $size); 
    $css_id = "image-size-{$size}-{$post->ID}"; 
    // if this size is the default but that's not available, don't select it 
    if ($size == $check) { 
    if ($enabled) 
    $checked = " checked='checked'"; 
    else 
    $check = ''; 
    } elseif (!$check && $enabled && 'thumbnail' != $size) { 
    // if $check is not enabled, default to the first available size that's bigger than a thumbnail 
    $check = $size; 
    $checked = " checked='checked'"; 
    } 

    $html = "<div class='image-size-item'><input type='radio' " . ($enabled ? '' : "disabled='disabled' ") . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />"; 

    $html .= "<label for='{$css_id}'>$label</label>"; 
    // only show the dimensions if that choice is available 
    if ($enabled) 
    $html .= " <label for='{$css_id}' class='help'>" . sprintf(__("(%d&nbsp;&times;&nbsp;%d)"), $downsize[1], $downsize[2]). "</label>"; 

    $html .= '</div>'; 

    $out[] = $html; 

    } 

    return array(
    'label' => __('Size'), 
    'input' => 'html', 
    'html' => join("\n", $out), 
); 
} 

. 맨 위에서 $ size_names 배열 정의에서 '전체 크기'에 대한 참조를 제거합니다. 그런 다음 $enabled = ($downsize[3] || 'large' == $size);라고 표시된 행이 변경되었습니다. 'full' == $size'large' == $size으로 바 꾸었습니다. 나는 큰 크기를 사용하지 않도록 찾는 게 아니에요 alt text

+0

감사합니다! 이것은 내가 원하는 것입니다! – Kyle

0

큰 크기를 비활성화 할 수는 없지만 너비와 높이를 중간 크기와 같게 설정할 수는 있습니다. 설정 아래에 있습니다 → 미디어

+0

:

다음은 결과의 스크린 샷입니다. 난 그냥 크기를 조정하지 않고 기본적으로 이미지를 "있는 그대로"삽입하는 전체 크기를 비활성화하려고합니다. 그리고 이것에 대한 상한을 정할 수있는 것처럼 보이지 않습니다. – Kyle

관련 문제