$body = '[quote]' . XenForo_Helper_String::autoLinkBbCode(XenForo_Html_Renderer_BbCode::renderFromHtml(nl2br($content))) . "[/quote]";
Could the content be trimmed prior to the above line ? I tried something like that before this line and it failed to write the thread.
Update: In case someone trips over this post. The answer was too obvious. I was missing the XenForo_Helper_String ...
Here is the working code:
$body = XenForo_Helper_String::wholeWordTrim($body, 500);