1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Widget to add custom content |
5
|
|
|
* |
6
|
|
|
* @since 1.5.4 |
7
|
|
|
* |
8
|
|
|
* @extends GravityView_Widget |
9
|
|
|
*/ |
10
|
|
|
class GravityView_Widget_Custom_Content extends \GV\Widget { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Does this get displayed on a single entry? |
14
|
|
|
* @var boolean |
15
|
|
|
*/ |
16
|
|
|
protected $show_on_single = false; |
17
|
|
|
|
18
|
2 |
|
function __construct() { |
|
|
|
|
19
|
|
|
|
20
|
2 |
|
$this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview' ); |
|
|
|
|
21
|
|
|
|
22
|
|
|
$default_values = array( |
23
|
2 |
|
'header' => 1, |
24
|
|
|
'footer' => 1, |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$settings = array( |
28
|
2 |
|
'content' => array( |
29
|
2 |
|
'type' => 'textarea', |
30
|
2 |
|
'label' => __( 'Custom Content', 'gravityview' ), |
31
|
2 |
|
'desc' => __( 'Enter text or HTML. Also supports shortcodes.', 'gravityview' ), |
32
|
2 |
|
'value' => '', |
33
|
2 |
|
'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
|
2 |
|
'type' => 'checkbox', |
39
|
2 |
|
'label' => __( 'Automatically add paragraphs to content', 'gravityview' ), |
40
|
2 |
|
'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview' ), |
41
|
2 |
|
'value' => '', |
42
|
|
|
), |
43
|
|
|
); |
44
|
|
|
|
45
|
2 |
|
parent::__construct( __( 'Custom Content', 'gravityview' ) , 'custom_content', $default_values, $settings ); |
46
|
2 |
|
} |
47
|
|
|
|
48
|
1 |
|
public function render_frontend( $widget_args, $content = '', $context = '') { |
49
|
|
|
|
50
|
1 |
|
if( !$this->pre_render_frontend() ) { |
|
|
|
|
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
if( !empty( $widget_args['title'] ) ) { |
|
|
|
|
55
|
|
|
echo $widget_args['title']; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
59
|
|
|
// Make sure the class is loaded in DataTables |
60
|
1 |
|
if( !class_exists( 'GFFormDisplay' ) ) { |
|
|
|
|
61
|
|
|
include_once( GFCommon::get_base_path() . '/form_display.php' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
$widget_args['content'] = trim( rtrim( $widget_args['content'] ) ); |
65
|
|
|
|
66
|
|
|
// No custom content |
67
|
1 |
|
if( empty( $widget_args['content'] ) ) { |
68
|
|
|
gravityview()->log->debug( 'No content.' ); |
69
|
|
|
return; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Add paragraphs? |
73
|
1 |
|
if( !empty( $widget_args['wpautop'] ) ) { |
|
|
|
|
74
|
|
|
$widget_args['content'] = wpautop( $widget_args['content'] ); |
75
|
|
|
} |
76
|
|
|
|
77
|
1 |
|
$content = $widget_args['content']; |
78
|
|
|
|
79
|
1 |
|
$content = GravityView_Merge_Tags::replace_variables( $content, array(), array(), false, true, false ); |
80
|
|
|
|
81
|
|
|
// Enqueue scripts needed for Gravity Form display, if form shortcode exists. |
82
|
|
|
// Also runs `do_shortcode()` |
83
|
1 |
|
$content = GFCommon::gform_do_shortcode( $content ); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
86
|
|
|
// Add custom class |
87
|
1 |
|
$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : ''; |
|
|
|
|
88
|
1 |
|
$class = gravityview_sanitize_html_class( $class ); |
89
|
|
|
|
90
|
1 |
|
echo '<div class="gv-widget-custom-content '.$class.'">'. $content .'</div>'; |
|
|
|
|
91
|
|
|
|
92
|
1 |
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
new GravityView_Widget_Custom_Content; |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.