Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress阻止用户上传完整大小的图像_Wordpress - Fatal编程技术网

Wordpress阻止用户上传完整大小的图像

Wordpress阻止用户上传完整大小的图像,wordpress,Wordpress,Wordpress中是否有任何方法阻止内容编辑器在将图像上载到帖子时选择全尺寸选项?我希望他们有缩图、中号和大号选项。我曾经使用剪刀插件来实现这一点,但是从Wordpress 2.9开始,这个插件就不再工作了。我认为你不能禁用大尺寸,但你可以将它的宽度和高度设置为与中等尺寸相同。正在设置中→ 媒体您可以通过强制WordPress不显示全尺寸选项来实现此结果。创建大小单选按钮的函数位于wp admin/includes/media.php中,称为image\u size\u input\u fie

Wordpress中是否有任何方法阻止内容编辑器在将图像上载到帖子时选择全尺寸选项?我希望他们有缩图、中号和大号选项。我曾经使用剪刀插件来实现这一点,但是从Wordpress 2.9开始,这个插件就不再工作了。

我认为你不能禁用大尺寸,但你可以将它的宽度和高度设置为与中等尺寸相同。正在设置中→ 媒体

您可以通过强制WordPress不显示全尺寸选项来实现此结果。创建大小单选按钮的函数位于wp admin/includes/media.php中,称为image\u size\u input\u fields

据我所知,该函数没有筛选器或操作挂钩,但调用它的函数image\u attachment\u fields\u to\u edit有一个附件\u fields\u to\u edit的筛选器挂钩

所以基本上我们可以使用过滤器钩子来覆盖我们自己的两个函数,只需稍微修改一下

这将在standard functions.php文件中工作,或者我认为您可以将其合并到插件中

首先,添加新过滤器:

add_filter('attachment_fields_to_edit', 'MY_image_attachment_fields_to_edit', 11, 2);
接下来我们创建两个函数。对于这种情况,我刚刚在名称前面加上我的前缀:

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;
}
这里唯一与普通WordPress函数不同的是,我们调用的是MY_image_size_input_字段,而不是image_size_input_字段

现在,执行实际隐藏的函数:

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\u names数组定义中对“Full Size”的引用。然后写着$enabled=$downsize[3]| |“large”=$size;,我们改变了。我们只是用“大”==$size替换了“满”=$size

以下是结果的屏幕截图:

我不想禁用大尺寸。我只是想禁用全尺寸,它基本上只是插入图像,没有任何大小调整。看来你不能给这个设定上限。谢谢!!这正是我想要的!