-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-gfnbtfieldaddon.php
137 lines (113 loc) · 3.81 KB
/
class-gfnbtfieldaddon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
GFForms::include_addon_framework();
class GFNBTFieldAddOn extends GFAddOn {
protected $_version = GF_NBT_FIELD_ADDON_VERSION;
protected $_min_gravityforms_version = '1.9';
protected $_slug = 'nbtfieldaddon';
protected $_path = 'nbtfieldaddon/nbtfieldaddon.php';
protected $_full_path = __FILE__;
protected $_title = 'New Blog Tempplates Add-On for Gravity Forms';
protected $_short_title = 'NBT Field Add-On';
/**
* @var object $_instance If available, contains an instance of this class.
*/
private static $_instance = null;
/**
* Returns an instance of this class, and stores it in the $_instance property.
*
* @return object $_instance An instance of this class.
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Include the field early so it is available when entry exports are being performed.
*/
public function pre_init() {
parent::pre_init();
if ( $this->is_gravityforms_supported() && class_exists( 'GF_Field' ) ) {
require_once( 'includes/class-nbt-gf-field.php' );
}
}
public function init_admin() {
parent::init_admin();
add_filter( 'gform_tooltips', array( $this, 'tooltips' ) );
add_action( 'gform_field_appearance_settings', array( $this, 'field_appearance_settings' ), 10, 2 );
}
// # SCRIPTS & STYLES -----------------------------------------------------------------------------------------------
/**
* Include my_script.js when the form contains a 'wpmudevnbt' type field.
*
* @return array
*/
public function scripts() {
$scripts = array(
array(
'handle' => 'my_script_js',
'src' => $this->get_base_url() . '/js/my_script.js',
'version' => $this->_version,
'deps' => array( 'jquery' ),
'enqueue' => array(
array( 'field_types' => array( 'wpmudevnbt' ) ),
),
),
);
return array_merge( parent::scripts(), $scripts );
}
/**
* Include my_styles.css when the form contains a 'wpmudevnbt' type field.
*
* @return array
*/
public function styles() {
$styles = array(
array(
'handle' => 'nbtfieldaddon_styles_css',
'src' => $this->get_base_url() . '/css/nbtfieldaddon.css',
'version' => $this->_version,
'enqueue' => array(
array( 'field_types' => array( 'wpmudevnbt' ) )
)
)
);
return array_merge( parent::styles(), $styles );
}
// # FIELD SETTINGS -------------------------------------------------------------------------------------------------
/**
* Add the tooltips for the field.
*
* @param array $tooltips An associative array of tooltips where the key is the tooltip name and the value is the tooltip.
*
* @return array
*/
public function tooltips( $tooltips ) {
$nbt_tooltips = array(
'input_class_setting' => sprintf( '<h6>%s</h6>%s', esc_html__( 'Input CSS Classes', 'nbtfieldaddon' ), esc_html__( 'The CSS Class names to be added to the field input.', 'nbtfieldaddon' ) ),
);
return array_merge( $tooltips, $nbt_tooltips );
}
/**
* Add the custom setting for the Simple field to the Appearance tab.
*
* @param int $position The position the settings should be located at.
* @param int $form_id The ID of the form currently being edited.
*/
public function field_appearance_settings( $position, $form_id ) {
// Add our custom setting just before the 'Custom CSS Class' setting.
if ( $position == 250 ) {
?>
<li class="input_class_setting field_setting">
<label for="input_class_setting">
<?php esc_html_e( 'Input CSS Classes', 'nbtfieldaddon' ); ?>
<?php gform_tooltip( 'input_class_setting' ) ?>
</label>
<input id="input_class_setting" type="text" class="fieldwidth-1" onkeyup="SetInputClassSetting(jQuery(this).val());" onchange="SetInputClassSetting(jQuery(this).val());"/>
<select>
</li>
<?php
}
}
}