bbp_edit_forum_handler

Handles the front end edit forum submission.

Description

bbp_edit_forum_handler( (string) $action = '' ); 

Parameters (1)

0. $action — Optional. (string) => ''
The requested action to compare this function to

Usage

  1. if ( !function_exists( 'bbp_edit_forum_handler' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // The requested action to compare this function to 
  5. $action = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_edit_forum_handler($action); 
  9.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_edit_forum_handler( $action = '' ) { 
  2.  
  3. // Bail if action is not bbp-edit-forum 
  4. if ( 'bbp-edit-forum' !== $action ) 
  5. return; 
  6.  
  7. // Define local variable(s) 
  8. $anonymous_data = array(); 
  9. $forum = $forum_id = $forum_parent_id = 0; 
  10. $forum_title = $forum_content = $forum_edit_reason = ''; 
  11.  
  12. /** Forum *****************************************************************/ 
  13.  
  14. // Forum id was not passed 
  15. if ( empty( $_POST['bbp_forum_id'] ) ) { 
  16. bbp_add_error( 'bbp_edit_forum_id', __( '<strong>ERROR</strong>: Forum ID not found.', bbpress ) ); 
  17. return; 
  18.  
  19. // Forum id was passed 
  20. } elseif ( is_numeric( $_POST['bbp_forum_id'] ) ) { 
  21. $forum_id = (int) $_POST['bbp_forum_id']; 
  22. $forum = bbp_get_forum( $forum_id ); 
  23.  
  24. // Nonce check 
  25. if ( ! bbp_verify_nonce_request( 'bbp-edit-forum_' . $forum_id ) ) { 
  26. bbp_add_error( 'bbp_edit_forum_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', bbpress ) ); 
  27. return; 
  28.  
  29. // Forum does not exist 
  30. } elseif ( empty( $forum ) ) { 
  31. bbp_add_error( 'bbp_edit_forum_not_found', __( '<strong>ERROR</strong>: The forum you want to edit was not found.', bbpress ) ); 
  32. return; 
  33.  
  34. // User cannot edit this forum 
  35. } elseif ( !current_user_can( 'edit_forum', $forum_id ) ) { 
  36. bbp_add_error( 'bbp_edit_forum_permissions', __( '<strong>ERROR</strong>: You do not have permission to edit that forum.', bbpress ) ); 
  37. return; 
  38.  
  39. // Remove kses filters from title and content for capable users and if the nonce is verified 
  40. if ( current_user_can( 'unfiltered_html' ) && !empty( $_POST['_bbp_unfiltered_html_forum'] ) && ( wp_create_nonce( 'bbp-unfiltered-html-forum_' . $forum_id ) === $_POST['_bbp_unfiltered_html_forum'] ) ) { 
  41. remove_filter( 'bbp_edit_forum_pre_title', 'wp_filter_kses' ); 
  42. remove_filter( 'bbp_edit_forum_pre_content', 'bbp_encode_bad', 10 ); 
  43. remove_filter( 'bbp_edit_forum_pre_content', 'bbp_filter_kses', 30 ); 
  44.  
  45. /** Forum Parent ***********************************************************/ 
  46.  
  47. // Forum parent id was passed 
  48. if ( !empty( $_POST['bbp_forum_parent_id'] ) ) { 
  49. $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] ); 
  50.  
  51. // Current forum this forum is in 
  52. $current_parent_forum_id = bbp_get_forum_parent_id( $forum_id ); 
  53.  
  54. // Forum exists 
  55. if ( !empty( $forum_parent_id ) && ( $forum_parent_id !== $current_parent_forum_id ) ) { 
  56.  
  57. // Forum is closed and user cannot access 
  58. if ( bbp_is_forum_closed( $forum_parent_id ) && !current_user_can( 'edit_forum', $forum_parent_id ) ) { 
  59. bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new forums.', bbpress ) ); 
  60.  
  61. // Forum is private and user cannot access 
  62. if ( bbp_is_forum_private( $forum_parent_id ) && !current_user_can( 'read_private_forums' ) ) { 
  63. bbp_add_error( 'bbp_edit_forum_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', bbpress ) ); 
  64.  
  65. // Forum is hidden and user cannot access 
  66. if ( bbp_is_forum_hidden( $forum_parent_id ) && !current_user_can( 'read_hidden_forums' ) ) { 
  67. bbp_add_error( 'bbp_edit_forum_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', bbpress ) ); 
  68.  
  69. /** Forum Title ***********************************************************/ 
  70.  
  71. if ( !empty( $_POST['bbp_forum_title'] ) ) 
  72. $forum_title = esc_attr( strip_tags( $_POST['bbp_forum_title'] ) ); 
  73.  
  74. // Filter and sanitize 
  75. $forum_title = apply_filters( 'bbp_edit_forum_pre_title', $forum_title, $forum_id ); 
  76.  
  77. // No forum title 
  78. if ( empty( $forum_title ) ) 
  79. bbp_add_error( 'bbp_edit_forum_title', __( '<strong>ERROR</strong>: Your forum needs a title.', bbpress ) ); 
  80.  
  81. /** Forum Content *********************************************************/ 
  82.  
  83. if ( !empty( $_POST['bbp_forum_content'] ) ) 
  84. $forum_content = $_POST['bbp_forum_content']; 
  85.  
  86. // Filter and sanitize 
  87. $forum_content = apply_filters( 'bbp_edit_forum_pre_content', $forum_content, $forum_id ); 
  88.  
  89. // No forum content 
  90. if ( empty( $forum_content ) ) 
  91. bbp_add_error( 'bbp_edit_forum_content', __( '<strong>ERROR</strong>: Your forum description cannot be empty.', bbpress ) ); 
  92.  
  93. /** Forum Blacklist *******************************************************/ 
  94.  
  95. if ( !bbp_check_for_blacklist( $anonymous_data, bbp_get_forum_author_id( $forum_id ), $forum_title, $forum_content ) ) 
  96. bbp_add_error( 'bbp_forum_blacklist', __( '<strong>ERROR</strong>: Your forum cannot be edited at this time.', bbpress ) ); 
  97.  
  98. /** Forum Moderation ******************************************************/ 
  99.  
  100. $post_status = bbp_get_public_status_id(); 
  101. if ( !bbp_check_for_moderation( $anonymous_data, bbp_get_forum_author_id( $forum_id ), $forum_title, $forum_content ) ) 
  102. $post_status = bbp_get_pending_status_id(); 
  103.  
  104. /** Additional Actions (Before Save) **************************************/ 
  105.  
  106. do_action( 'bbp_edit_forum_pre_extras', $forum_id ); 
  107.  
  108. // Bail if errors 
  109. if ( bbp_has_errors() ) 
  110. return; 
  111.  
  112. /** No Errors *************************************************************/ 
  113.  
  114. // Add the content of the form to $forum_data as an array 
  115. // Just in time manipulation of forum data before being edited 
  116. $forum_data = apply_filters( 'bbp_edit_forum_pre_insert', array( 
  117. 'ID' => $forum_id,  
  118. 'post_title' => $forum_title,  
  119. 'post_content' => $forum_content,  
  120. 'post_status' => $post_status,  
  121. 'post_parent' => $forum_parent_id 
  122. ) ); 
  123.  
  124. // Insert forum 
  125. $forum_id = wp_update_post( $forum_data ); 
  126.  
  127. /** Revisions *************************************************************/ 
  128.  
  129. /** 
  130. * @todo omitted for 2.1 
  131. // Revision Reason 
  132. if ( !empty( $_POST['bbp_forum_edit_reason'] ) ) 
  133. $forum_edit_reason = esc_attr( strip_tags( $_POST['bbp_forum_edit_reason'] ) ); 
  134.   
  135. // Update revision log 
  136. if ( !empty( $_POST['bbp_log_forum_edit'] ) && ( "1" === $_POST['bbp_log_forum_edit'] ) && ( $revision_id = wp_save_post_revision( $forum_id ) ) ) { 
  137. bbp_update_forum_revision_log( array( 
  138. 'forum_id' => $forum_id,  
  139. 'revision_id' => $revision_id,  
  140. 'author_id' => bbp_get_current_user_id(),  
  141. 'reason' => $forum_edit_reason 
  142. ) ); 
  143. */ 
  144.  
  145. /** No Errors *************************************************************/ 
  146.  
  147. if ( !empty( $forum_id ) && !is_wp_error( $forum_id ) ) { 
  148.  
  149. // Update counts, etc... 
  150. do_action( 'bbp_edit_forum', array( 
  151. 'forum_id' => $forum_id,  
  152. 'post_parent' => $forum_parent_id,  
  153. 'forum_author' => $forum->post_author,  
  154. 'last_topic_id' => 0,  
  155. 'last_reply_id' => 0,  
  156. 'last_active_id' => 0,  
  157. 'last_active_time' => 0,  
  158. 'last_active_status' => bbp_get_public_status_id() 
  159. ) ); 
  160.  
  161. // If the new forum parent id is not equal to the old forum parent 
  162. // id, run the bbp_move_forum action and pass the forum's parent id 
  163. // as the first arg and new forum parent id as the second. 
  164. // @todo implement 
  165. //if ( $forum_id !== $forum->post_parent ) 
  166. // bbp_move_forum_handler( $forum_parent_id, $forum->post_parent, $forum_id ); 
  167.  
  168. /** Additional Actions (After Save) ***********************************/ 
  169.  
  170. do_action( 'bbp_edit_forum_post_extras', $forum_id ); 
  171.  
  172. /** Redirect **********************************************************/ 
  173.  
  174. // Redirect to 
  175. $redirect_to = bbp_get_redirect_to(); 
  176.  
  177. // View all? 
  178. $view_all = bbp_get_view_all(); 
  179.  
  180. // Get the forum URL 
  181. $forum_url = bbp_get_forum_permalink( $forum_id, $redirect_to ); 
  182.  
  183. // Add view all? 
  184. if ( !empty( $view_all ) ) 
  185. $forum_url = bbp_add_view_all( $forum_url ); 
  186.  
  187. // Allow to be filtered 
  188. $forum_url = apply_filters( 'bbp_edit_forum_redirect_to', $forum_url, $view_all, $redirect_to ); 
  189.  
  190. /** Successful Edit ***************************************************/ 
  191.  
  192. // Redirect back to new forum 
  193. wp_safe_redirect( $forum_url ); 
  194.  
  195. // For good measure 
  196. exit(); 
  197.  
  198. /** Errors ****************************************************************/ 
  199.  
  200. } else { 
  201. $append_error = ( is_wp_error( $forum_id ) && $forum_id->get_error_message() ) ? $forum_id->get_error_message() . ' ' : ''; 
  202. bbp_add_error( 'bbp_forum_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', bbpress ) );