function upload_limit( $file ) {
if ( $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : false ) ) {
$count_images = get_attached_media( 'image', $post_id );
if ( count( $count_images ) > 50 ) {
$file['error'] = 'Больше 50 изображений нельзя!';
}
}
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'upload_limit' );