bb_destroy_tag

Bb_destroy_tag() - Completely removes a bb_topic_tag.

Description

bb_destroy_tag( (int) $tt_id, (bool) $recount_topics = true ); 

Parameters (2)

0. $tt_id (int)
The TT_ID of the tag to destroy
1. $recount_topics — Optional. (bool) => true
The recount topics.

Usage

  1. if ( !function_exists( 'bb_destroy_tag' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The TT_ID of the tag to destroy 
  5. $tt_id = -1; 
  6.  
  7. // The recount topics. 
  8. $recount_topics = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_destroy_tag($tt_id, $recount_topics); 
  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_destroy_tag( $tt_id, $recount_topics = true ) { 
  2. global $wp_taxonomy_object; 
  3.  
  4. $tt_id = (int) $tt_id; 
  5.  
  6. if ( !$tag = bb_get_tag( $tt_id ) ) 
  7. return false; 
  8.  
  9. if ( is_wp_error($tag) ) 
  10. return false; 
  11.  
  12. $topic_ids = bb_get_tagged_topic_ids( $tag->term_id ); 
  13.  
  14. $return = $wp_taxonomy_object->delete_term( $tag->term_id, 'bb_topic_tag' ); 
  15.  
  16. if ( is_wp_error($return) ) 
  17. return false; 
  18.  
  19. if ( !is_wp_error( $topic_ids ) && is_array( $topic_ids ) ) { 
  20. global $bbdb; 
  21. $bbdb->query( 
  22. "UPDATE $bbdb->topics SET tag_count = tag_count - 1 WHERE topic_id IN (" . join( ', ', $topic_ids ) . ")" 
  23. ); 
  24. foreach ( $topic_ids as $topic_id ) { 
  25. wp_cache_delete( $topic_id, 'bb_topic' ); 
  26.  
  27. return $return;