bp_dtheme_new_activity_comment

Posts new Activity comments received via a POST request.

Description

(string) bp_dtheme_new_activity_comment(); 

Returns (string)

HTML


Usage

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

Defined (1)

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

/bp-themes/bp-default/_inc/ajax.php  
  1. function bp_dtheme_new_activity_comment() { 
  2. global $activities_template; 
  3.  
  4. // Bail if not a POST action 
  5. if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 
  6. return; 
  7.  
  8. // Check the nonce 
  9. check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 
  10.  
  11. if ( ! is_user_logged_in() ) 
  12. exit( '-1' ); 
  13.  
  14. if ( empty( $_POST['content'] ) ) 
  15. exit( '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', buddypress ) . '</p></div>' ); 
  16.  
  17. if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) ) 
  18. exit( '-1<div id="message" class="error"><p>' . __( 'There was anerrorposting that reply, please try again.', buddypress ) . '</p></div>' ); 
  19.  
  20. $comment_id = bp_activity_new_comment( array( 
  21. 'activity_id' => $_POST['form_id'],  
  22. 'content' => $_POST['content'],  
  23. 'parent_id' => $_POST['comment_id'],  
  24. 'error_type' => wp_error 
  25. ) ); 
  26.  
  27. if ( false === $comment_id ) { 
  28. exit( '-1<div id="message" class="error"><p>' . __( 'There was anerrorposting that reply, please try again.', buddypress ) . '</p></div>' ); 
  29. } elseif ( is_wp_error( $comment_id ) ) { 
  30. exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $comment_id->get_error_message() ) . '</p></div>' ); 
  31.  
  32. // Load the new activity item into the $activities_template global 
  33. bp_has_activities( 'display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id ); 
  34.  
  35. // Swap the current comment with the activity item we just loaded 
  36. $activities_template->activity = new stdClass; 
  37. $activities_template->activity->id = $activities_template->activities[0]->item_id; 
  38. $activities_template->activity->current_comment = $activities_template->activities[0]; 
  39.  
  40. $template = locate_template( 'activity/comment.php', false, false ); 
  41.  
  42. /** 
  43. * Backward compatibility. In older versions of BP, the markup was 
  44. * generated in the PHP instead of a template. This ensures that 
  45. * older themes (which are not children of bp-default and won't 
  46. * have the new template) will still work. 
  47. */ 
  48. if ( empty( $template ) ) 
  49. $template =buddypress)->plugin_dir . '/bp-themes/bp-default/activity/comment.php'; 
  50.  
  51. load_template( $template, false ); 
  52.  
  53. unset( $activities_template ); 
  54. exit;