bp_forums_directory_forums_setup

Load the Forums directory.

Description

bp_forums_directory_forums_setup(); 

Usage

  1. if ( !function_exists( 'bp_forums_directory_forums_setup' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bp-forums-screens.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_forums_directory_forums_setup(); 
  7.  

Defined (1)

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

/bp-forums/bp-forums-screens.php  
  1. function bp_forums_directory_forums_setup() { 
  2.  
  3. // Get BuddyPress once. 
  4. $bp =buddypress); 
  5.  
  6. if ( bp_is_forums_component() && ( !bp_current_action() || ( 'tag' == bp_current_action() && bp_action_variables() ) ) && !bp_current_item() ) { 
  7. if ( !bp_forums_has_directory() ) 
  8. return false; 
  9.  
  10. if ( !bp_forums_is_installed_correctly() ) { 
  11. bp_core_add_message( __( 'The forums component has not been set up yet.', buddypress ), error ); 
  12.  
  13. bp_update_is_directory( true, 'forums' ); 
  14.  
  15. /** 
  16. * Fires early in the initialization of bbPress-based areas of BuddyPress. 
  17. * @since 1.1.0 
  18. */ 
  19.  
  20. // Check to see if the user has posted a new topic from the forums page. 
  21. if ( isset( $_POST['submit_topic'] ) && bp_is_active( 'forums' ) ) { 
  22. check_admin_referer( 'bp_forums_new_topic' ); 
  23.  
  24. $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ); 
  25. if ( !empty( $bp->groups->current_group->id ) ) { 
  26. // Auto join this user if they are not yet a member of this group. 
  27. if ( !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) 
  28. groups_join_group( $bp->groups->current_group->id ); 
  29.  
  30. $error_message = ''; 
  31.  
  32. $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 
  33. if ( !empty( $forum_id ) ) { 
  34. if ( empty( $_POST['topic_title'] ) ) 
  35. $error_message = __( 'Please provide a title for your forum topic.', buddypress ); 
  36. else if ( empty( $_POST['topic_text'] ) ) 
  37. $error_message = __( 'Forum posts cannot be empty. Please enter some text.', buddypress ); 
  38.  
  39. if ( $error_message ) { 
  40. bp_core_add_message( $error_message, error ); 
  41. $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum'; 
  42. } else { 
  43. if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) { 
  44. bp_core_add_message( __( 'There was anerrorwhen creating the topic', buddypress), error ); 
  45. $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum'; 
  46. } else { 
  47. bp_core_add_message( __( 'The topic was created successfully', buddypress) ); 
  48. $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/'; 
  49.  
  50. bp_core_redirect( $redirect ); 
  51.  
  52. } else { 
  53. bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', buddypress ), error ); 
  54.  
  55. } else { 
  56. bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', buddypress ), error ); 
  57.  
  58. /** 
  59. * Fires right before the loading of the forums directory screen template file. 
  60. * @since 1.1.0 
  61. */ 
  62.  
  63. /** 
  64. * Filters the template to load for the forums directory screen. 
  65. * @since 1.1.0 
  66. * @param string $template Path to the forums template to load. 
  67. */