bb_merge_tags

The BuddyPress bb merge tags function.

Description

bb_merge_tags( $old_id, $new_id ); 

Parameters (2)

0. $old_id
The old id.
1. $new_id
The new id.

Usage

  1. if ( !function_exists( 'bb_merge_tags' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The old id. 
  5. $old_id = null; 
  6.  
  7. // The new id. 
  8. $new_id = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_merge_tags($old_id, $new_id); 
  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_merge_tags( $old_id, $new_id ) { 
  2. if ( !bb_current_user_can( 'manage_tags' ) ) { 
  3. return false; 
  4.  
  5. $old_id = (int) $old_id; 
  6. $new_id = (int) $new_id; 
  7.  
  8. if ( $old_id == $new_id ) { 
  9. return false; 
  10.  
  11. do_action( 'bb_pre_merge_tags', $old_id, $new_id ); 
  12.  
  13. // Get all topics tagged with old tag 
  14. $old_topics = bb_get_tagged_topic_ids( $old_id ); 
  15.  
  16. // Get all toics tagged with new tag 
  17. $new_topics = bb_get_tagged_topic_ids( $new_id ); 
  18.  
  19. // Get intersection of those topics 
  20. $both_topics = array_intersect( $old_topics, $new_topics ); 
  21.  
  22. // Discard the intersection from the old tags topics 
  23. $old_topics = array_diff( $old_topics, $both_topics ); 
  24.  
  25. // Add the remainder of the old tag topics to the new tag 
  26. if ( count( $old_topics ) ) { 
  27. $new_tag = bb_get_tag( $new_id ); 
  28. foreach ( $old_topics as $old_topic ) { 
  29. bb_add_topic_tag( $old_topic, $new_tag->slug ); 
  30.  
  31. // Destroy the old tag 
  32. $old_tag = bb_destroy_tag( $old_id ); 
  33.  
  34. return array( 'destroyed' => $old_tag, 'old_count' => count( $old_topics ), 'diff_count' => count( $both_topics ) );