Skip to:
Content

BuddyPress.org

Changeset 527


Ignore:
Timestamp:
11/10/2008 11:22:03 AM (18 years ago)
Author:
apeatling
Message:

Added new function "bp_core_redirect()" to perform safe "wp_redirect()" calls. Stops bug with redirection loops and multiple friend confirmations.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r519 r527  
    213213add_action( 'admin_menu', 'bp_core_check_installed' );
    214214
    215 
     215/**
     216 * bp_core_add_admin_menu()
     217 *
     218 * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
     219 *
     220 * @package BuddyPress Core
     221 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     222 * @global $wpdb WordPress DB access object.
     223 * @uses is_site_admin() returns true if the current user is a site admin, false if not
     224 * @uses add_submenu_page() WP function to add a submenu item
     225 */
    216226function bp_core_add_admin_menu() {
    217227    global $wpdb, $bp;
     
    224234add_action( 'admin_menu', 'bp_core_add_admin_menu' );
    225235
     236/**
     237 * bp_core_redirect()
     238 *
     239 * Perform a safe wp_redirect without causing redirect loops due to confirmation redirects.
     240 *
     241 * @package BuddyPress Core
     242 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     243 * @global $wpdb WordPress DB access object.
     244 * @uses bp_core_is_root_component() checks if a component sits in the root of the site
     245 * @uses site_url() Returns the site url including protocol
     246 */
     247function bp_core_redirect( $url ) {
     248    global $bp;
     249   
     250    if ( isset( $_GET['nr'] ) ) {
     251        if ( bp_core_is_root_component( $bp['current_component'] ) ) {
     252            if ( $bp['current_item'] != '' )
     253                $url = site_url() . '/' . $bp[$bp['current_component']]['slug'] . '/' . $bp['current_item'] . '/' . $bp['current_action'] . '/' . $bp['action_variables'][0];
     254            else
     255                $url = site_url() . '/' . $bp[$bp['current_component']]['slug'] . '/' . $bp['current_action'] . '/' . $bp['action_variables'][0];
     256        } else {
     257            $url = $bp['loggedin_domain'] . $bp[$bp['current_component']]['slug'] . '/' . $bp['current_action'];
     258        }
     259    }
     260
     261    wp_redirect( $url );
     262}
     263
     264/**
     265 * bp_core_is_root_component()
     266 *
     267 * Checks to see if a component's URL should be in the root, not under a member page:
     268 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
     269 *
     270 * @package BuddyPress Core
     271 * @return true if root component, else false.
     272 */
     273function bp_core_is_root_component( $component_name ) {
     274    $root_components = explode( ',', BP_CORE_ROOT_COMPONENTS );
     275    return in_array( $component_name, $root_components );
     276}
    226277
    227278/**
  • trunk/bp-friends.php

    r525 r527  
    132132            bp_core_add_message( __('Friendship could not be accepted', 'buddypress'), 'error' );
    133133        }
    134         wp_redirect( $_SERVER['HTTP_REFERER'] );
     134        bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    135135       
    136136    } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) {
     
    141141            bp_core_add_message( __('Friendship could not be rejected', 'buddypress'), 'error' );
    142142        }   
    143         wp_redirect( $_SERVER['HTTP_REFERER'] );   
     143        bp_core_redirect( $_SERVER['HTTP_REFERER'] );   
    144144    }
    145145   
  • trunk/bp-groups.php

    r524 r527  
    288288            bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' );         
    289289        }
    290         wp_redirect( $_SERVER['HTTP_REFERER'] );
     290        bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    291291       
    292292    } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) {
     
    296296            bp_core_add_message( __('Group invite could not be rejected', 'buddypress'), 'error' );         
    297297        }
    298         wp_redirect( $_SERVER['HTTP_REFERER'] );
     298        bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    299299    }
    300300   
     
    336336            // We're done.
    337337            if ( $create_group_step == 4 )
    338                 wp_redirect( bp_group_permalink( $group_obj, false ) );
     338                bp_core_redirect( bp_group_permalink( $group_obj, false ) );
    339339
    340340            if ( !$group_id = groups_manage_group( $create_group_step, $_SESSION['group_obj_id'] ) ) {
    341341                bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
    342                 wp_redirect( $bp['loggedin_domain'] . $bp['groups']['slug'] . '/create/step/' . $create_group_step );
     342                bp_core_redirect( $bp['loggedin_domain'] . $bp['groups']['slug'] . '/create/step/' . $create_group_step );
    343343            } else {
    344344                $create_group_step++;
     
    396396           
    397397            if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
    398                 wp_redirect( bp_group_permalink( $group_obj, false ) );
     398                bp_core_redirect( bp_group_permalink( $group_obj, false ) );
    399399            } else {
    400                 wp_redirect( bp_group_permalink( $group_obj, false ) . '/' . $bp['wire']['slug'] );
     400                bp_core_redirect( bp_group_permalink( $group_obj, false ) . '/' . $bp['wire']['slug'] );
    401401            }
    402402   
     
    411411           
    412412            if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
    413                 wp_redirect( bp_group_permalink( $group_obj, false ) );
     413                bp_core_redirect( bp_group_permalink( $group_obj, false ) );
    414414            } else {
    415                 wp_redirect( bp_group_permalink( $group_obj, false ) . '/' . $bp['wire']['slug'] );
     415                bp_core_redirect( bp_group_permalink( $group_obj, false ) . '/' . $bp['wire']['slug'] );
    416416            }
    417417       
     
    453453           
    454454            bp_core_add_message( __('Group invites sent.', 'buddypress') );
    455             wp_redirect( bp_group_permalink( $group_obj, false ) );
     455            bp_core_redirect( bp_group_permalink( $group_obj, false ) );
    456456        } else {
    457457            // Show send invite page
     
    470470            if ( !groups_leave_group( $group_obj->id ) ) {
    471471                bp_core_add_message(  __('There was an error leaving the group. Please try again.', 'buddypress'), 'error' );
    472                 wp_redirect( bp_group_permalink( $group_obj, false) );
     472                bp_core_redirect( bp_group_permalink( $group_obj, false) );
    473473            } else {
    474474                bp_core_add_message( __('You left the group successfully.', 'buddypress') );
    475                 wp_redirect( $bp['loggedin_domain'] . $bp['groups']['slug'] );
     475                bp_core_redirect( $bp['loggedin_domain'] . $bp['groups']['slug'] );
    476476            }
    477477        } else if ( isset($bp['action_variables']) && $bp['action_variables'][0] == 'no' ) {
    478             wp_redirect( bp_group_permalink( $group_obj, false) );
     478            bp_core_redirect( bp_group_permalink( $group_obj, false) );
    479479        } else {
    480480            // Show leave group page
     
    498498                bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) );
    499499            }
    500             wp_redirect( bp_group_permalink( $group_obj, false ) );
     500            bp_core_redirect( bp_group_permalink( $group_obj, false ) );
    501501        }
    502502        bp_catch_uri( 'groups/request-membership' );
     
    526526                bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) );
    527527            }
    528             wp_redirect( $_SERVER['HTTP_REFERER'] );
     528            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    529529        }
    530530
     
    557557            }
    558558           
    559             wp_redirect( $_SERVER['HTTP_REFERER'] );
     559            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    560560        }
    561561       
     
    596596                }   
    597597            }
    598             wp_redirect( $_SERVER['HTTP_REFERER'] );
     598            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    599599        }
    600600       
     
    618618            } else {
    619619                bp_core_add_message( __( 'The group was deleted successfully', 'buddypress' ) );
    620                 wp_redirect( site_url() . '/' . $bp['groups']['slug'] . '/' );
     620                bp_core_redirect( site_url() . '/' . $bp['groups']['slug'] . '/' );
    621621            }
    622             wp_redirect( $_SERVER['HTTP_REFERER'] );
     622            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    623623        } else {
    624624            bp_catch_uri( 'groups/admin/delete-group' );
     
    691691            bp_core_add_message( __('You joined the group!', 'buddypress') );
    692692        }
    693         wp_redirect( $_SERVER['HTTP_REFERER'] );
     693        bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    694694    }
    695695
  • trunk/bp-messages.php

    r518 r527  
    281281
    282282    if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) {
    283         wp_redirect( $_SERVER['HTTP_REFERER'] );
     283        bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    284284    } else {
    285285        // delete message
    286286        if ( !BP_Messages_Thread::delete($thread_id) ) {
    287287            bp_core_add_message( __('There was an error deleting that message.', 'buddypress'), 'error' );
    288             wp_redirect( $_SERVER['HTTP_REFERER'] );
     288            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    289289        } else {
    290290            bp_core_add_message( __('Message deleted.', 'buddypress') );
    291             wp_redirect( $_SERVER['HTTP_REFERER'] );
     291            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    292292        }
    293293    }
     
    310310        if ( !BP_Messages_Thread::delete( explode(',', $thread_ids ) ) ) {
    311311            bp_core_add_message( __('There was an error deleting messages.', 'buddypress'), 'error' );
    312             wp_redirect( $_SERVER['HTTP_REFERER'] );
     312            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    313313        } else {
    314314            bp_core_add_message( __('Messages deleted.', 'buddypress') );
    315             wp_redirect( $_SERVER['HTTP_REFERER'] );
     315            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    316316        }
    317317    }
     
    367367        if ( !$from_ajax ) {   
    368368            bp_core_add_message( __('Please enter at least one valid user to send this message to.', 'buddypress'), 'error' );
    369             wp_redirect( $_SERVER['HTTP_REFERER'] );
     369            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    370370        } else {
    371371            return array('status' => 0, 'message' => __('There was an error sending the reply, please try again.', 'buddypress'));
     
    374374        if ( !$from_ajax ) {
    375375            bp_core_add_message( __('Please make sure you fill in all the fields.', 'buddypress'), 'error' );
    376             wp_redirect( $_SERVER['HTTP_REFERER'] );
     376            bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    377377        } else {
    378378            return array('status' => 0, 'message' => __('Please make sure you have typed a message before sending a reply.', 'buddypress'));
     
    405405                } else {
    406406                    bp_core_add_message( $message, $type );
    407                     wp_redirect( $_SERVER['HTTP_REFERER'] );
     407                    bp_core_redirect( $_SERVER['HTTP_REFERER'] );
    408408                }
    409409            } else {
     
    424424                } else {
    425425                    bp_core_add_message( $message );
    426                     wp_redirect( $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox' );
     426                    bp_core_redirect( $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox' );
    427427                }
    428428            }
     
    435435            } else {
    436436                bp_core_add_message( $message, $type );
    437                 wp_redirect( $bp['loggedin_domain'] . $bp['messages']['slug'] . '/compose' );
     437                bp_core_redirect( $bp['loggedin_domain'] . $bp['messages']['slug'] . '/compose' );
    438438            }
    439439        }
  • trunk/bp-wire.php

    r518 r527  
    9696   
    9797    if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
    98         wp_redirect( $bp['current_domain'] );
     98        bp_core_redirect( $bp['current_domain'] );
    9999    } else {
    100         wp_redirect( $bp['current_domain']. $bp['wire']['slug'] );
     100        bp_core_redirect( $bp['current_domain']. $bp['wire']['slug'] );
    101101    }
    102102}
     
    118118   
    119119    if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
    120         wp_redirect( $bp['current_domain'] );
     120        bp_core_redirect( $bp['current_domain'] );
    121121    } else {
    122         wp_redirect( $bp['current_domain']. $bp['wire']['slug'] );
     122        bp_core_redirect( $bp['current_domain']. $bp['wire']['slug'] );
    123123    }
    124124}
Note: See TracChangeset for help on using the changeset viewer.