Skip to:
Content

BuddyPress.org

Ticket #2002: 2002.002.diff

File 2002.002.diff, 5.5 KB (added by cnorris23, 9 years ago)

redirect via query arg

  • bp-activity.php

     
    280280}
    281281add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
    282282
     283/**
     284 * bp_activity_action_delete_activity()
     285 *
     286 * Delete specific activity item and redirect to previous page ( if applicable ).
     287 *
     288 * @package BuddyPress Activity
     289 * @since 1.1
     290 *
     291 * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions
     292 *      to be taken before the activity is deleted.     
     293 * @uses bp_activity_delete()
     294 * @uses bp_core_add_message()
     295 * @uses bp_core_redirect()
     296 *
     297 * @global object $bp
     298 */
    283299function bp_activity_action_delete_activity() {
    284300        global $bp;
    285301
     
    289305        if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
    290306                return false;
    291307
    292         /* Check the nonce */
     308        // Check the nonce
    293309        check_admin_referer( 'bp_activity_delete_link' );
    294310
    295311        $activity_id = $bp->action_variables[0];
    296312        $activity = new BP_Activity_Activity( $activity_id );
    297313
    298         /* Check access */
     314        // Check access
    299315        if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
    300316                return false;
    301 
     317       
    302318        /* Call the action before the delete so plugins can still fetch information about it */
    303319        do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
    304320
    305         /* Now delete the activity item */
     321        // Always redirect somewhere
     322        $bp_redirect_to = $bp->root_domain;
     323
     324        // Check for the redirect query arg, otherwise let WP handle things
     325        if ( isset( $_GET['bp_redirect_to'] ) ) {
     326                $bp_redirect_to = $_GET['bp_redirect_to'];
     327        } else {
     328                $bp_redirect_to = wp_get_referer();
     329        }
     330
     331        // Now delete the activity item
    306332        if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
    307333                bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
    308334        else
    309335                bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
    310336
    311         bp_core_redirect( wp_get_referer() );
     337        bp_core_redirect( $bp_redirect_to );
    312338}
    313339add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
    314340
  • bp-themes/bp-default/_inc/ajax.php

     
    221221}
    222222add_action( 'wp_ajax_new_activity_comment', 'bp_dtheme_new_activity_comment' );
    223223
    224 /* AJAX delete an activity */
     224/**
     225 * bp_dtheme_delete_activity()
     226 *
     227 * Delete specific activity item via AJAX.
     228 *
     229 * @since 1.2
     230 *
     231 * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow action
     232 *      to be taken before the activity is deleted.     
     233 * @uses bp_activity_delete()
     234 *
     235 * @global object $bp BuddyPress global settings
     236 * @return bool False on failure. True if activity deleted.
     237 */
    225238function bp_dtheme_delete_activity() {
    226239        global $bp;
    227240
  • bp-activity/bp-activity-templatetags.php

     
    841841                return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
    842842        }
    843843
     844/**
     845 * bp_activity_delete_link()
     846 *
     847 * Display the activity delete link.
     848 *
     849 * @package BuddyPress Activity
     850 * @since 1.1
     851 *
     852 * @uses bp_get_activity_delete_link()
     853 */
    844854function bp_activity_delete_link() {
    845855        echo bp_get_activity_delete_link();
    846856}
     857        /**
     858         * bp_get_activity_delete_link()
     859         *
     860         * Return the activity delete link.
     861         *
     862         * @package BuddyPress Activity
     863         * @since 1.1
     864         *
     865         * @uses apply_filters() Calls 'bp_get_activity_delete_link' hook to allow altering
     866         *      of the activity delete link.   
     867         * @uses wp_nonce_url()
     868         * @uses add_query_arg()
     869         * @uses wp_get_referer()
     870         *
     871         * @global object $bp BuddyPress global settings
     872         * @global object $activities_template BuddyPress Activities Template
     873         * @return string Activity delete link. Contains $bp_redirect_to arg if on single activity page.
     874         */
    847875        function bp_get_activity_delete_link() {
    848876                global $activities_template, $bp;
    849877
    850                 return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>' );
     878                // Determine if we're on a single activity page, and customize accordingly
     879                if ( !empty( $bp->current_component ) && $bp->current_component == BP_ACTIVITY_SLUG && !empty( $bp->current_action ) && is_numeric( $bp->current_action ) )
     880                        return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( add_query_arg( array( 'bp_redirect_to' => wp_get_referer() ), $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id ), 'bp_activity_delete_link' ) . '" class="item-button delete-single-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>' );
     881                else
     882                        return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>' );
    851883        }
    852884
    853885function bp_activity_latest_update( $user_id = false ) {