function node_unpublish_by_keyword_action

7.x node.module node_unpublish_by_keyword_action($node, $context)
6.x node.module node_unpublish_by_keyword_action($node, $context)

Unpublishes a node containing certain keywords.

Parameters

$node: A node object to modify.

$context: Array with the following elements:

  • 'keywords': Array of keywords. If any keyword is present in the rendered node, the node's status flag is set to unpublished.

Related topics

1 string reference to 'node_unpublish_by_keyword_action'
node_action_info in drupal-7.x/modules/node/node.module
Implements hook_action_info().

File

drupal-7.x/modules/node/node.module, line 4075
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_unpublish_by_keyword_action($node, $context) {
  foreach ($context['keywords'] as $keyword) {
    $elements = node_view(clone $node);
    if (strpos(drupal_render($elements), $keyword) !== FALSE || strpos($node->title, $keyword) !== FALSE) {
      $node->status = NODE_NOT_PUBLISHED;
      watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title));
      break;
    }
  }
}