[wp-hackers] Redirecting Users In Admin To Avoid Resubmitting Information

Austin Matzko if.website at gmail.com
Sun Oct 25 03:46:13 UTC 2009


On Sat, Oct 24, 2009 at 10:37 PM, raj <websweetweb at gmail.com> wrote:
> I am creating a simple create, edit, update, delete [something] wordpress
> plugin.
> In the create screen, the user inserts something in the database and is sent
> to the
> confirmation message. But the data gets inserted again if the user refreshes
> the page.
>
> How do you handle this? How do you 'redirect' users to a different
> location such that once they get there, the action shouldn't be
> performed again if they refresh that page.

Do what core WP does: perform the data operations before the page is
printed (say on the "admin_init" action or the like), and then use
wp_redirect() to redirect to a page with an argument that specifies
the message to show.

For example, after submitting the Settings > General page, one is
redirected to wp-admin/options-general.php?updated=true, and that
"updated" $_GET parameter is detected and the message "Settings
saved." printed.


More information about the wp-hackers mailing list