bbp_ajax_response( bool $success = false, string $content = '', $status = -1, array $extras = array() )
Helper method to return JSON response for the ajax calls
Description
Parameters
- $success
-
(Optional)
Default value: false
- $content
-
(Optional)
Default value: ''
- $extras
-
(Optional)
Default value: array()
Source
File: bp-forums/common/ajax.php
function bbp_ajax_response( $success = false, $content = '', $status = -1, $extras = array() ) {
// Set status to 200 if setting response as successful
if ( ( true === $success ) && ( -1 === $status ) )
$status = 200;
// Setup the response array
$response = array(
'success' => $success,
'status' => $status,
'content' => $content
);
// Merge extra response parameters in
if ( !empty( $extras ) && is_array( $extras ) ) {
$response = array_merge( $response, $extras );
}
// Send back the JSON
wp_send_json( $response, $status );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r4542) | 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.