function bp_get_url_data( $url ) {
global $wp, $bp, $wp_query;
$tempurl = ! empty( $_SERVER['REQUEST_URI'] ) ? bbapp_input_clean( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ! bp_has_pretty_urls() ) {
$bp_request = preg_replace( '|https?\://[^/]+/|', '/', $url );
$matched_query = wp_parse_url( $bp_request, PHP_URL_QUERY );
} else {
$_SERVER['REQUEST_URI'] = preg_replace( '|https?\://[^/]+/|', '/', $url );
$wp->parse_request();
// Extra step to check for root profiles.
$member = bp_rewrites_get_member_data( $wp->request );
if ( isset( $member['object'] ) && $member['object'] ) {
$_SERVER['REQUEST_URI'] = trailingslashit( $bp->members->root_slug ) . $wp->request;
// Reparse the request.
$wp->parse_request();
}
$matched_query = $wp->matched_query;
}
// Parse the matched query.
$wp_query->parse_query( $matched_query );
$_SERVER['REQUEST_URI'] = $tempurl;
$global_variable = array();
$global_variable['component'] = bp_current_component();
$global_variable['action'] = bp_current_action();
$global_variable['item'] = bp_current_item();
$global_variable['action_variables'] = bp_action_variables();
return $global_variable;
}
Related