Filter by Created By on Entry Edit

When filtering by the special Current User ID value, you may want to preserve the original context when editing an entry by returning the ID of the user who created the entry rather than the current user editing the entry.

Code

Filename: gppa-filter-by-created-by-on-entry-edit.php

<?php
/**
 * Gravity Perks // Populate Anything // Filter by Created By on Entry Edit
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * When filtering by the special Current User ID value, you may want to preserve the original context when editing an
 * entry by returning the ID of the user who created the entry rather than the current user editing the entry.
 */
add_filter( 'gform_replace_merge_tags', function( $value ) {
	if ( GFForms::get_page() === 'entry_detail_edit' ) {
		$entry = GFAPI::get_entry( rgget( 'lid' ) );
		if ( ! is_wp_error( $entry ) ) {
			$value = str_replace( 'special_value:current_user:ID', $entry['created_by'], $value );
		}
	}
	return $value;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.