在Wordpress中是否有任何方式阻止内容编辑者在将图片上传到文章时选择“全尺寸”选项?我希望他们只有“缩略图”,“中等”和“大”选项。我曾经使用剪刀插件来做到这一点,但从Wordpress 2.9开始,这个插件不再有效。Wordpress阻止用户发布全尺寸图片上传
回答
你可以通过强迫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;
}
这是这里改变从正常的WordPress的功能,唯一的事情是,我们调用MY_image_size_input_fields
,而不是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 × %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);
,我们改变了。我们简单地用'large' == $size
替换'full' == $size
。
这里的结果的截图:
我不认为你可以禁用大尺寸,但你可以将其宽度和高度设置为与中等尺寸相同。它在设置→媒体
我不希望禁用大尺寸。我只是想禁用基本上只是插入图像“原样”没有任何调整大小的全尺寸。并没有出现你可以设置上限。 – Kyle 2010-01-05 19:07:58
- 1. WordPress的:停止上传全尺寸的图像
- 2. 我可以获取用户墙上发布的全尺寸照片吗?
- 3. 查看上传的图片尺寸
- 4. PHP正确尺寸上传图片
- 5. 大尺寸PHP上传图片
- 6. 调整上传图片的尺寸
- 7. 获取上传图片的尺寸?
- 8. 上传WordPresspress最小图片尺寸
- 9. 标准尺寸的上传图片(PHP)
- 10. 在Facebook上使用全尺寸在全尺寸上照片使用GRAPH API Android
- 11. 图片尺寸,客户端文件上传后选
- 12. 如何使用Telegram Bot从用户上传的API下载全尺寸照片
- 13. 无法获得全尺寸的动态WordPress灯箱图片
- 14. Android:MediaStore.Images.Media.EXTERNAL_CONTENT_URI ...在全尺寸显示图片?
- 15. Inno CustomPage全尺寸背景图片
- 16. Jquery/CSS:全尺寸背景图片
- 17. 大尺寸图片不在服务器上使用PHP上传
- 18. 图片WaterMark尺寸
- 19. 上传尺寸PHP
- 20. 图片上传,采集图像尺寸指令
- 21. 上传前用画布调整图像尺寸
- 22. 在发布之前减小图片的尺寸
- 23. 全尺寸Silverlight应用尺寸
- 24. 限制按尺寸和尺寸上传无效图像
- 25. Django图片上传中...阻止巨大文件上传
- 26. 发行上传图片到WordPress
- 27. 尺寸背景图片?
- 28. WallpaperManager错误图片尺寸
- 29. 图片尺寸奇数
- 30. 小尺寸图片问题
谢谢!这正是我想要的! – Kyle 2010-01-11 14:15:16