Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/5727f3c54410feee6a5b to your computer and use it in GitHub Desktop.
Save spivurno/5727f3c54410feee6a5b to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment