bb_get_tag

Bb_get_tag() - Returns the specified tag.

Description

(object) bb_get_tag( (mixed) $id, (int) $user_id = 0, (int) $topic_id = 0 ); 

If $user_id and $topic_id are passed, will check to see if that tag exists on that topic by that user.

Returns (object)

Term object (back-compat)

Parameters (3)

0. $id (mixed)
The TT_ID or tag name of the desired tag
1. $user_id — Optional. (int)
The user id.
2. $topic_id — Optional. (int)
The topic id.

Usage

  1. if ( !function_exists( 'bb_get_tag' ) ) { 
  2. require_once '/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The TT_ID or tag name of the desired tag 
  5. $id = null; 
  6.  
  7. // The user id. 
  8. $user_id = -1; 
  9.  
  10. // The topic id. 
  11. $topic_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_get_tag($id, $user_id, $topic_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php  
  1. function bb_get_tag( $id, $user_id = 0, $topic_id = 0 ) { 
  2. global $wp_taxonomy_object; 
  3. $user_id = (int) $user_id; 
  4. $topic_id = (int) $topic_id; 
  5.  
  6. $term = false; 
  7. if ( is_integer( $id ) ) { 
  8. $tt_id = (int) $id; 
  9. } else { 
  10. if ( !$term = $wp_taxonomy_object->get_term_by( 'slug', $id, 'bb_topic_tag' ) ) 
  11. return false; 
  12. $tt_id = (int) $term->term_taxonomy_id; 
  13.  
  14. if ( $user_id && $topic_id ) { 
  15. $args = array( 'user_id' => $user_id, 'fields' => 'tt_ids' ); 
  16. $cache_id = $topic_id . serialize( $args ); 
  17.  
  18. $tt_ids = wp_cache_get( $cache_id, 'bb_topic_tag_terms' ); 
  19. if ( empty( $tt_ids ) ) { 
  20. $tt_ids = $wp_taxonomy_object->get_object_terms( $topic_id, 'bb_topic_tag', $args ); 
  21. wp_cache_set( $cache_id, $tt_ids, 'bb_topic_tag_terms' ); 
  22. if ( !in_array( $tt_id, $tt_ids ) ) 
  23. return false; 
  24.  
  25. if ( !$term ) 
  26. $term = $wp_taxonomy_object->get_term_by( 'tt_id', $tt_id, 'bb_topic_tag' ); 
  27.  
  28. _bb_make_tag_compat( $term ); 
  29.  
  30. return $term;