Handling results from data hooked into admin_post


I’m writing a plugin that uses a form to pass some data through to itself.

Is there any way to do this “The WordPress Way”?

Sample form code (on a custom submenu page added under “Tools”):

<form action="<?php echo get_admin_url() . 'admin-post.php'; ?>" method="post">
    <input name="some_input" type="text">
    <input name="other_input" type="text">

Then on the logic side of the plugin:

function my_process_form_data() {
    // Process the form data here and return the results
add_action( 'admin_post', 'my_process_form_data' );

Now that I’ve processed the form and have the resulting data (stored as a somewhat large array), what’s the best way to return that data to the custom submenu page I’ve created?

I understand there are a few options:

  • Instead of posting to “admin-post.php”, I could post directly to the page. But this makes for some messy code and conditionals (i.e. if results, load this, else, load this. Ideally the templating and the logic should be kept separate.
  • Use wp_redirect and store the data in the URL that it is redirecting to. But I have a large array of data to return to the end-user, so this isn’t really an option.
  • Serialize the data and store temporarily in the database, through transients or options, unsetting the data in the db once the user has seen it. But this feels very ‘hackish’.

Any suggestions how to get this large array of data back to my custom submenu page “the WordPress way”?

, member8888 7 years 2015-01-03T09:41:57-05:00 0 Answers 89 views 0

Leave an answer