bb_new_forum

The BuddyPress bb new forum function.

Description

bb_new_forum( $args ); 

Parameters (1)

0. $args
The args.

Usage

  1. if ( !function_exists( 'bb_new_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_new_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_new_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_name' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => false, 'forum_is_category' => 0 ); 
  8. $args = wp_parse_args( $args, $defaults ); 
  9. if ( 1 < func_num_args() ) : // For back compat 
  10. $args['forum_name'] = $func_args[0]; 
  11. $args['forum_desc'] = $func_args[1]; 
  12. $args['forum_order'] = 2 < func_num_args() ? $func_args[2] : 0; 
  13. endif; 
  14.  
  15. extract($args, EXTR_SKIP); 
  16.  
  17. if ( !is_numeric($forum_order) ) 
  18. $forum_order = (int) $bbdb->get_var("SELECT MAX(forum_order) FROM $bbdb->forums") + 1; 
  19.  
  20. $forum_order = (int) $forum_order; 
  21. $forum_parent = (int) $forum_parent; 
  22. $forum_is_category = (int) $forum_is_category; 
  23.  
  24. $forum_name = apply_filters( 'bb_pre_forum_name', stripslashes( wp_specialchars_decode( $forum_name, ENT_QUOTES ) ) ); 
  25. $forum_desc = apply_filters( 'bb_pre_forum_desc', stripslashes($forum_desc) ); 
  26.  
  27. if ( strlen($forum_name) < 1 ) 
  28. return false; 
  29.  
  30. $forum_sql = "SELECT forum_slug FROM $bbdb->forums WHERE forum_slug = %s"; 
  31.  
  32. $forum_slug = $_forum_slug = bb_slug_sanitize($forum_name); 
  33. if ( strlen($_forum_slug) < 1 ) 
  34. return false; 
  35.  
  36. while ( is_numeric($forum_slug) || $existing_slug = $bbdb->get_var( $bbdb->prepare( $forum_sql, $forum_slug ) ) ) 
  37. $forum_slug = bb_slug_increment($_forum_slug, $existing_slug); 
  38.  
  39. $bbdb->insert( $bbdb->forums, compact( 'forum_name', 'forum_slug', 'forum_desc', 'forum_parent', 'forum_order' ) ); 
  40. $forum_id = $bbdb->insert_id; 
  41. if ($forum_id && $forum_is_category) 
  42. bb_update_forummeta($forum_id, 'forum_is_category', $forum_is_category); 
  43.  
  44. return $forum_id;