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()


Top ↑

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();
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.