bbp_save_forum_extras

Handle the saving of core forum metadata (Status, Visibility, and Type).

Description

bbp_save_forum_extras( (int) $forum_id = 0 ); 

Parameters (1)

0. $forum_id — Optional. (int)
The forum id.

Usage

  1. if ( !function_exists( 'bbp_save_forum_extras' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // The forum id. 
  5. $forum_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_save_forum_extras($forum_id); 
  9.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_save_forum_extras( $forum_id = 0 ) { 
  2.  
  3. // Validate the forum ID 
  4. $forum_id = bbp_get_forum_id( $forum_id ); 
  5.  
  6. // Bail if forum ID is empty 
  7. if ( empty( $forum_id ) || ! bbp_is_forum( $forum_id ) ) 
  8. return; 
  9.  
  10. /** Forum Status ******************************************************/ 
  11.  
  12. if ( !empty( $_POST['bbp_forum_status'] ) && in_array( $_POST['bbp_forum_status'], array( 'open', 'closed' ) ) ) { 
  13. if ( 'closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed( $forum_id, false ) ) { 
  14. bbp_close_forum( $forum_id ); 
  15. } elseif ( 'open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed( $forum_id, false ) ) { 
  16. bbp_open_forum( $forum_id ); 
  17.  
  18. /** Forum Type ********************************************************/ 
  19.  
  20. if ( !empty( $_POST['bbp_forum_type'] ) && in_array( $_POST['bbp_forum_type'], array( 'forum', 'category' ) ) ) { 
  21. if ( 'category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category( $forum_id ) ) { 
  22. bbp_categorize_forum( $forum_id ); 
  23. } elseif ( 'forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category( $forum_id ) ) { 
  24. bbp_normalize_forum( $forum_id ); 
  25.  
  26. /** Forum Visibility **************************************************/ 
  27.  
  28. if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ) ) ) { 
  29.  
  30. // Get forums current visibility 
  31. $visibility = bbp_get_forum_visibility( $forum_id ); 
  32.  
  33. // What is the new forum visibility setting? 
  34. switch ( $_POST['bbp_forum_visibility'] ) { 
  35.  
  36. // Hidden 
  37. bbp_hide_forum( $forum_id, $visibility ); 
  38. break; 
  39.  
  40. // Private 
  41. bbp_privatize_forum( $forum_id, $visibility ); 
  42. break; 
  43.  
  44. // Publish (default) 
  45. default : 
  46. bbp_publicize_forum( $forum_id, $visibility ); 
  47. break;