bb_update_forum

The BuddyPress bb update forum function.

Description

bb_update_forum( $args ); 

Parameters (1)

0. $args
The args.

Usage

  1. if ( !function_exists( 'bb_update_forum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php'; 
  3.  
  4. // The args. 
  5. $args = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_update_forum($args); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php  
  1. function bb_update_forum( $args ) { 
  2. global $bbdb; 
  3. if ( !bb_current_user_can( 'manage_forums' ) ) 
  4. return false; 
  5.  
  6. $func_args = func_get_args(); 
  7. $defaults = array( 'forum_id' => 0, 'forum_name' => '', 'forum_slug' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => 0, 'forum_is_category' => 0 ); 
  8. $fields = array( 'forum_name', 'forum_desc', 'forum_parent', 'forum_order' ); 
  9. $args = wp_parse_args( $args, $defaults ); 
  10. if ( 1 < func_num_args() ) : // For back compat 
  11. $args['forum_id'] = $func_args[0]; 
  12. $args['forum_name'] = $func_args[1]; 
  13. $args['forum_desc'] = 2 < func_num_args() ? $func_args[2] : ''; 
  14. $args['forum_order'] = 3 < func_num_args() && is_numeric($func_args[3]) ? $func_args[3] : 0; 
  15. endif; 
  16.  
  17. extract($args, EXTR_SKIP); 
  18.  
  19. if ( !$forum_id = (int) $forum_id ) 
  20. return false; 
  21. if ( !$forum = bb_get_forum( $forum_id ) ) 
  22. return false; 
  23. $forum_order = (int) $forum_order; 
  24. $forum_parent = (int) $forum_parent; 
  25. $forum_is_category = (int) $forum_is_category; 
  26.  
  27. $forum_name = apply_filters( 'bb_pre_forum_name', stripslashes( wp_specialchars_decode( $forum_name, ENT_QUOTES ) ), $forum_id ); 
  28. $forum_desc = apply_filters( 'bb_pre_forum_desc', stripslashes($forum_desc), $forum_id ); 
  29.  
  30. if ( strlen($forum_name) < 1 ) 
  31. return false; 
  32.  
  33. // Slug is not changing, don't update it 
  34. if ( !$forum_slug || $forum_slug == $forum->forum_slug ) { 
  35. // [sic] 
  36. } else { 
  37. $forum_slug = $_forum_slug = bb_slug_sanitize($forum_slug); 
  38. if ( strlen($_forum_slug) < 1 ) 
  39. return false; 
  40.  
  41. $forum_sql = "SELECT forum_slug FROM $bbdb->forums WHERE forum_slug = %s"; 
  42.  
  43. while ( is_numeric($forum_slug) || $existing_slug = $bbdb->get_var( $bbdb->prepare( $forum_sql, $forum_slug ) ) ) 
  44. $forum_slug = bb_slug_increment($_forum_slug, $existing_slug); 
  45.  
  46. $fields[] = 'forum_slug'; 
  47.  
  48. wp_cache_delete( $forum_id, 'bb_forum' ); 
  49.  
  50. $update_result = $bbdb->update( $bbdb->forums, compact( $fields ), compact( 'forum_id' ) ); 
  51.  
  52. if ($forum_is_category) 
  53. bb_update_forummeta($forum_id, 'forum_is_category', $forum_is_category); 
  54. else 
  55. bb_delete_forummeta($forum_id, 'forum_is_category'); 
  56.  
  57. return $update_result;