Handle New Lines

Replace the \n new line terminator with an actual new line in template values. This is particularly useful in custom templates for Paragraph fields where you are outputting multiple object values.

Example:

Code

Filename: gppa-handle-new-lines.php

<?php
/**
 * Gravity Perks // Populate Anything // Handle New Lines
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * Replace the `\n` new line terminator with an actual new line in template values. This is particularly
 * useful in custom templates for Paragraph fields where you are outputting multiple object values.
 *
 * Example:
 *
 * ID: {post:ID}\nAuthor: {post:post_author}\nDate: {post:post_date}
 */
add_filter( 'gppa_process_template_value', function( $value, $field ) {
	if ( ! is_array( $value ) ) {
		$value = str_replace( '\n', "\n", $value );
	}
	return $value;
}, 10, 2 );

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.