bb_add_topic_tags

Bb_add_topic_tag() - Adds a multiple tags to a topic.

Description

(array|bool) bb_add_topic_tags( (int) $topic_id, (array|string) $tags ); 

Returns (array|bool)

The TT_IDs of the new bb_topic_tags or false on failure

Parameters (2)

0. $topic_id (int)
The topic id.
1. $tags (array|string)
The (unsanitized) full names of the tag to be added. CSV or array.

Usage

  1. if ( !function_exists( 'bb_add_topic_tags' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The topic id. 
  5. $topic_id = -1; 
  6.  
  7. // The (unsanitized) full names of the tag to be added. CSV or array. 
  8. $tags = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_add_topic_tags($topic_id, $tags); 
  12.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php  
  1. function bb_add_topic_tags( $topic_id, $tags ) { 
  2. global $wp_taxonomy_object; 
  3. $topic_id = (int) $topic_id; 
  4. if ( !$topic = get_topic( $topic_id ) ) 
  5. return false; 
  6. if ( !bb_current_user_can( 'add_tag_to', $topic_id ) ) 
  7. return false; 
  8.  
  9. $user_id = bb_get_current_user_info( 'id' ); 
  10.  
  11. $tags = apply_filters( 'bb_add_topic_tags', $tags, $topic_id ); 
  12.  
  13. if ( !is_array( $tags ) ) 
  14. $tags = explode(', ', (string) $tags); 
  15.  
  16. $tt_ids = $wp_taxonomy_object->set_object_terms( $topic->topic_id, $tags, 'bb_topic_tag', array( 'append' => true, 'user_id' => $user_id ) ); 
  17.  
  18. if ( is_array($tt_ids) ) { 
  19. global $bbdb; 
  20. $bbdb->query( $bbdb->prepare( 
  21. "UPDATE $bbdb->topics SET tag_count = tag_count + %d WHERE topic_id = %d", count( $tt_ids ), $topic->topic_id 
  22. ) ); 
  23. wp_cache_delete( $topic->topic_id, 'bb_topic' ); 
  24. foreach ( $tt_ids as $tt_id ) 
  25. do_action('bb_tag_added', $tt_id, $user_id, $topic_id); 
  26. return $tt_ids; 
  27. return false;