GravityView  2.10.1
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  public $icon = 'dashicons-editor-code';
13 
14  /**
15  * Does this get displayed on a single entry?
16  * @var boolean
17  */
18  protected $show_on_single = false;
19 
20  function __construct() {
21 
22  $this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview' );
23 
24  $default_values = array(
25  'header' => 1,
26  'footer' => 1,
27  );
28 
29  $settings = array(
30  'content' => array(
31  'type' => 'textarea',
32  'label' => __( 'Custom Content', 'gravityview' ),
33  'desc' => __( 'Enter text or HTML. Also supports shortcodes.', 'gravityview' ),
34  'value' => '',
35  'class' => 'code',
36  'merge_tags' => false,
37  'show_all_fields' => true, // Show the `{all_fields}` and `{pricing_fields}` merge tags
38  ),
39  'wpautop' => array(
40  'type' => 'checkbox',
41  'label' => __( 'Automatically add paragraphs to content', 'gravityview' ),
42  'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview' ),
43  'value' => '',
44  ),
45  );
46 
47  parent::__construct( __( 'Custom Content', 'gravityview' ) , 'custom_content', $default_values, $settings );
48  }
49 
50  public function render_frontend( $widget_args, $content = '', $context = '') {
51 
52  if( !$this->pre_render_frontend() ) {
53  return;
54  }
55 
56  if( !empty( $widget_args['title'] ) ) {
57  echo $widget_args['title'];
58  }
59 
60 
61  // Make sure the class is loaded in DataTables
62  if( !class_exists( 'GFFormDisplay' ) ) {
63  include_once( GFCommon::get_base_path() . '/form_display.php' );
64  }
65 
66  $widget_args['content'] = trim( rtrim( \GV\Utils::get( $widget_args, 'content' ) ) );
67 
68  // No custom content
69  if( empty( $widget_args['content'] ) ) {
70  gravityview()->log->debug( 'No content.' );
71  return;
72  }
73 
74  // Add paragraphs?
75  if( !empty( $widget_args['wpautop'] ) ) {
76  $widget_args['content'] = wpautop( $widget_args['content'] );
77  }
78 
79  $content = $widget_args['content'];
80 
81  $content = GravityView_Merge_Tags::replace_variables( $content, array(), array(), false, true, false );
82 
83  // Enqueue scripts needed for Gravity Form display, if form shortcode exists.
84  // Also runs `do_shortcode()`
85  $content = GFCommon::gform_do_shortcode( $content );
86 
87 
88  // Add custom class
89  $class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
90  $class = gravityview_sanitize_html_class( $class );
91 
92  echo '<div class="gv-widget-custom-content '.$class.'">'. $content .'</div>';
93 
94  }
95 
96 }
97 
pre_render_frontend()
General validations when rendering the widget.
$class
static replace_variables( $text, $form=array(), $entry=array(), $url_encode=false, $esc_html=true, $nl2br=true, $format='html', $aux_data=array())
Alias for GFCommon::replace_variables()
gravityview()
Definition: _stubs.php:26
get( $key, $default=null)
Retrieve a setting.
If this file is called directly, abort.
if(empty( $field_settings['content'])) $content
Definition: custom.php:37
render_frontend( $widget_args, $content='', $context='')