GravityExport field: MetaField

Gravity Forms adds some data on top of the fields in a form. Things like an IP address, a timestamp, etc. All this meta data is being provided by a single meta  field. Therefor we created this MetaField  class. This way you can target every individual meta field in the export for changing, and it has it’s own filters.

Because these meta fields closely resemble the other fields, the plugin has a tiny meta fields Transformer  baked in. This allows you to (also) register your own (custom) MetaField  instances. You can add your fields via the filter. The plugin actually already has a custom MetaField  called DateCreatedField.

Filters

  • gfexcel_meta_value_{field_id}_{form_id}

    Just as it’s big brother for the field value, this filter can change the value of this meta field. The extra options are reversed on purpose, because it’s more likely you’ll want to change every meta field (type), that for a specific form.

/**
 * Filters the exported IP meta value in GravityExport exports.
 *
 * This hook allows you to modify the IP address value before it’s written to the export file.
 * In this example, a prefix is added before the IP address.
 *
 * @since 1.0.0
 *
 * @param string   $value The original IP address value.
 * @param array    $entry The full Gravity Forms entry array.
 * @param GF_Field $field The field object associated with the meta value (if applicable).
 *
 * @return string The modified IP address value.
 */
add_filter(
	'gfexcel_meta_value_ip',
	function ( $value, $entry, $field ) {
		return 'IP:' . $value;
	},
	10,
	3
);

  • gfexcel_transformer_subfields

    This filter allows you to add your own (custom) MetaField  instance for a specific type. Let say you created a IpAddressField  and you want to register it for the ip  field.

Example

/**
 * Registers a custom transformer class for specific subfields in GravityExport.
 *
 * This filter allows you to define custom logic for transforming the value
 * of specific subfields during export by mapping a subfield key to a fully qualified class name.
 *
 * @since 1.0.0
 *
 * @param array $fields An associative array of subfield keys mapped to their transformer classes.
 *                      Example: [ 'ip' => 'Your\Full\Namespace\IpAddressField' ].
 *
 * @return array The modified array of subfield transformer mappings.
 */
add_filter(
	'gfexcel_transformer_subfields',
	function ( $fields ) {
		$fields['ip'] = 'Your\Full\Namespace\IpAddressField';
		return $fields;
	}
);

DateCreatedField

This actually is a custom MetaField  instance, that allows you to split the timestamp into two fields; Date  and Time .

Filters

  • gfexcel_meta_date_created_separated_{form_id} allows you to separate the timestamp into two fields.

Example

/**
 * Splits the "date_created" meta field into separate date and time columns
 * in GravityExport exports.
 *
 * By returning true, the export will include two columns:
 * one for the date and another for the time of entry creation.
 *
 * @since 1.0.0
 *
 * @return bool True to separate the date_created field into date and time fields.
 */
add_filter( 'gfexcel_meta_date_created_separated', '__return_true' );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us