bbp_hide_forum

Mark the forum as hidden.

Description

bbp_hide_forum( (int) $forum_id = 0, (string) $current_visibility = '' ); 

Parameters (2)

0. $forum_id — Optional. (int)
Forum id
1. $current_visibility — Optional. (string) => ''
The current visibility.

Usage

  1. if ( !function_exists( 'bbp_hide_forum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // Optional. Forum id 
  5. $forum_id = -1; 
  6.  
  7. // The current visibility. 
  8. $current_visibility = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_hide_forum($forum_id, $current_visibility); 
  12.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_hide_forum( $forum_id = 0, $current_visibility = '' ) { 
  2.  
  3. $forum_id = bbp_get_forum_id( $forum_id ); 
  4.  
  5. do_action( 'bbp_hide_forum', $forum_id ); 
  6.  
  7. // Only run queries if visibility is changing 
  8. if ( bbp_get_hidden_status_id() !== $current_visibility ) { 
  9.  
  10. // Get private forums 
  11. $private = bbp_get_private_forum_ids(); 
  12.  
  13. // Find this forum in the array 
  14. if ( in_array( $forum_id, $private ) ) { 
  15.  
  16. $offset = array_search( $forum_id, $private ); 
  17.  
  18. // Splice around it 
  19. array_splice( $private, $offset, 1 ); 
  20.  
  21. // Update private forums minus this one 
  22. update_option( '_bbp_private_forums', array_unique( array_filter( array_values( $private ) ) ) ); 
  23.  
  24. // Add to '_bbp_hidden_forums' site option 
  25. $hidden = bbp_get_hidden_forum_ids(); 
  26. $hidden[] = $forum_id; 
  27. update_option( '_bbp_hidden_forums', array_unique( array_filter( array_values( $hidden ) ) ) ); 
  28.  
  29. // Update forums visibility setting 
  30. global $wpdb; 
  31. $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) ); 
  32. wp_transition_post_status( bbp_get_hidden_status_id(), $current_visibility, get_post( $forum_id ) ); 
  33. bbp_clean_post_cache( $forum_id ); 
  34.  
  35. do_action( 'bbp_hid_forum', $forum_id ); 
  36.  
  37. return $forum_id;