0

So, I have the following code:

    <?php if ( I_delete_user($user_id) || $demo_site->request_verification($user_id) || isset( $args["{$template}_button_primary"] ) || isset( $args["{$template}_button_secondary"] ) ) { ?>
        <div class="submit_it">             
            <?php if (isset($args["{$template}_button_primary"]) ) { ?>
                <input type="submit" value="<?php echo $args["{$template}_button_primary"]; ?>" class="my-button" />
            <?php } ?>
        </div>
    <?php } ?>

Users can upload their picture and save it by clicking "submit" button while staying in the page.

I am trying to add a function so that when an user clicks this "submit" button on a specific page (post_id of 222, for example), the user is redirected to a different page (demo.com/another_page) once the save is done.

I am not sure how to go about it.

Any suggestions?

Thanks

1 Answer 1

1

You will need to use a hook (such as init or admin_init) to detect whether a condition has been met. For instance, the existence of a certain querystring variable (which can be a url encoded url, if you like).

When the condition is met, use wp_safe_redirect() (and optionally exit()) to redirect to the URL you want. You can either hard-code that URL or fetch it from the querystring if your button passed it along as a urlencoded variable.

Hypothetical example (PHP 5.3+ syntax):

add_action('init', function(){
    if ( isset($_REQUEST['redirect_to']) ) {
        wp_safe_redirect($_REQUEST['redirect_to']);
        exit();
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.