bpbbpst_handle_moving_topic

Handles topic moves from a forum to another.

Description

bpbbpst_handle_moving_topic( (int) $topic_id = 0, (int) $forum_id = 0 ); 

Parameters (2)

0. $topic_id — Optional. (int)
The topic id.
1. $forum_id — Optional. (int)
The new forum id

Usage

  1. if ( !function_exists( 'bpbbpst_handle_moving_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddy-bbpress-support-topic/includes/functions.php'; 
  3.  
  4. // The topic id. 
  5. $topic_id = -1; 
  6.  
  7. // the new forum id 
  8. $forum_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bpbbpst_handle_moving_topic($topic_id, $forum_id); 
  12.  

Defined (1)

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

/includes/functions.php  
  1. function bpbbpst_handle_moving_topic( $topic_id = 0, $forum_id = 0 ) { 
  2. if ( empty( $topic_id ) || empty( $forum_id ) ) { 
  3. return; 
  4.  
  5. $old_forum_id = bbp_get_topic_forum_id( $topic_id ); 
  6.  
  7. //if old is new, then do nothing ! 
  8. if ( $old_forum_id == $forum_id ) { 
  9. return; 
  10.  
  11. $old_forum_support_feature = bpbbpst_get_forum_support_setting( $old_forum_id ); 
  12. $new_forum_support_feature = bpbbpst_get_forum_support_setting( $forum_id ); 
  13.  
  14. //if old has same support feature than new, then do nothing 
  15. if ( $old_forum_support_feature == $new_forum_support_feature ) { 
  16. return; 
  17.  
  18. // at this point it means old had a support feature and new one no 
  19. if ( $new_forum_support_feature == 3 ) { 
  20. // delete_post_meta will be handled by bpbbpst_bbpress_edit_support_type 
  21. if ( isset( $_POST['_bp_bbp_st_is_support'] ) ) { 
  22. unset( $_POST['_bp_bbp_st_is_support'] ); 
  23.  
  24. if ( isset( $_POST['_support_status'] ) ) { 
  25. unset( $_POST['_support_status'] ); 
  26.  
  27. delete_post_meta( $topic_id, '_bpbbpst_support_topic' ); 
  28.  
  29. } else { 
  30. $meta = get_post_meta( $topic_id, '_bpbbpst_support_topic', true ); 
  31.  
  32. if ( $old_forum_support_feature == 3 ) { 
  33. // in this case nonce is not set 
  34. if ( $new_forum_support_feature == 2 ) { 
  35. $meta = 1; 
  36.  
  37. update_post_meta( $topic_id, '_bpbbpst_support_topic', $meta ); 
  38. } else { 
  39. if ( empty( $_POST['_bp_bbp_st_is_support'] ) && $new_forum_support_feature == 2 ) { 
  40. $_POST['_bp_bbp_st_is_support'] = 'support'; 
  41.  
  42. if ( ! empty( $_POST['_bp_bbp_st_is_support'] ) && empty( $meta ) && $new_forum_support_feature == 1 ) { 
  43. unset( $_POST['_bp_bbp_st_is_support'] ); 
  44.  
  45. if ( empty( $_POST['_support_status'] ) && empty( $meta ) && $new_forum_support_feature == 2 ) { 
  46. $_POST['_support_status'] = 1; 
  47.