Skip to content

Instantly share code, notes, and snippets.

@geekontheroad
Created September 8, 2024 11:04
Show Gist options
  • Save geekontheroad/91bdf646326a361a166bb2f84451341a to your computer and use it in GitHub Desktop.
Save geekontheroad/91bdf646326a361a166bb2f84451341a to your computer and use it in GitHub Desktop.
<?php
/**
* This function is for Gravity Forms and can be used to bulk update the source url of all entries of a form
*
* @author Johan d'Hollander
* @link https://geekontheroad.com
**/
function update_form_entries_source_url( $form_id, $source_url ) {
// Get all entries for the given form ID
$search_criteria = array('status' => 'active');
$paging = array( 'offset' => 0, 'page_size' => 200 );
$entries = GFAPI::get_entries( $form_id, $search_criteria, null, $paging );
if ( is_wp_error( $entries ) ) {
error_log( 'Error fetching entries: ' . $entries->get_error_message() );
return false;
}
foreach ( $entries as $entry ) {
$escaped_url = json_encode( $source_url );
$escaped_url = trim( $escaped_url, '"' );
$entry['source_url'] = $escaped_url;
// Save the updated entry
$result = GFAPI::update_entry( $entry );
if ( is_wp_error( $result ) ) {
error_log( 'Error updating entry ID ' . $entry['id'] . ': ' . $result->get_error_message() );
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment