0
这是在做我的坚果 我想调用特定页面上的功能。实际的功能似乎正在正常工作,防止用户在特定维度下提交图片。 问题是为了正确识别页面,所以这个功能只能在那个页面上运行。目前,只要媒体需要上传,任何地方都可以调用该功能。下面 代码,请过目:试图在wordpress的特定页面上调用特定功能
add_action('wp_handle_upload_prefilter', 'filter_media_pages');
function filter_media_pages()
{
if(is_page($page = 'add-new-propety.php'))
add_filter('wp_handle_upload_prefilter', 'block_small_images_upload');
}
function block_small_images_upload($file)
{
// Mime type with dimensions, check to exit earlier
$mimes = array('image/jpeg', 'image/png', 'image/gif');
if(!in_array($file['type'], $mimes))
return $file;
//Adjust dimensions
$img = getimagesize($file['tmp_name']);
$minimum = array('width' => 1170, 'height' => 786);
if ($img[0] < $minimum['width'])
$file['error'] =
'Image too small. Minimum width is '
. $minimum['width']
. 'px. Uploaded image width is '
. $img[0] . 'px';
elseif ($img[1] < $minimum['height'])
$file['error'] =
'Image too small. Minimum height is '
. $minimum['height']
. 'px. Uploaded image height is '
. $img[1] . 'px';
return $file;
}
我试过标题,slu,,ID,当前值。似乎忽略IF()语句并执行。 –
似乎没有名为“wp_handle_upload_prefilter”的动作,只有一个过滤器? – klumme
有效点,回到制图板。谢谢 –