Skip to:
Content

bbPress.org

Changeset 5658


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.

Location:
trunk/src/includes
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/forums.php

    r5637 r5658  
    428428     *                    data, action and message
    429429     * @uses add_query_arg() To add custom args to the url
    430      * @uses wp_safe_redirect() Redirect the page to custom url
     430     * @uses bbp_redirect() Redirect the page to custom url
    431431     */
    432432    public function toggle_forum() {
     
    480480            // Redirect back to the forum
    481481            $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'forum_id' ) ) );
    482             wp_safe_redirect( $redirect );
    483 
    484             // For good measure
    485             exit();
     482            bbp_redirect( $redirect );
    486483        }
    487484    }
  • trunk/src/includes/admin/functions.php

    r5466 r5658  
    200200 * @uses delete_transient() To delete the transient if it exists
    201201 * @uses is_network_admin() To bail if being network activated
    202  * @uses wp_safe_redirect() To redirect
     202 * @uses bbp_redirect() To redirect
    203203 * @uses add_query_arg() To help build the URL to redirect to
    204204 * @uses admin_url() To get the admin URL to index.php
     
    227227
    228228    // Redirect to bbPress about page
    229     wp_safe_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) );
     229    bbp_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) );
    230230}
    231231
  • trunk/src/includes/admin/replies.php

    r5637 r5658  
    465465     *                    data, action and message
    466466     * @uses add_query_arg() To add custom args to the url
    467      * @uses wp_safe_redirect() Redirect the page to custom url
     467     * @uses bbp_redirect() Redirect the page to custom url
    468468     */
    469469    public function toggle_reply() {
     
    522522            // Redirect back to the reply
    523523            $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) );
    524             wp_safe_redirect( $redirect );
    525 
    526             // For good measure
    527             exit();
     524            bbp_redirect( $redirect );
    528525        }
    529526    }
  • trunk/src/includes/admin/topics.php

    r5637 r5658  
    488488     *                    data, action and message
    489489     * @uses add_query_arg() To add custom args to the url
    490      * @uses wp_safe_redirect() Redirect the page to custom url
     490     * @uses bbp_redirect() Redirect the page to custom url
    491491     */
    492492    public function toggle_topic() {
     
    585585            // Redirect back to the topic
    586586            $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'topic_id' ) ) );
    587             wp_safe_redirect( $redirect );
    588 
    589             // For good measure
    590             exit();
     587            bbp_redirect( $redirect );
    591588        }
    592589    }
  • 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}
  • trunk/src/includes/extend/buddypress/notifications.php

    r5512 r5658  
    183183
    184184    // Redirect
    185     wp_safe_redirect( $redirect );
    186 
    187     // For good measure
    188     exit();
     185    bbp_redirect( $redirect );
    189186}
    190187add_action( 'bbp_get_request', 'bbp_buddypress_mark_notifications', 1 );
  • trunk/src/includes/forums/functions.php

    r5655 r5658  
    104104 * @uses bbp_unstick_forum() To unstick the forum
    105105 * @uses bbp_get_forum_permalink() To get the forum permalink
    106  * @uses wp_safe_redirect() To redirect to the forum link
     106 * @uses bbp_redirect() To redirect to the forum link
    107107 * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
    108108 *                                              messages
     
    332332
    333333        // Redirect back to new forum
    334         wp_safe_redirect( $redirect_url );
    335 
    336         // For good measure
    337         exit();
     334        bbp_redirect( $redirect_url );
    338335
    339336    // Errors
     
    373370 *                                 to another
    374371 * @uses bbp_get_forum_permalink() To get the forum permalink
    375  * @uses wp_safe_redirect() To redirect to the forum link
     372 * @uses bbp_redirect() To redirect to the forum link
    376373 * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
    377374 *                                              messages
     
    587584
    588585        // Redirect back to new forum
    589         wp_safe_redirect( $forum_url );
    590 
    591         // For good measure
    592         exit();
     586        bbp_redirect( $forum_url );
    593587
    594588    /** Errors ****************************************************************/
     
    21272121 * @uses current_user_can()
    21282122 * @uses bbp_get_forum_id()
    2129  * @uses wp_safe_redirect()
     2123 * @uses bbp_redirect()
    21302124 * @uses bbp_get_forum_permalink()
    21312125 */
     
    21332127
    21342128    // Bail if not editing a topic
    2135     if ( !bbp_is_forum_edit() ) {
     2129    if ( ! bbp_is_forum_edit() ) {
    21362130        return;
    21372131    }
    21382132
    21392133    // User cannot edit topic, so redirect back to reply
    2140     if ( !current_user_can( 'edit_forum', bbp_get_forum_id() ) ) {
    2141         wp_safe_redirect( bbp_get_forum_permalink() );
    2142         exit();
     2134    if ( ! current_user_can( 'edit_forum', bbp_get_forum_id() ) ) {
     2135        bbp_redirect( bbp_get_forum_permalink() );
    21432136    }
    21442137}
  • trunk/src/includes/replies/functions.php

    r5651 r5658  
    102102 *                    the reply to id
    103103 * @uses bbp_get_reply_url() To get the paginated url to the reply
    104  * @uses wp_safe_redirect() To redirect to the reply url
     104 * @uses bbp_redirect() To redirect to the reply url
    105105 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
    106106 *                                              message
     
    450450
    451451        // Redirect back to new reply
    452         wp_safe_redirect( $reply_url );
    453 
    454         // For good measure
    455         exit();
     452        bbp_redirect( $reply_url );
    456453
    457454    /** Errors ****************************************************************/
     
    492489 *                    and the reply to id
    493490 * @uses bbp_get_reply_url() To get the paginated url to the reply
    494  * @uses wp_safe_redirect() To redirect to the reply url
     491 * @uses bbp_redirect() To redirect to the reply url
    495492 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
    496493 *                                             message
     
    762759
    763760        // Redirect back to new reply
    764         wp_safe_redirect( $reply_url );
    765 
    766         // For good measure
    767         exit();
     761        bbp_redirect( $reply_url );
    768762
    769763    /** Errors ****************************************************************/
     
    12741268 *                    source topic ids and source topic's forum id
    12751269 * @uses bbp_get_topic_permalink() To get the topic permalink
    1276  * @uses wp_safe_redirect() To redirect to the topic link
     1270 * @uses bbp_redirect() To redirect to the topic link
    12771271 */
    12781272function bbp_move_reply_handler( $action = '' ) {
     
    14971491
    14981492    // Redirect back to the topic
    1499     wp_safe_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
    1500 
    1501     // For good measure
    1502     exit();
     1493    bbp_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
    15031494}
    15041495
     
    15701561 * @uses bbp_get_reply_url() To get the reply url
    15711562 * @uses add_query_arg() To add custom args to the reply url
    1572  * @uses wp_safe_redirect() To redirect to the reply
     1563 * @uses bbp_redirect() To redirect to the reply
    15731564 * @uses bbPress::errors:add() To log the error messages
    15741565 */
     
    16941685
    16951686        // Redirect back to reply
    1696         wp_safe_redirect( $reply_url );
    1697 
    1698         // For good measure
    1699         exit();
     1687        bbp_redirect( $reply_url );
    17001688
    17011689    // Handle errors
     
    23112299 * @uses current_user_can()
    23122300 * @uses bbp_get_topic_id()
    2313  * @uses wp_safe_redirect()
     2301 * @uses bbp_redirect()
    23142302 * @uses bbp_get_topic_permalink()
    23152303 */
     
    23172305
    23182306    // Bail if not editing a topic
    2319     if ( !bbp_is_reply_edit() ) {
     2307    if ( ! bbp_is_reply_edit() ) {
    23202308        return;
    23212309    }
    23222310
    23232311    // User cannot edit topic, so redirect back to reply
    2324     if ( !current_user_can( 'edit_reply', bbp_get_reply_id() ) ) {
    2325         wp_safe_redirect( bbp_get_reply_url() );
    2326         exit();
     2312    if ( ! current_user_can( 'edit_reply', bbp_get_reply_id() ) ) {
     2313        bbp_redirect( bbp_get_reply_url() );
    23272314    }
    23282315}
  • trunk/src/includes/search/functions.php

    r5466 r5658  
    8181
    8282    // Redirect and bail
    83     wp_safe_redirect( $redirect_to );
    84     exit();
     83    bbp_redirect( $redirect_to );
    8584}
  • trunk/src/includes/topics/functions.php

    r5656 r5658  
    109109 * @uses bbp_unstick_topic() To unstick the topic
    110110 * @uses bbp_get_topic_permalink() To get the topic permalink
    111  * @uses wp_safe_redirect() To redirect to the topic link
     111 * @uses bbp_redirect() To redirect to the topic link
    112112 * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
    113113 *                                              messages
     
    428428
    429429        // Redirect back to new topic
    430         wp_safe_redirect( $redirect_url );
    431 
    432         // For good measure
    433         exit();
     430        bbp_redirect( $redirect_url );
    434431
    435432    // Errors
     
    471468 *                                 to another
    472469 * @uses bbp_get_topic_permalink() To get the topic permalink
    473  * @uses wp_safe_redirect() To redirect to the topic link
     470 * @uses bbp_redirect() To redirect to the topic link
    474471 * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
    475472 *                                              messages
     
    792789
    793790        // Redirect back to new topic
    794         wp_safe_redirect( $topic_url );
    795 
    796         // For good measure
    797         exit();
     791        bbp_redirect( $topic_url );
    798792
    799793    /** Errors ****************************************************************/
     
    11491143 *                    topic ids and source topic's forum id
    11501144 * @uses bbp_get_topic_permalink() To get the topic permalink
    1151  * @uses wp_safe_redirect() To redirect to the topic link
     1145 * @uses bbp_redirect() To redirect to the topic link
    11521146 */
    11531147function bbp_merge_topic_handler( $action = '' ) {
     
    13621356
    13631357    // Redirect back to new topic
    1364     wp_safe_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
    1365 
    1366     // For good measure
    1367     exit();
     1358    bbp_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
    13681359}
    13691360
     
    14491440 *                    source topic ids and source topic's forum id
    14501441 * @uses bbp_get_topic_permalink() To get the topic permalink
    1451  * @uses wp_safe_redirect() To redirect to the topic link
     1442 * @uses bbp_redirect() To redirect to the topic link
    14521443 */
    14531444function bbp_split_topic_handler( $action = '' ) {
     
    17451736
    17461737    // Redirect back to the topic
    1747     wp_safe_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
    1748 
    1749     // For good measure
    1750     exit();
     1738    bbp_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
    17511739}
    17521740
     
    18111799 * @uses do_action() Calls actions based on the actions with associated args
    18121800 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
    1813  * @uses wp_safe_redirect() To redirect to the url
     1801 * @uses bbp_redirect() To redirect to the url
    18141802 */
    18151803function bbp_edit_topic_tag_handler( $action = '' ) {
     
    19801968    // Redirect back
    19811969    $redirect = ( ! empty( $redirect ) && ! is_wp_error( $redirect ) ) ? $redirect : home_url();
    1982     wp_safe_redirect( $redirect );
    1983 
    1984     // For good measure
    1985     exit();
     1970    bbp_redirect( $redirect );
    19861971}
    19871972
     
    20872072 * @uses bbp_get_topic_permalink() To get the topic link
    20882073 * @uses add_query_arg() To add args to the url
    2089  * @uses wp_safe_redirect() To redirect to the topic
     2074 * @uses bbp_redirect() To redirect to the topic
    20902075 * @uses bbPress::errors:add() To log the error messages
    20912076 */
     
    22322217        }
    22332218
    2234         wp_safe_redirect( $redirect );
    2235 
    2236         // For good measure
    2237         exit();
     2219        bbp_redirect( $redirect );
    22382220
    22392221    // Handle errors
     
    37863768 * @uses current_user_can()
    37873769 * @uses bbp_get_topic_id()
    3788  * @uses wp_safe_redirect()
     3770 * @uses bbp_redirect()
    37893771 * @uses bbp_get_topic_permalink()
    37903772 */
     
    37983780    // User cannot edit topic, so redirect back to topic
    37993781    if ( ! current_user_can( 'edit_topic', bbp_get_topic_id() ) ) {
    3800         wp_safe_redirect( bbp_get_topic_permalink() );
    3801         exit();
     3782        bbp_redirect( bbp_get_topic_permalink() );
    38023783    }
    38033784}
     
    38113792 * @uses current_user_can()
    38123793 * @uses bbp_get_topic_tag_id()
    3813  * @uses wp_safe_redirect()
     3794 * @uses bbp_redirect()
    38143795 * @uses bbp_get_topic_tag_link()
    38153796 */
     
    38233804    // Bail if current user cannot edit topic tags
    38243805    if ( ! current_user_can( 'edit_topic_tags', bbp_get_topic_tag_id() ) ) {
    3825         wp_safe_redirect( bbp_get_topic_tag_link() );
    3826         exit();
    3827     }
    3828 }
     3806        bbp_redirect( bbp_get_topic_tag_link() );
     3807    }
     3808}
  • trunk/src/includes/users/functions.php

    r5657 r5658  
    2323 * @uses home_url() To get the home url
    2424 * @uses esc_url() To escape the url
    25  * @uses wp_safe_redirect() To redirect
     25 * @uses bbp_redirect() To redirect
    2626 */
    2727function bbp_redirect_login( $url = '', $raw_url = '', $user = '' ) {
     
    395395 * @uses bbp_get_favorites_link() To get the favorites page link
    396396 * @uses bbp_get_topic_permalink() To get the topic permalink
    397  * @uses wp_safe_redirect() To redirect to the url
     397 * @uses bbp_redirect() To redirect to the url
    398398 */
    399399function bbp_favorites_handler( $action = '' ) {
     
    471471        }
    472472
    473         wp_safe_redirect( $redirect );
    474 
    475         // For good measure
    476         exit();
     473        bbp_redirect( $redirect );
    477474
    478475    // Fail! Handle errors
     
    11161113 * @uses bbp_is_subscription() To check if it's the subscription page
    11171114 * @uses bbp_get_forum_permalink() To get the forum permalink
    1118  * @uses wp_safe_redirect() To redirect to the url
     1115 * @uses bbp_redirect() To redirect to the url
    11191116 */
    11201117function bbp_forum_subscriptions_handler( $action = '' ) {
     
    11921189        }
    11931190
    1194         wp_safe_redirect( $redirect );
    1195 
    1196         // For good measure
    1197         exit();
     1191        bbp_redirect( $redirect );
    11981192
    11991193    // Fail! Handle errors
     
    12221216 * @uses bbp_is_subscription() To check if it's the subscription page
    12231217 * @uses bbp_get_topic_permalink() To get the topic permalink
    1224  * @uses wp_safe_redirect() To redirect to the url
     1218 * @uses bbp_redirect() To redirect to the url
    12251219 */
    12261220function bbp_subscriptions_handler( $action = '' ) {
     
    12981292        }
    12991293
    1300         wp_safe_redirect( $redirect );
    1301 
    1302         // For good measure
    1303         exit();
     1294        bbp_redirect( $redirect );
    13041295
    13051296    // Fail! Handle errors
     
    13271318 * @uses delete_option() To delete the displayed user's email id option
    13281319 * @uses bbp_get_user_profile_edit_url() To get the edit profile url
    1329  * @uses wp_safe_redirect() To redirect to the url
     1320 * @uses bbp_redirect() To redirect to the url
    13301321 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
    13311322 * @uses current_user_can() To check if the current user can edit the user
     
    13711362            delete_option( $user_id . '_new_email' );
    13721363
    1373             wp_safe_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $user_id ) ) );
    1374             exit();
     1364            bbp_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $user_id ) ) );
    13751365        }
    13761366
     
    13781368    } elseif ( is_multisite() && bbp_is_user_home_edit() && ! empty( $_GET['dismiss'] ) && ( $user_id . '_new_email' === $_GET['dismiss'] ) ) {
    13791369        delete_option( $user_id . '_new_email' );
    1380         wp_safe_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $user_id ) ) );
    1381         exit();
     1370        bbp_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $user_id ) ) );
    13821371    }
    13831372
     
    14201409        $redirect = add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $edit_user ) );
    14211410
    1422         wp_safe_redirect( $redirect );
    1423         exit;
     1411        bbp_redirect( $redirect );
    14241412    }
    14251413}
     
    17041692 * @uses current_user_can()
    17051693 * @uses bbp_get_displayed_user_id()
    1706  * @uses wp_safe_redirect()
     1694 * @uses bbp_redirect()
    17071695 * @uses bbp_get_user_profile_url()
    17081696 */
     
    17441732
    17451733    // Redirect
    1746     wp_safe_redirect( $redirect_to );
    1747     exit();
     1734    bbp_redirect( $redirect_to );
    17481735}
    17491736
  • trunk/src/includes/users/template.php

    r5563 r5658  
    15191519 * @param string $url The URL to redirect to
    15201520 * @uses is_user_logged_in() Check if user is logged in
    1521  * @uses wp_safe_redirect() To safely redirect
     1521 * @uses bbp_redirect() To safely redirect
    15221522 * @uses bbp_get_user_profile_url() To get the profile url of the user
    15231523 * @uses bbp_get_current_user_id() To get the current user id
     
    15331533    $redirect_to = ! empty( $url ) ? $url : bbp_get_user_profile_url( bbp_get_current_user_id() );
    15341534
    1535     // Do a safe redirect and exit
    1536     wp_safe_redirect( $redirect_to );
    1537     exit;
     1535    // Do a safe redirect
     1536    bbp_redirect( $redirect_to );
    15381537}
    15391538
Note: See TracChangeset for help on using the changeset viewer.