[wp-hackers] Best way to kick off actual work from plugin settings page?

Jeff Waugh jdub at bethesignal.org
Mon Jul 12 08:18:54 UTC 2010


<quote who="Matt Jacob">

> User clicks a submit button that says 'Begin Upgrade' or something
> similar. Callback function checks for existence of that input field and
> fires off function to convert, e.g., 1000 records from custom DB table to
> custom post type records.
> 
> Maybe I'm getting too philosophical, but it seems like too much work to do
> from a function that's supposed to validate/sanitize inputs. I don't see a
> better way, though.

A delightful way to approach this might involve wp_schedule_single_event.

Grab (and filter) the input you need, then schedule an event to perform the
(potentially long running) function.

You can even schedule another event in the handler, so you can do the work
in a sliced up queue (if it's really that much).

Make sure that whatever you're doing has mid-process results, so you can
display progress on (most likely) your settings page.

For pure awesomeness, create an AJAX handler to provide mid-process results,
and add a little JavaScript on your settings page to show progress in almost
real time.

:-)

Thanks,

- Jeff

-- 
Ubuntu's Bleeding Edge                      http://ubuntuedge.wordpress.com/
 
     "They cosset us with trappings to shut us up. That way when we say
     'sharecropper!' you can point to my free suit and say 'Shut up pop
                          star.'" - Courtney Love


More information about the wp-hackers mailing list