bbp_ajax_response( bool $success = false, string $content = '', $status = -1, array $extras = array() )
Helper method to return JSON response for bbPress AJAX calls
Description Description
Parameters Parameters
- $success
-
(Optional)
Default value: false
- $content
-
(Optional)
Default value: ''
- $extras
-
(Optional)
Default value: array()
Source Source
File: includes/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
@header( 'Content-type: application/json' );
echo json_encode( $response );
die();
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |