bb_remove_topic_tag

Bb_remove_topic_tag() - Removes a single bb_topic_tag by a user from a topic.

Description

(array|false) bb_remove_topic_tag( (int) $tt_id, (int) $user_id, (int) $topic_id ); 

Returns (array|false)

The TT_IDs of the users bb_topic_tags on that topic or false on failure

Parameters (3)

0. $tt_id (int)
The TT_ID of the bb_topic_tag to be removed
1. $user_id (int)
The user id.
2. $topic_id (int)
The topic id.

Usage

  1. if ( !function_exists( 'bb_remove_topic_tag' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The TT_ID of the bb_topic_tag to be removed 
  5. $tt_id = -1; 
  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_remove_topic_tag($tt_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_remove_topic_tag( $tt_id, $user_id, $topic_id ) { 
  2. global $wp_taxonomy_object; 
  3. $tt_id = (int) $tt_id; 
  4. $user_id = (int) $user_id; 
  5. $topic_id = (int) $topic_id; 
  6. if ( !$topic = get_topic( $topic_id ) ) 
  7. return false; 
  8. if ( !bb_current_user_can( 'edit_tag_by_on', $user_id, $topic_id ) ) 
  9. return false; 
  10.  
  11. $_tag = bb_get_tag( $tt_id ); 
  12.  
  13. do_action('bb_pre_tag_removed', $tt_id, $user_id, $topic_id); 
  14. $currents = $wp_taxonomy_object->get_object_terms( $topic_id, 'bb_topic_tag', array( 'user_id' => $user_id, 'fields' => 'all' ) ); 
  15. if ( !is_array( $currents ) ) 
  16. return false; 
  17.  
  18. $found_tag_to_remove = false; 
  19. $current_tag_term_ids = array(); 
  20. foreach ( $currents as $current ) { 
  21. if ( $current->term_taxonomy_id == $tt_id ) { 
  22. $found_tag_to_remove = true; 
  23. continue; 
  24. $current_tag_term_ids[] = $current->term_id; 
  25.  
  26. if ( !$found_tag_to_remove ) 
  27. return false; 
  28.  
  29. $current_tag_term_ids = array_map( 'intval', $current_tag_term_ids ); 
  30.  
  31. $tt_ids = $wp_taxonomy_object->set_object_terms( $topic_id, array_values($current_tag_term_ids), 'bb_topic_tag', array( 'user_id' => $user_id ) ); 
  32. if ( is_array( $tt_ids ) ) { 
  33. global $bbdb; 
  34. $bbdb->query( $bbdb->prepare( 
  35. "UPDATE $bbdb->topics SET tag_count = %d WHERE topic_id = %d", count( $tt_ids ), $topic_id 
  36. ) ); 
  37. wp_cache_delete( $topic_id, 'bb_topic' ); 
  38.  
  39. // Count is updated at set_object_terms() 
  40. if ( $_tag && 2 > $_tag->tag_count ) { 
  41. bb_destroy_tag( $_tag->term_taxonomy_id ); 
  42. } elseif ( is_wp_error( $tt_ids ) ) { 
  43. return false; 
  44. return $tt_ids;