Accessing plugin functionality within WP REST API

I’m using the WP REST API to trigger a task from an AJAX request, my callback function attempts to trigger an action found within a plugin, however, that plugin doesn’t appear to have loaded.

The following code is within my functions.php file:

add_action(‘rest_api_init’, function() {

register_rest_route(‘foo/v1’, ‘/capture-payments’, array(
‘methods’ => ‘POST’,
‘callback’ => [$this, ‘capturePayments’],


public static function capturePayments($request) {

if ( ! has_action(‘name_of_plugin_action’) ) {
return new WP_Error(‘payment_capture_not_available’, ‘Payment capture is not available’, array(‘status’ => 500));


My question is, is there a way to load the plugins for this API request, such that I can access their functionality as I would within a normal theme?

Read more here:: Accessing plugin functionality within WP REST API

Leave a Reply

Your email address will not be published. Required fields are marked *