bb_rename_tag

The BuddyPress bb rename tag function.

Description

bb_rename_tag( $tag_id, (string) $tag_name ); 

Parameters (2)

0. $tag_id
The tag id.
1. $tag_name (string)
The tag name.

Usage

  1. if ( !function_exists( 'bb_rename_tag' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The tag id. 
  5. $tag_id = null; 
  6.  
  7. // The tag name. 
  8. $tag_name = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_rename_tag($tag_id, $tag_name); 
  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_rename_tag( $tag_id, $tag_name ) { 
  2. if ( !bb_current_user_can( 'manage_tags' ) ) { 
  3. return false; 
  4.  
  5. $tag_id = (int) $tag_id; 
  6. $raw_tag = bb_trim_for_db( $tag_name, 50 ); 
  7. $tag_name = tag_sanitize( $tag_name );  
  8.  
  9. if ( empty( $tag_name ) ) { 
  10. return false; 
  11.  
  12. if ( $existing_tag = bb_get_tag( $tag_name ) ) { 
  13. if ( $existing_tag->term_id !== $tag_id ) { 
  14. return false; 
  15.  
  16. if ( !$old_tag = bb_get_tag( $tag_id ) ) { 
  17. return false; 
  18.  
  19. global $wp_taxonomy_object; 
  20. $ret = $wp_taxonomy_object->update_term( $tag_id, 'bb_topic_tag', array( 'name' => $raw_tag, 'slug' => $tag_name ) ); 
  21.  
  22. if ( $ret && !is_wp_error( $ret ) ) { 
  23. do_action( 'bb_tag_renamed', $tag_id, $old_tag->raw_tag, $raw_tag ); 
  24. return bb_get_tag( $tag_id ); 
  25. return false;