bp_activity_admin_reply

AJAX receiver for Activity replies via the admin screen.

Description

bp_activity_admin_reply(); 

Processes requests to add new activity comments, and echoes HTML for a new table row.


Usage

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

Defined (1)

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

/bp-activity/bp-activity-admin.php  
  1. function bp_activity_admin_reply() { 
  2. // Check nonce. 
  3. check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' ); 
  4.  
  5. $parent_id = ! empty( $_REQUEST['parent_id'] ) ? (int) $_REQUEST['parent_id'] : 0; 
  6. $root_id = ! empty( $_REQUEST['root_id'] ) ? (int) $_REQUEST['root_id'] : 0; 
  7.  
  8. // $parent_id is required 
  9. if ( empty( $parent_id ) ) 
  10. die( '-1' ); 
  11.  
  12. // If $root_id not set (e.g. for root items), use $parent_id. 
  13. if ( empty( $root_id ) ) 
  14. $root_id = $parent_id; 
  15.  
  16. // Check that a reply has been entered. 
  17. if ( empty( $_REQUEST['content'] ) ) 
  18. die( __( ERROR Please type a reply.', buddypress ) ); 
  19.  
  20. // Check parent activity exists. 
  21. $parent_activity = new BP_Activity_Activity( $parent_id ); 
  22. if ( empty( $parent_activity->component ) ) 
  23. die( __( ERROR The item you are trying to reply to cannot be found, or it has been deleted.', buddypress ) ); 
  24.  
  25. // @todo: Check if user is allowed to create new activity items 
  26. // if ( ! current_user_can( 'bp_new_activity' ) ) 
  27. if ( ! current_user_can( 'bp_moderate' ) ) 
  28. die( '-1' ); 
  29.  
  30. // Add new activity comment. 
  31. $new_activity_id = bp_activity_new_comment( array( 
  32. 'activity_id' => $root_id, // ID of the root activity item. 
  33. 'content' => $_REQUEST['content'],  
  34. 'parent_id' => $parent_id, // ID of a parent comment. 
  35. ) ); 
  36.  
  37. // Fetch the new activity item, as we need it to create table markup to return. 
  38. $new_activity = new BP_Activity_Activity( $new_activity_id ); 
  39.  
  40. // This needs to be set for the BP_Activity_List_Table constructor to work. 
  41. set_current_screen( 'toplevel_page_bp-activity' ); 
  42.  
  43. // Set up an output buffer. 
  44. ob_start(); 
  45. $list_table = new BP_Activity_List_Table(); 
  46. $list_table->single_row( (array) $new_activity ); 
  47.  
  48. // Get table markup. 
  49. $response = array( 
  50. 'data' => ob_get_contents(),  
  51. 'id' => $new_activity_id,  
  52. 'position' => -1,  
  53. 'what' => 'bp_activity',  
  54. ); 
  55. ob_end_clean(); 
  56.  
  57. // Send response. 
  58. $r = new WP_Ajax_Response(); 
  59. $r->add( $response ); 
  60. $r->send(); 
  61.  
  62. exit();