forked from leepeterson/gravityblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-gf-gutenberg.php
More file actions
272 lines (231 loc) · 5.12 KB
/
class-gf-gutenberg.php
File metadata and controls
272 lines (231 loc) · 5.12 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
// If Gravity Forms cannot be found, exit.
if ( ! class_exists( 'GFForms' ) ) {
die();
}
// Load Add-On Framework.
GFForms::include_addon_framework();
/**
* Gutenberg integration using the Add-On Framework.
*
* @see GFAddOn
*/
class GF_Gutenberg extends GFAddOn {
/**
* Contains an instance of this class, if available.
*
* @since 1.0
* @access private
* @var GF_Gutenberg $_instance If available, contains an instance of this class.
*/
private static $_instance = null;
/**
* Defines the version of the Gutenberg Add-On.
*
* @since 1.0
* @access protected
* @var string $_version Contains the version, defined in gutenberg.php
*/
protected $_version = GF_GUTENBERG_VERSION;
/**
* Defines the minimum Gravity Forms version required.
*
* @since 1.0
* @access protected
* @var string $_min_gravityforms_version The minimum version required.
*/
protected $_min_gravityforms_version = '2.2';
/**
* Defines the plugin slug.
*
* @since 1.0
* @access protected
* @var string $_slug The slug used for this plugin.
*/
protected $_slug = 'gravityformsgutenberg';
/**
* Defines the main plugin file.
*
* @since 1.0
* @access protected
* @var string $_path The path to the main plugin file, relative to the plugins folder.
*/
protected $_path = 'gravityformsgutenberg/gutenberg.php';
/**
* Defines the full path to this class file.
*
* @since 1.0
* @access protected
* @var string $_full_path The full path.
*/
protected $_full_path = __FILE__;
/**
* Defines the URL where this Add-On can be found.
*
* @since 1.0
* @access protected
* @var string The URL of the Add-On.
*/
protected $_url = 'http://www.gravityforms.com';
/**
* Defines the title of this Add-On.
*
* @since 1.0
* @access protected
* @var string $_title The title of the Add-On.
*/
protected $_title = 'Gravity Forms Gutenberg Add-On';
/**
* Defines the short title of the Add-On.
*
* @since 1.0
* @access protected
* @var string $_short_title The short title.
*/
protected $_short_title = 'Gutenberg';
/**
* Defines if Add-On should use Gravity Forms servers for update data.
*
* @since 1.0
* @access protected
* @var bool
*/
protected $_enable_rg_autoupgrade = true;
/**
* Get instance of this class.
*
* @since 1.0
* @access public
* @static
*
* @return GF_Gutenberg
*/
public static function get_instance() {
if ( null === self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
// # HELPER METHODS ------------------------------------------------------------------------------------------------
/**
* Get forms for block control.
*
* @since 1.0-dev-1
* @access public
*
* @uses GFAPI::get_forms()
*
* @return array
*/
public function get_forms() {
// Initialize options array.
$options = array(
array(
'label' => esc_html__( 'Select a Form', 'gravityforms' ),
'value' => '',
),
);
// Get forms.
$forms = GFAPI::get_forms();
// Loop through forms.
foreach ( $forms as $form ) {
// Add form as option.
$options[] = array(
'label' => $form['title'],
'value' => $form['id'],
);
}
return $options;
}
/**
* Get options for the conditional logic drop downs.
*
* @since 1.0-dev-3
* @access public
*
* @uses GF_Gutenberg::get_roles()
*
* @return array
*/
public function get_conditional_options() {
return array(
array(
'key' => array(
'label' => esc_html__( 'User', 'gravityforms' ),
'value' => 'user',
),
'operators' => array(
array(
'label' => 'is',
'value' => 'is',
),
array(
'label' => 'is not',
'value' => 'isnot',
),
),
'value' => array(
'type' => 'select',
'choices' => array(
array(
'label' => esc_html__( 'Logged In', 'gravityforms' ),
'value' => 'logged-in',
),
array(
'label' => esc_html__( 'Logged Out', 'gravityforms' ),
'value' => 'logged-out',
),
array(
'label' => esc_html__( 'Roles', 'gravityforms' ),
'choices' => $this->get_roles(),
),
),
),
),
array(
'key' => array(
'label' => esc_html__( 'Date', 'gravityforms' ),
'value' => 'date',
),
'operators' => array(
array(
'label' => 'is before',
'value' => 'greater_than',
),
array(
'label' => 'is after',
'value' => 'less_than',
),
),
'value' => array(
'type' => 'date',
),
),
);
}
/**
* Get available roles for block control.
*
* @since 1.0-dev-3
* @access public
*
* @return array
*/
public function get_roles() {
// Load needed function file.
if ( ! function_exists( 'get_editable_roles' ) ) {
require_once( ABSPATH . '/wp-admin/includes/user.php' );
}
// Initialize roles array.
$roles = array();
// Loop through roles.
foreach ( get_editable_roles() as $role_name => $role ) {
// Add role as option.
$roles[] = array(
'label' => $role['name'],
'value' => $role_name,
);
}
return $roles;
}
}