The following code snippet assumes a couple of things:
- You created the posts you’re loading to edit from a Gravity Form with a Feed
- You know the Post ID and the Form ID you’re loading into
<?php
/**
* Override the item ID that is edited by the Gravity Form when using a Pods feed.
*
* @param int $edit_id Edit ID.
* @param string $pod_name Pod name.
* @param int $form_id GF Form ID.
* @param array $feed GF Form feed array.
* @param array $form GF Form array.
* @param array $options Pods GF options.
* @param Pods $pod Pods object.
*
* @return int The edit ID to use.
*/
function my_custom_pods_gf_edit_id( $edit_id, $pod_name, $form_id, $feed, $form, $options, $pod ) {
// Only change the edit_id if this is for the form ID 123.
if ( 123 !== (int) $form_id ) {
return $edit_id;
}
// Check access rights, adjust this as needed.
if ( ! is_user_logged_in() || ! current_user_can( 'edit_posts' ) ) {
return $edit_id;
}
// Check if the edit_id passed into the URL was set.
if ( ! isset( $_GET['my_edit_id'] ) ) {
return $edit_id;
}
// Force the edit_id to one from the URL.
$edit_id = absint( $_GET['my_edit_id'] );
// Let's add the filter so we tell Pods to prepopulate the form with this item's data.
add_filter( 'pods_gf_addon_prepopulate', 'my_custom_pods_gf_prepopulate', 10, 7 );
return $edit_id;
}
add_filter( 'pods_gf_addon_edit_id', 'my_custom_pods_gf_edit_id', 10, 7 );
/**
* Override whether to prepopulate the form with the item being edited by the Gravity Form when using a Pods feed.
*
* @param bool $prepopulate Whether to prepopulate or not.
* @param string $pod_name Pod name.
* @param int $form_id GF Form ID.
* @param array $feed GF Form feed array.
* @param array $form GF Form array.
* @param array $options Pods GF options.
* @param Pods $pod Pods object.
*
* @return Whether to prepopulate the form with data from the item being edited.
*/
function my_custom_pods_gf_prepopulate( $prepopulate, $pod_name, $form_id, $feed, $form, $options, $pod ) {
// We added this filter when checking if they can edit, so we can trust this filter context.
// Always prepopulate the form with the item we are editing.
return true;
}