michaelbourne / gravity-forms-zoom-webinar-registration

Register attendees in your Zoom Webinar through a Gravity Form
GNU General Public License v3.0
25 stars 12 forks source link

How do I know an entry has registered successfully? #9

Closed apos37 closed 2 years ago

apos37 commented 2 years ago

Great plugin. Been using it for awhile now. Thank you! Now I need to update the user's meta (which I know how to do) when an entry has successfully registered them on Zoom. Do you have an action that I can hook into or a function that checks this that I can call when the form has been submitted? Also, as far as I can tell, I don't see a way to check for previous entries that have registered is there?

apos37 commented 2 years ago

Nevermind, I used a GF hook to fire after the feed is processed:

add_action( 'gform_gravity-forms-zoom-webinar-registration_post_process_feed', 'live_post_process', 10, 4 );
function live_post_process( $feed, $entry, $form, $addon ) {
    // Get the form fields
    $fields = $form['fields'];

    // Find the access id field
    $access_id_field = 0;
    foreach ($fields as $field) {
        if (strpos(strtolower($field->label), '{aid_field}') !== false) {
            $access_id_field = $field->id;
            break;
        }
    }

    // If we found one, let's continue
    if ($access_id_field > 0 && isset($entry[$access_id_field])) {

        // Get the access id value from the entry field
        $access_id = $entry[$access_id_field];

        // Get the user id
        $user_id = $entry['created_by'];

        // Add the access id to the user's meta
        update_user_meta( $user_id, 'access_id', $access_id );

        // Indicate that this was a live registration on the entry meta
        $entry['live_registration'] = true;

        // Update the entry
        GFAPI::update_entry( $entry );
    }
}

In order to add the meta to entry, the meta key needs to be added.

// Add entry meta for live registrations
add_filter( 'gform_entry_meta', 'add_live_entry_meta', 10, 2 );
function add_live_entry_meta( $entry_meta, $form_id ) {
    $entry_meta['live_registration'] = array(
        'label' => 'Live Registration',
        'is_numeric' => false,
        'update_entry_meta_callback' => [$this, 'default_live_entry_meta'],
        'is_default_column' => false
    );
    return $entry_meta;
}

// Default value upon form submission or editing an entry
function default_live_entry_meta( $key, $entry, $form ) {
    return;
}

// Change the column content to "Yes" instead of 1 if true
add_action( 'gform_entries_field_value', 'live_col_content', 10, 4 );
function live_col_content( $value, $form_id, $field_id, $entry ) {
    // Targeting this field only
    if ( $field_id == 'live_registration' && isset($value) && $value == 1) {
        $value = 'Yes';
    }

    // Return the value
    return $value;
}