spivurno
11/1/2014 - 10:54 PM

Gravity Perks // GP Terms of Service Field // Add Support for Using Shortcodes in Terms Field

Gravity Perks // GP Terms of Service Field // Add Support for Using Shortcodes in Terms Field

/**
 * Gravity Perks // GP Terms of Service Field // Add Support for Using Shortcodes in Terms Field
 * http://gravitywiz.com/documentation/gp-terms-of-service/
 *
 * This plug-in-play snippet adds support for shortcodes in terms. It will automatically convert the ToS fields for the given
 * form into the HTML-enabled version (default uses <textarea> which does not support HTML).
 *
 * One way this snippet can be used is in conjuction with the [Post Content Shortcodes](https://wordpress.org/plugins/post-content-shortcodes/)
 * which provides a shortcode to retrive the content of a post. You can keep your terms in a single post and then use a
 * shortcode (i.e. [post-content id="12"])to display those terms in all of your ToS fields.
 */
add_filter( 'gform_pre_render', 'gw_add_terms_shortcode_support' );
function gw_add_terms_shortcode_support( $form ) {

	$did_shortcodes = false;

	foreach( $form['fields'] as &$field ) {
		if( $field['type'] == 'tos' ) {
			$did_shortcodes = true;
			$field['gwtermsofservice_terms'] = do_shortcode( $field['gwtermsofservice_terms'] );
		}
	}

	if( $did_shortcodes ) {
		add_action( "gptos_terms_container_tag_{$form['id']}", create_function( '$tag', 'return "div";' ) );
	}

	return $form;
}