You are here

function _hashtags_add_term in Hashtags 7

Check if term exists with passed term name and if not - add new term to database

Parameters

string $name term name:

int $vid vid:

Return value

int tid

2 calls to _hashtags_add_term()
hashtags_comment_presave in ./hashtags.module
Implements hook_comment_presave().
hashtags_entity_presave in ./hashtags.module
Implementation of hook_entity_presave().

File

./hashtags.module, line 438

Code

function _hashtags_add_term($name, $vid) {
  $term = taxonomy_term_load_multiple(array(), array(
    'name' => trim($name),
    'vid' => $vid,
  ));

  // move up array to one level
  $term = array_shift($term);
  if (empty($term)) {
    $term = new stdClass();
    $term->name = $name;
    $term->vid = $vid;
    taxonomy_term_save($term);
  }
  return isset($term->tid) ? $term->tid : '';
}