GravityView  2.17
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', 'gk-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', 'gk-gravityview' ),
33  'desc' => __( 'Enter text or HTML. Also supports shortcodes.', 'gk-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', 'gk-gravityview' ),
42  'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gk-gravityview' ),
43  'value' => '',
44  ),
45  'admin_label' => array(
46  'type' => 'text',
47  'class' => 'widefat',
48  'label' => __( 'Admin Label', 'gk-gravityview' ),
49  'desc' => __( 'A label that is only shown in the GravityView View configuration screen.', 'gk-gravityview' ),
50  'value' => '',
51  ),
52  );
53 
54  parent::__construct( __( 'Custom Content', 'gk-gravityview' ) , 'custom_content', $default_values, $settings );
55  }
56 
57  public function render_frontend( $widget_args, $content = '', $context = '') {
58 
59  if( !$this->pre_render_frontend() ) {
60  return;
61  }
62 
63  if( !empty( $widget_args['title'] ) ) {
64  echo $widget_args['title'];
65  }
66 
67 
68  // Make sure the class is loaded in DataTables
69  if( !class_exists( 'GFFormDisplay' ) ) {
70  include_once( GFCommon::get_base_path() . '/form_display.php' );
71  }
72 
73  $widget_args['content'] = trim( rtrim( \GV\Utils::get( $widget_args, 'content', '' ) ) );
74 
75  // No custom content
76  if( empty( $widget_args['content'] ) ) {
77  gravityview()->log->debug( 'No content.' );
78  return;
79  }
80 
81  // Add paragraphs?
82  if( !empty( $widget_args['wpautop'] ) ) {
83  $widget_args['content'] = wpautop( $widget_args['content'] );
84  }
85 
86  $content = $widget_args['content'];
87 
88  $content = GravityView_Merge_Tags::replace_variables( $content, array(), array(), false, true, false );
89 
90  // Enqueue scripts needed for Gravity Form display, if form shortcode exists.
91  // Also runs `do_shortcode()`
92  $content = GFCommon::gform_do_shortcode( $content );
93 
94 
95  // Add custom class
96  $class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
97  $class = gravityview_sanitize_html_class( $class );
98 
99  echo '<div class="gv-widget-custom-content '.$class.'">'. $content .'</div>';
100 
101  }
102 
103 }
104 
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()
If this file is called directly, abort.
if(empty( $field_settings['content'])) $content
Definition: custom.php:37
render_frontend( $widget_args, $content='', $context='')
gravityview()
The main GravityView wrapper function.