• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress develop tests

WordPress develop tests

WordPress develop tests a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WP_Ajax_UnitTestCase::_handleAjax() – Mimics the Ajax handling of admin-ajax.php.

You appear to be a bot. Output may be restricted

Description

Mimics the Ajax handling of admin-ajax.php.

Captures the output via output buffering, and if there is any, stores it in $this->_last_response.

Usage

WP_Ajax_UnitTestCase::_handleAjax( $action );

Parameters

$action
( string ) required – The action to handle.

Returns

void

Source

File name: wordpress-develop-tests/phpunit/includes/testcase-ajax.php


Lines:

1 to 22 of 22
  protected function _handleAjax( $action ) {

    // Start output buffering.
    ini_set( 'implicit_flush', false );
    ob_start();

    // Build the request.
    $_POST['action'] = $action;
    $_GET['action']  = $action;
    $_REQUEST        = array_merge( $_POST, $_GET );

    // Call the hooks.
    do_action( 'admin_init' );
    do_action( 'wp_ajax_' . $_REQUEST['action'], null );

    // Save the output.
    $buffer = ob_get_clean();
    if ( ! empty( $buffer ) ) {
      $this->_last_response = $buffer;
    }
  }
 

 View on GitHub

Published: 26th November 2019 | Last updated: 20th March 2022

Primary Sidebar

Information

Function name: WP_Ajax_UnitTestCase::_handleAjax
Class ref: WP_Ajax_UnitTestCase
Plugin ref: WordPress develop tests
Version: 5.9.3
Sourcefile: phpunit/includes/testcase-ajax.php
File ref: phpunit/includes/testcase-ajax.php
Deprecated?: No
API Letters: A,H,U,W

Footer

WordPress develop tests
WordPress develop tests
WordPress develop tests a2z
WordPress 6.4.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  develop.wp-a2z.org
© Copyright WordPress develop tests 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites