GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-widget-custom-content.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Widget to add custom content
5  *
6  * @since 1.5.4
7  *
8  * @extends GravityView_Widget
9  */
11 
12  /**
13  * Does this get displayed on a single entry?
14  * @var boolean
15  */
16  protected $show_on_single = false;
17 
18  function __construct() {
19 
20  $this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview' );
21 
22  $default_values = array(
23  'header' => 1,
24  'footer' => 1,
25  );
26 
27  $settings = array(
28  'content' => array(
29  'type' => 'textarea',
30  'label' => __( 'Custom Content', 'gravityview' ),
31  'desc' => __( 'Enter text or HTML. Also supports shortcodes.', 'gravityview' ),
32  'value' => '',
33  'class' => 'code',
34  'merge_tags' => false,
35  'show_all_fields' => true, // Show the `{all_fields}` and `{pricing_fields}` merge tags
36  ),
37  'wpautop' => array(
38  'type' => 'checkbox',
39  'label' => __( 'Automatically add paragraphs to content', 'gravityview' ),
40  'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview' ),
41  'value' => '',
42  ),
43  );
44 
45  parent::__construct( __( 'Custom Content', 'gravityview' ) , 'custom_content', $default_values, $settings );
46  }
47 
48  public function render_frontend( $widget_args, $content = '', $context = '') {
49 
50  if( !$this->pre_render_frontend() ) {
51  return;
52  }
53 
54  if( !empty( $widget_args['title'] ) ) {
55  echo $widget_args['title'];
56  }
57 
58 
59  // Make sure the class is loaded in DataTables
60  if( !class_exists( 'GFFormDisplay' ) ) {
61  include_once( GFCommon::get_base_path() . '/form_display.php' );
62  }
63 
64  $widget_args['content'] = trim( rtrim( $widget_args['content'] ) );
65 
66  // No custom content
67  if( empty( $widget_args['content'] ) ) {
68  do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: No content.', get_class($this)) );
69  return;
70  }
71 
72  // Add paragraphs?
73  if( !empty( $widget_args['wpautop'] ) ) {
74  $widget_args['content'] = wpautop( $widget_args['content'] );
75  }
76 
77  $content = $widget_args['content'];
78 
80 
81  // Enqueue scripts needed for Gravity Form display, if form shortcode exists.
82  // Also runs `do_shortcode()`
83  $content = GFCommon::gform_do_shortcode( $content );
84 
85 
86  // Add custom class
87  $class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
88  $class = gravityview_sanitize_html_class( $class );
89 
90  echo '<div class="gv-widget-custom-content '.$class.'">'. $content .'</div>';
91 
92  }
93 
94 }
95 
Main GravityView widget class.
$class
render_frontend($widget_args, $content= '', $context= '')
static replace_variables($text, $form=array(), $entry=array(), $url_encode=false, $esc_html=true)
Alias for GFCommon::replace_variables()
pre_render_frontend()
General validations when rendering the widget.
if(empty($field_settings['content'])) $content
Definition: custom.php:37