Skip to content

Commit b68026b

Browse files
committed
Allow the response code to be passed as a shorthand to the $title or $args parameter of wp_die(), for brevity.
See WordPress#10551 and WordPress#11286 Props nacin git-svn-id: https://develop.svn.wordpress.org/trunk@30355 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9a04369 commit b68026b

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

src/wp-includes/functions.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,17 +2331,40 @@ function wp_nonce_ays( $action ) {
23312331
*
23322332
* This function complements the die() PHP function. The difference is that
23332333
* HTML will be displayed to the user. It is recommended to use this function
2334-
* only, when the execution should not continue any further. It is not
2334+
* only when the execution should not continue any further. It is not
23352335
* recommended to call this function very often and try to handle as many errors
2336-
* as possible silently.
2336+
* as possible silently or more gracefully.
2337+
*
2338+
* As a shorthand, the desired HTTP response code may be passed as an integer to
2339+
* the $title parameter (the default title would apply) or the $args parameter.
23372340
*
23382341
* @since 2.0.4
23392342
*
2340-
* @param string $message Optional. Error message. Default empty.
2341-
* @param string $title Optional. Error title. Default empty.
2342-
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
2343+
* @param string|WP_Error $message Optional. Error message. Default empty.
2344+
* If this is a WP_Error object, the error's messages are used.
2345+
* @param string $title Optional. Error title. Default is a generic title.
2346+
* If $message is a WP_Error object, error data with the key
2347+
* 'title' may be used to specify the title.
2348+
* @param string|array|int $args {
2349+
* Optional. Arguments to control behavior. Default empty array.
2350+
* If $args is an integer, then it is treated as the response code.
2351+
*
2352+
* @type int $response The HTTP response code. Default 500.
2353+
* @type bool $back_link Whether to include a link to go back. Default false.
2354+
* @type string $text_direction The text direction. Defaults to the value of is_rtl().
2355+
* Accepts 'rtl'. This is only useful internally, when WordPress
2356+
* is still loading and the site's locale is not set up yet.
2357+
* }
23432358
*/
23442359
function wp_die( $message = '', $title = '', $args = array() ) {
2360+
2361+
if ( is_int( $args ) ) {
2362+
$args = array( 'response' => $args );
2363+
} elseif ( is_int( $title ) ) {
2364+
$args = array( 'response' => $title );
2365+
$title = '';
2366+
}
2367+
23452368
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
23462369
/**
23472370
* Filter callback for killing WordPress execution for AJAX requests.

0 commit comments

Comments
 (0)