要求作者在发布帖子之前选择最小图像尺寸宽度,至少500x500像素。
我使用设置错误来向function.php添加代码,但无法正常工作
function display_size_error_message($messages)
{
global $post;
$types = array( 'post');
if ( $post && in_array( $post->post_type, $types, true ) ) {
$images = array();
foreach ( $matches[1] as $match ) {
$attachment_id = attachment_url_to_postid( $match );
if ( $attachment_id ) {
$path = get_attached_file( $attachment_id );
list( $width, $height ) = getimagesize( $path );
if ( $width < 500 && $height < 500 ) {
$error_message = 'Imaze size minimum 500x500px';
add_settings_error('post_size_error', '', $error_message, 'error');
settings_errors( 'post_size_error' );
$post->post_status = 'draft';
wp_update_post($post);
return;
}
}
}
}
return $messages;
}
add_action('post_updated_messages', 'display_size_error_message');