bp_activity_admin_reply()

AJAX receiver for Activity replies via the admin screen.

Description

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

Source

File: bp-activity/bp-activity-admin.php

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function bp_activity_admin_reply() {
    // Check nonce.
    check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' );
 
    $parent_id = ! empty( $_REQUEST['parent_id'] ) ? (int) $_REQUEST['parent_id'] : 0;
    $root_id   = ! empty( $_REQUEST['root_id'] )   ? (int) $_REQUEST['root_id']   : 0;
 
    // $parent_id is required
    if ( empty( $parent_id ) )
        die( '-1' );
 
    // If $root_id not set (e.g. for root items), use $parent_id.
    if ( empty( $root_id ) )
        $root_id = $parent_id;
 
    // Check that a reply has been entered.
    if ( empty( $_REQUEST['content'] ) )
        die( __( 'ERROR: Please type a reply.', 'buddyboss' ) );
 
    // Check parent activity exists.
    $parent_activity = new BP_Activity_Activity( $parent_id );
    if ( empty( $parent_activity->component ) )
        die( __( 'ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddyboss' ) );
 
    // @todo: Check if user is allowed to create new activity items
    // if ( ! current_user_can( 'bp_new_activity' ) )
    if ( ! bp_current_user_can( 'bp_moderate' ) )
        die( '-1' );
 
    // Add new activity comment.
    $new_activity_id = bp_activity_new_comment( array(
        'activity_id' => $root_id,              // ID of the root activity item.
        'content'     => $_REQUEST['content'],
        'parent_id'   => $parent_id,            // ID of a parent comment.
    ) );
 
    // Fetch the new activity item, as we need it to create table markup to return.
    $new_activity = new BP_Activity_Activity( $new_activity_id );
 
    // This needs to be set for the BP_Activity_List_Table constructor to work.
    set_current_screen( 'toplevel_page_bp-activity' );
 
    // Set up an output buffer.
    ob_start();
    $list_table = new BP_Activity_List_Table();
    $list_table->single_row( (array) $new_activity );
 
    // Get table markup.
    $response array(
        'data'     => ob_get_contents(),
        'id'       => $new_activity_id,
        'position' => -1,
        'what'     => 'bp_activity',
    );
    ob_end_clean();
 
    // Send response.
    $r = new WP_Ajax_Response();
    $r->add( $response );
    $r->send();
 
    exit();
}

Changelog

Changelog
Version Description
BuddyPress 1.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.