Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

assert_post_request()

Description

Assert API request is using POST method.

Parameters

ColumnTypeDefaultDescription
$force: bool
$force bool Force the assertion

Return

array Returns JSend data back {@see ajax_functions.php} if not POST method

Location

include/api_functions.php lines 268 to 285

Definition

 
function assert_post_request(bool $force): array
    {
    
// Legacy use cases we don't want to break backwards compatibility for (e.g JS api() makes only POST requests but
    // other clients might only use GET because it was allowed if not authenticating with native mode)
    
if (!$force)
        {
        return [];
        }
    elseif (
$_SERVER['REQUEST_METHOD'] === 'POST')
        {
        return [];
        }
    else
        {
        
http_response_code(405);
        return 
ajax_response_fail(ajax_build_message($GLOBALS['lang']['error-method-not_allowed']));
        }
    }

This article was last updated 27th April 2024 14:05 Europe/London time based on the source file dated 25th April 2024 17:25 Europe/London time.