How to achieve Post-Redirect-Get on Wordpress Plugin Admin Menu Page?

I am writing a Wordpress plugin that adds an admin menu page. There is a form on the page. When the form is submitted, the plugin writes to the database. But then I came across a problem: whenever the user reloads the page, they ask him whether to send POSTDATA again. If the user clicks "Yes", the plugin writes to the database again.

After some searching, I found a solution, the "Post-Redirect-Get" template. Then, later, I found it difficult to implement this template in the Wordpress plugin.

  • The plugin itself cannot send HTTP 301/302, because there is some content already issued by the Wordpress core.

  • You can insert a meta tag in the HTML header (in order to issue a redirect). But according to the W3C, the meta redirect is out of date, so I think it's best not to use it.

  • Use JavaScript window.location . But what if JavaScript is disabled in the user's browser?

Is there any other way to redirect?

+4
source share
3 answers

You can try to do your plugin handling in the admin_init hook, which, I believe, is executed before any content is output.

+8
source

To save a lot of work. Just use the WordPress api settings.

Codex Article โ†’ here

Otto's more useful article โ†’ here

Using the WordPress settings, the api will take care of the "Post-Redirect-Get" problem that you are describing.

+1
source
  • check if the table exists in the database or insert in sql if no exists for inaction, if the table exists in the database.

  • option set_option, in which the plugin is activated.

  • use register_activation_hook wordpress function to enable activation activation plugin

Sorry for my english, very bad, but I think you can understand

0
source

All Articles