Create Comment Programmatically

This code snippet is useful if you want to write some custom Import script.

$comment = (object) array(
'nid' => $parentthread,
'cid' => 0,
'pid' => 0,
'uid' => $userid,
'is_anonymous' => 0,
'created' => $datenew,
'changed' => $datenew,
'status' => $pub,
'subject' => $subject,
'language' => LANGUAGE_NONE,
'comment_body' => array(
  LANGUAGE_NONE => array(
0 => array (
  'value' => $body,
  'format' => 'full_html'
)
  )
),
  );
  comment_submit($comment);
  comment_save($comment);

Share this post

Leave a comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.