WordPress.org

Make WordPress Core

Changeset 30355


Ignore:
Timestamp:
11/16/2014 06:10:58 AM (6 years ago)
Author:
johnbillion
Message:

Allow the response code to be passed as a shorthand to the $title or $args parameter of wp_die(), for brevity.

See #10551 and #11286
Props nacin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r30207 r30355  
    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 */
    23442359function 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        /**
Note: See TracChangeset for help on using the changeset viewer.