Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/24/2015 01:32:20 PM (11 years ago)
Author:
johnjamesjacoby
Message:

API: Introduce bbp_redirect()

  • Wraps wp_safe_redirect() & exit() calls
  • Prevents errors from potentially empty wp_get_referrer() results
  • Replace wp_safe_redirect() usages with bbp_redirect()

Fixes #2778.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/functions.php

    r5481 r5658  
    584584}
    585585
     586/** Redirection ***************************************************************/
     587
     588/**
     589 * Perform a safe, local redirect somewhere inside the current site
     590 *
     591 * On some setups, passing the value of wp_get_referer() may result in an empty
     592 * value for $location, which results in an error on redirection. If $location
     593 * is empty, we can safely redirect back to the forum root. This might change
     594 * in a future version, possibly to the site root.
     595 *
     596 * @since bbPress (r5658)
     597 *
     598 * @uses wp_safe_redirect()
     599 *
     600 * @param string $location The URL to redirect the user to.
     601 * @param int    $status   Optional. The numeric code to give in the redirect
     602 *                         headers. Default: 302.
     603 */
     604function bbp_redirect( $location = '', $status = 302 ) {
     605
     606    // Prevent errors from empty $location
     607    if ( empty( $location ) ) {
     608        $location = bbp_get_forums_url();
     609    }
     610
     611    // Setup the safe redirect
     612    wp_safe_redirect( $location, $status );
     613
     614    // Exit so the redirect takes place immediately
     615    exit();
     616}
Note: See TracChangeset for help on using the changeset viewer.