Skip to:
Content

BuddyPress.org

Changeset 8934


Ignore:
Timestamp:
08/17/2014 06:11:40 PM (10 years ago)
Author:
boonebgorges
Message:

BP_Group_Extension should automatically handle redirects after the 'edit' screen save routine

After handling POSTed settings save on the 'edit' view of a BP_Group_Extension
plugin, plugins were previously required to handle their own redirects
(primarily to avoid "are you sure you want to resubmit the data?" browser
prompts when reloading the page). This created a disparity between the 'edit'
screen and the 'create' and 'admin' screens, the latter two of which handled
their own redirect logic.

This changeset performs the necessary redirect after calling the edit screen
save callback. There is some logic in place to ensure that no double redirects
take place.

Fixes #5557

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-classes.php

    r8829 r8934  
    30023002
    30033003    /**
     3004     * Redirect location as defined by post-edit save callback.
     3005     *
     3006     * @since BuddyPress (2.1.0)
     3007     * @var string
     3008     */
     3009    protected $post_save_redirect;
     3010
     3011    /**
    30043012     * Miscellaneous data as set by the __set() magic method.
    30053013     *
     
    36903698
    36913699        $this->check_nonce( 'edit' );
     3700
     3701        // Detect whether the screen_save_callback is performing a
     3702        // redirect, so that we don't do one of our own
     3703        add_filter( 'wp_redirect', array( $this, 'detect_post_save_redirect' ) );
     3704
     3705        // Call the extension's save routine
    36923706        call_user_func( $this->screens['edit']['screen_save_callback'], $this->group_id );
     3707
     3708        // Clean up detection filters
     3709        remove_filter( 'wp_redirect', array( $this, 'detect_post_save_redirect' ) );
     3710
     3711        // Perform a redirect only if one has not already taken place
     3712        if ( empty( $this->post_save_redirect ) ) {
     3713            $redirect_to = apply_filters( 'bp_group_extension_edit_screen_save_redirect', bp_get_requested_url( ) );
     3714
     3715            bp_core_redirect( $redirect_to );
     3716            die();
     3717        }
    36933718    }
    36943719
     
    37523777        preg_match( $pattern, $screen, $matches );
    37533778        return ! empty( $matches[0] );
     3779    }
     3780
     3781    /**
     3782     * Detect redirects hardcoded into edit_screen_save() callbacks.
     3783     *
     3784     * @since BuddyPress (2.1.0)
     3785     *
     3786     * @param string $location
     3787     * @return string
     3788     */
     3789    public function detect_post_save_redirect( $redirect = '' ) {
     3790        if ( ! empty( $redirect ) ) {
     3791            $this->post_save_redirect = $redirect;
     3792        }
     3793
     3794        return $redirect;
    37543795    }
    37553796
Note: See TracChangeset for help on using the changeset viewer.