Same name and namespace in other branches
  1. 6.x modules/comment/comment.module \comment_unpublish_by_keyword_action()

Unpublishes a comment if it contains certain keywords.

Parameters

object $comment: Comment object to modify.

array $context: Array with components:

  • 'keywords': Keywords to look for. If the comment contains at least one of the keywords, it is unpublished.

See also

comment_unpublish_by_keyword_action_form()

comment_unpublish_by_keyword_action_submit()

Related topics

1 call to comment_unpublish_by_keyword_action()
CommentActionsTestCase::testCommentUnpublishByKeyword in modules/comment/comment.test
Tests the unpublish comment by keyword action.
3 string references to 'comment_unpublish_by_keyword_action'
CommentActionsTestCase::testCommentUnpublishByKeyword in modules/comment/comment.test
Tests the unpublish comment by keyword action.
comment_action_info in modules/comment/comment.module
Implements hook_action_info().
hook_action_info in modules/system/system.api.php
Declares information about actions.

File

modules/comment/comment.module, line 2635
Enables users to comment on published content.

Code

function comment_unpublish_by_keyword_action($comment, $context) {
  $node = node_load($comment->nid);
  $build = comment_view($comment, $node);
  $text = drupal_render($build);
  foreach ($context['keywords'] as $keyword) {
    if (strpos($text, $keyword) !== FALSE) {
      $comment->status = COMMENT_NOT_PUBLISHED;
      comment_save($comment);
      watchdog('action', 'Unpublished comment %subject.', array(
        '%subject' => $comment->subject,
      ));
      break;
    }
  }
}