On my site I have a form that can be filled out by users. Once submitted, I am storing the form data in a third-party service using their RESTful API.

function gravity_forms_1_after_submission( $entry, $form ) {
    if ( rgar( $entry, 'status' ) === 'spam' ) {

    $response = wp_remote_post(
        esc_url_raw( '...' ),
            'headers' => array(
            'body' => json_encode( array(
            ) )

    if ( is_wp_error( $response ) ) {
    } else {

add_action( 'gform_after_submission_1', 'gravity_forms_1_after_submission', 10, 2 );

For cases where the API is down or there is a problem along the way, so that no data is lost, I want to code an auto-retry feature - if the first API call fails, there will be subsequent tries later until the data is successfully sent. (By subsequent tries I do not mean immediately after, since the API might be down, but maybe 5 minutes later, then 30 minutes later, then 2 hours later, until the call is successful.)

How would I go about coding that in WordPress?

1 Answer 1


First you should save the data somewhere in your wordpress. I personally like to use custom tables. Then use a schedule (cron job) to check if there is new data. Then try to submit the data. If you sumitted the data successfully delete it or mark your local data as successfully submitted. Else retry it with the next schedule run. If you want to increase the waiting time with every try you could save the retry count on your local dataset.

  • 1
    The data will already be stored in wp_gf_entry and entrymeta, you don't need any extra tables. But yes, I'd store a 'submitted' flag in entrymeta and set up a scheduled job to look for entries that don't have the flag and retry them. I expect there are gf_* apis to search and fetch the records but I don't know them.
    – Rup
    May 20, 2021 at 11:10
  • Edward, please cut down on self-promotion (links to your own external content).
    – Christine Cooper
    Jun 28, 2021 at 10:08

Your Answer

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

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