bbp_do_ajax( string $action = '' )

Hooked to the ‘bbp_template_redirect’ action, this is also the custom theme-side AJAX handler.


Description Description

This is largely taken from admin-ajax.php, but adapted specifically for theme-side bbPress-only AJAX requests.


Parameters Parameters

$action

(Optional) Sanitized action from bbp_post_request/bbp_get_request

Default value: ''


Top ↑

Return Return

(If) not a bbPress AJAX request


Top ↑

Source Source

File: includes/common/ajax.php

function bbp_do_ajax( $action = '' ) {

	// Bail if not a bbPress specific AJAX request
	if ( ! bbp_is_ajax() ) {
		return;
	}

	// Set WordPress core AJAX constant for back-compat
	if ( ! defined( 'DOING_AJAX' ) ) {
		define( 'DOING_AJAX', true );
	}

	// Setup AJAX headers
	bbp_ajax_headers();

	// Compat for targeted action hooks (without $action param)
	$action = empty( $action )
		? sanitize_key( $_REQUEST['action'] ) // isset checked by bbp_is_ajax()
		: $action;

	// Setup action key
	$key = "bbp_ajax_{$action}";

	// Bail if no action is registered
	if ( empty( $action ) || ! has_action( $key ) ) {
		wp_die( '0', 400 );
	}

	// Everything is 200 OK.
	bbp_set_200();

	// Execute custom bbPress AJAX action
	do_action( $key );

	// All done
	wp_die( '0' );
}

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.