bp_activity_action_permalink_router
Catch and route requests for single activity item permalinks.
Description
bp_activity_action_permalink_router();
Usage
if ( !function_exists( 'bp_activity_action_permalink_router' ) ) { require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-actions.php'; } // NOTICE! Understand what this does before running. $result = bp_activity_action_permalink_router();
Defined (1)
The function is defined in the following location(s).
- /bp-activity/bp-activity-actions.php
- function bp_activity_action_permalink_router() {
- // Not viewing activity.
- if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) )
- return false;
- // No activity to display.
- if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) )
- return false;
- // Get the activity details.
- $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) );
- // 404 if activity does not exist
- if ( empty( $activity['activities'][0] ) ) {
- bp_do_404();
- return;
- } else {
- $activity = $activity['activities'][0];
- }
- // Do not redirect at default.
- $redirect = false;
- // Redirect based on the type of activity.
- if ( bp_is_active( 'groups' ) && $activity->component ==buddypress)->groups->id ) {
- // Activity is a user update.
- if ( ! empty( $activity->user_id ) ) {
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
- // Activity is something else.
- } else {
- // Set redirect to group activity stream.
- if ( $group = groups_get_group( $activity->item_id ) ) {
- $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';
- }
- }
- // Set redirect to users' activity stream.
- } elseif ( ! empty( $activity->user_id ) ) {
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
- }
- // If set, add the original query string back onto the redirect URL.
- if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
- $query_frags = array();
- wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags );
- $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect );
- }
- /**
- * Filter the intended redirect url before the redirect occurs for the single activity item.
- *
- * @since 1.2.2
- *
- * @param array $value Array with url to redirect to and activity related to the redirect.
- */
- if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) {
- }
- // Redirect to the actual activity permalink page.
- bp_core_redirect( $redirect );
- }