GravityKit/GravityView

Redirect after duplicate

rafaehlers opened this issue · 0 comments

Context

It seems like there are plenty of folks who want this functionality: https://secure.helpscout.net/search/?query=tag%3Aduplicate%20entries%20redirect

I know we have the gravityview/duplicate-entry/duplicated hook but perhaps it's time to implement an UI for that?

The idea is to mimic the functionality already present in the Delete tab, but for duplicating entries. I think we can even use the same tab to avoid creating a new one since the Delete tab only has two items.

image

Code suggestion:

add_action( 'gravityview/duplicate-entry/duplicated', 'gk_run_stuff_after_duplication', 10, 2 );
function gk_run_stuff_after_duplication( $duplicated_entry, $entry ) {
    $form_id = $duplicated_entry['form_id'];
    
    $run_on_forms = [157]; // The IDs of the Forms you'd like to affect.

    if ( ! in_array( $form_id, $run_on_forms ) ) {
        return;
    }

    // Redirect to the desired URL.
    $url = 'http://www.website.com/page/';
    wp_redirect( $url );
    exit;
}