Support » Alpha/Beta/RC » admin-ajax.php unnecessary wp_die( ‘0’, 400 );

  • Resolved Tickera

    (@tickera)


    Hi guys,

    We’re just testing latest beta release and found something, as we think, unnecessary.
    At the end of the admin-ajax.php file (line 105), somebody modified wp_die( ‘0’ ); to wp_die( ‘0’, 400 );

    it makes perfect sense to leave it as is on this line 28 (as it’s also modified)

    if ( empty( $_REQUEST[‘action’] ) )
    wp_die( ‘0’, 400 );

    since it’s really Bad Request if you don’t supply action with your post call – no problems here 😉

    HOWEVER, we don’t see a need to have it at the end of the file. That means, that you’ll get the same error (400 Bad Request) if you don’t die / exit / whatever your function after response even if you supply all arguments, action etc. So this one is either unnecessary and should be replaced with wp_die( ‘0’ ) or error / error code should be replaced with some other which describes the “error” better.

    Hope it helps.

    Cheers!
    Marko

Viewing 3 replies - 1 through 3 (of 3 total)
  • Maybe it should be changed to wp_die( '0', 400 ); only if the action didn’t exist? We could do an has_action() check if it returns false then we know that handler was registered and it was a bad request. Otherwise, if a handler was registered but just didn’t wp_die() then it could still be a 200 response.

    Moderator Marius L. J.

    (@clorith)

    Hiya,

    You’re quite right about it making sense to not return a bad request status if the file has finished processing, we’ve created ticket #42240 for this. It has a patch to revert that bit, and also implement the suggestion by Weston, as it makes sense seeing as how the request is bad if there’s nothing waiting to be called.

    I’ll tag this topic as resolved, it’s the status we use if there’s a Trac ticket associated with an issue to help us keep on top of which topics still need attention here on the forums.

    Awesome, thanks guys!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.