Add comment programmatically in Drupal 7

Posted by volocuga on Stack Overflow See other posts from Stack Overflow or by volocuga
Published on 2011-11-24T01:34:53Z Indexed on 2011/11/24 1:51 UTC
Read the original article Hit count: 850

Filed under:
|

trying to create a comment in own module.

$comment = new stdClass();
$comment->nid = 555; // Node Id the comment will attached to
$comment->cid = 0;
$comment->pid = 0;
$comment->uid = 1;
$comment->mail = '[email protected]';
$comment->name = 'admin';
$comment->is_anonymous = 0;
$comment->homepage = '';
$comment->status = COMMENT_PUBLISHED;
$comment->language = LANGUAGE_NONE;
$comment->subject = 'Comment subject'; 
$comment->comment_body[$comment->language][0]['value'] = 'Comment body text';
$comment->comment_body[$comment->language][0]['format'] = 'filtered_html'; 
comment_submit($comment);
comment_save($comment);

The code causes the following error:

Fatal error: Call to undefined function node_load() in BLA/BLA/comment.module on line 1455

node_load() function is in node module which, of course, enabled.

How to fix it?

Thanks!

© Stack Overflow or respective owner

Related posts about drupal

Related posts about drupal-7