1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Set of functions to separate main plugin from Gravity Forms API and other methods |
4
|
|
|
* |
5
|
|
|
* @package GravityView |
6
|
|
|
* @license GPL2+ |
7
|
|
|
* @author Katz Web Services, Inc. |
8
|
|
|
* @link http://gravityview.co |
9
|
|
|
* @copyright Copyright 2014, Katz Web Services, Inc. |
10
|
|
|
* |
11
|
|
|
* @since 1.0.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Returns the form object for a given Form ID. |
19
|
|
|
* @see GVCommon::get_form() |
20
|
|
|
* @access public |
21
|
|
|
* @param mixed $form_id |
22
|
|
|
* @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms |
23
|
|
|
*/ |
24
|
|
|
function gravityview_get_form( $form_id ) { |
25
|
2 |
|
return GVCommon::get_form( $form_id ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the form array for an entry based only on the entry ID |
31
|
|
|
* @see GVCommon::get_form_from_entry_id |
32
|
|
|
* @param int|string $entry_slug Entry slug |
33
|
|
|
* @return array Gravity Forms form array |
34
|
|
|
*/ |
35
|
|
|
function gravityview_get_form_from_entry_id( $entry_slug ) { |
36
|
|
|
return GVCommon::get_form_from_entry_id( $entry_slug ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Alias of GFAPI::get_forms() |
42
|
|
|
* |
43
|
|
|
* @see GFAPI::get_forms() |
44
|
|
|
* |
45
|
|
|
* @since 1.19 Allow "any" $active status option |
46
|
|
|
* |
47
|
|
|
* @param bool|string $active Status of forms. Use `any` to get array of forms with any status. Default: `true` |
48
|
|
|
* @param bool $trash Include forms in trash? Default: `false` |
49
|
|
|
* |
50
|
|
|
* @return array Empty array if GFAPI class isn't available or no forms. Otherwise, the array of Forms |
51
|
|
|
*/ |
52
|
|
|
function gravityview_get_forms( $active = true, $trash = false ) { |
53
|
|
|
return GVCommon::get_forms( $active, $trash ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return array of fields' id and label, for a given Form ID |
58
|
|
|
* |
59
|
|
|
* @see GVCommon::get_form_fields() |
60
|
|
|
* @access public |
61
|
|
|
* @param string|array $form_id (default: '') or $form object |
|
|
|
|
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
|
function gravityview_get_form_fields( $form = '', $add_default_properties = false, $include_parent_field = true ) { |
65
|
|
|
return GVCommon::get_form_fields( $form, $add_default_properties, $include_parent_field ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* get extra fields from entry meta |
70
|
|
|
* @param string $form_id (default: '') |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
function gravityview_get_entry_meta( $form_id, $only_default_column = true ) { |
74
|
|
|
return GVCommon::get_entry_meta( $form_id, $only_default_column ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Wrapper for the Gravity Forms GFFormsModel::search_lead_ids() method |
79
|
|
|
* |
80
|
|
|
* @see GFEntryList::leads_page() |
81
|
|
|
* @param int $form_id ID of the Gravity Forms form |
82
|
|
|
* @since 1.1.6 |
83
|
|
|
* @return array Array of entry IDs |
84
|
|
|
*/ |
85
|
|
|
function gravityview_get_entry_ids( $form_id, $search_criteria = array() ) { |
86
|
|
|
return GVCommon::get_entry_ids( $form_id, $search_criteria ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Retrieve entries given search, sort, paging criteria |
92
|
|
|
* |
93
|
|
|
* @see GFAPI::get_entries() |
94
|
|
|
* @see GFFormsModel::get_field_filters_where() |
95
|
|
|
* @access public |
96
|
|
|
* @param int|array $form_ids The ID of the form or an array IDs of the Forms. Zero for all forms. |
97
|
|
|
* @param mixed $passed_criteria (default: null) |
98
|
|
|
* @param mixed &$total (default: null) |
99
|
|
|
* @return mixed False: Error fetching entries. Array: Multi-dimensional array of Gravity Forms entry arrays |
100
|
|
|
*/ |
101
|
|
|
function gravityview_get_entries( $form_ids = null, $passed_criteria = null, &$total = null ) { |
102
|
|
|
return GVCommon::get_entries( $form_ids, $passed_criteria, $total ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Return a single entry object |
107
|
|
|
* |
108
|
|
|
* Since 1.4, supports custom entry slugs. The way that GravityView fetches an entry based on the custom slug is by searching `gravityview_unique_id` meta. The `$entry_slug` is fetched by getting the current query var set by `is_single_entry()` |
109
|
|
|
* |
110
|
|
|
* @access public |
111
|
|
|
* @param mixed $entry_id |
|
|
|
|
112
|
|
|
* @param boolean $force_allow_ids Force the get_entry() method to allow passed entry IDs, even if the `gravityview_custom_entry_slug_allow_id` filter returns false. |
113
|
|
|
* @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true {@since 1.14} |
114
|
|
|
* @return array|boolean |
115
|
|
|
*/ |
116
|
|
|
function gravityview_get_entry( $entry_slug, $force_allow_ids = false, $check_entry_display = true ) { |
117
|
1 |
|
return GVCommon::get_entry( $entry_slug, $force_allow_ids, $check_entry_display ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Retrieve the label of a given field id (for a specific form) |
122
|
|
|
* |
123
|
|
|
* @access public |
124
|
|
|
* @param mixed $form |
125
|
|
|
* @param mixed $field_id |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
function gravityview_get_field_label( $form, $field_id, $field_value = '' ) { |
129
|
|
|
return GVCommon::get_field_label( $form, $field_id, $field_value ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns the field details array of a specific form given the field id |
135
|
|
|
* |
136
|
|
|
* Alias of GFFormsModel::get_field |
137
|
|
|
* |
138
|
|
|
* @since 1.19 Allow passing form ID as well as form array |
139
|
|
|
* |
140
|
|
|
* @uses GVCommon::get_field |
141
|
|
|
* @see GFFormsModel::get_field |
142
|
|
|
* @access public |
143
|
|
|
* @param array|int $form Form array or ID |
144
|
|
|
* @param string|int $field_id |
145
|
|
|
* @return GF_Field|null Returns NULL if field with ID $field_id doesn't exist. |
146
|
|
|
*/ |
147
|
|
|
function gravityview_get_field( $form, $field_id ) { |
148
|
|
|
return GVCommon::get_field( $form, $field_id ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Check whether the post is GravityView |
154
|
|
|
* |
155
|
|
|
* - Check post type. Is it `gravityview`? |
156
|
|
|
* - Check shortcode |
157
|
|
|
* |
158
|
|
|
* @param WP_Post $post WordPress post object |
159
|
|
|
* @return boolean True: yep, GravityView; No: not! |
160
|
|
|
*/ |
161
|
|
|
function has_gravityview_shortcode( $post = NULL ) { |
|
|
|
|
162
|
1 |
|
return GVCommon::has_gravityview_shortcode( $post ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Placeholder until the recursive has_shortcode() patch is merged |
167
|
|
|
* @see https://core.trac.wordpress.org/ticket/26343#comment:10 |
168
|
|
|
*/ |
169
|
|
|
function gravityview_has_shortcode_r( $content, $tag = 'gravityview' ) { |
170
|
1 |
|
return GVCommon::has_shortcode_r( $content, $tag ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get the views for a particular form |
175
|
|
|
* @param int $form_id Gravity Forms form ID |
176
|
|
|
* @return array Array with view details |
177
|
|
|
*/ |
178
|
|
|
function gravityview_get_connected_views( $form_id ) { |
179
|
|
|
return GVCommon::get_connected_views( $form_id ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get the connected form ID from a View ID |
184
|
|
|
* |
185
|
|
|
* @see GVCommon::get_meta_form_id |
186
|
|
|
* |
187
|
|
|
* @param int $view_id ID of the View you want the form of |
188
|
|
|
* |
189
|
|
|
* @return false|string ID of the connected Form, if exists. Empty string if not. False if not the View ID isn't valid. |
190
|
|
|
*/ |
191
|
|
|
function gravityview_get_form_id( $view_id ) { |
192
|
2 |
|
return GVCommon::get_meta_form_id( $view_id ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Get the template ID (`list`, `table`, `datatables`, `map`) for a View |
197
|
|
|
* |
198
|
|
|
* @see GravityView_Template::template_id |
199
|
|
|
* |
200
|
|
|
* @param int $view_id The ID of the View to get the layout of |
|
|
|
|
201
|
|
|
* |
202
|
|
|
* @return string GravityView_Template::template_id value. Empty string if not. |
203
|
|
|
*/ |
204
|
|
|
function gravityview_get_template_id( $post_id ) { |
205
|
2 |
|
return GVCommon::get_meta_template_id( $post_id ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get all the settings for a View |
210
|
|
|
* |
211
|
|
|
* @uses GravityView_View_Data::get_default_args() Parses the settings with the plugin defaults as backups. |
212
|
|
|
* @param int $post_id View ID |
213
|
|
|
* @return array Associative array of settings with plugin defaults used if not set by the View |
214
|
|
|
*/ |
215
|
|
|
function gravityview_get_template_settings( $post_id ) { |
216
|
2 |
|
return GVCommon::get_template_settings( $post_id ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Get the setting for a View |
221
|
|
|
* |
222
|
|
|
* If the setting isn't set by the View, it returns the plugin default. |
223
|
|
|
* |
224
|
|
|
* @param int $post_id View ID |
225
|
|
|
* @param string $key Key for the setting |
226
|
|
|
* @return mixed|null Setting value, or NULL if not set. |
227
|
|
|
*/ |
228
|
|
|
function gravityview_get_template_setting( $post_id, $key ) { |
229
|
|
|
return GVCommon::get_template_setting( $post_id, $key ); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Get all available preset templates |
234
|
|
|
* @since 1.13.2 |
235
|
|
|
* @return array Templates |
236
|
|
|
*/ |
237
|
|
|
function gravityview_get_registered_templates() { |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @filter `gravityview_register_directory_template` Fetch available View templates |
241
|
|
|
* @param array $templates Templates to show |
242
|
|
|
*/ |
243
|
|
|
$templates = apply_filters( 'gravityview_register_directory_template', array() ); |
244
|
|
|
|
245
|
|
|
return $templates; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Get the field configuration for the View |
250
|
|
|
* |
251
|
|
|
* array( |
252
|
|
|
* |
253
|
|
|
* [other zones] |
254
|
|
|
* |
255
|
|
|
* 'directory_list-title' => array( |
256
|
|
|
* |
257
|
|
|
* [other fields] |
258
|
|
|
* |
259
|
|
|
* '5372653f25d44' => array( |
260
|
|
|
* 'id' => string '9' (length=1) |
261
|
|
|
* 'label' => string 'Screenshots' (length=11) |
262
|
|
|
* 'show_label' => string '1' (length=1) |
263
|
|
|
* 'custom_label' => string '' (length=0) |
264
|
|
|
* 'custom_class' => string 'gv-gallery' (length=10) |
265
|
|
|
* 'only_loggedin' => string '0' (length=1) |
266
|
|
|
* 'only_loggedin_cap' => string 'read' (length=4) |
267
|
|
|
* ) |
268
|
|
|
* |
269
|
|
|
* [other fields] |
270
|
|
|
* ) |
271
|
|
|
* |
272
|
|
|
* [other zones] |
273
|
|
|
* ) |
274
|
|
|
* |
275
|
|
|
* @since 1.17.4 Added $apply_filter parameter |
276
|
|
|
* |
277
|
|
|
* @param int $post_id View ID |
278
|
|
|
* @param bool $apply_filter Whether to apply the `gravityview/configuration/fields` filter [Default: true] |
279
|
|
|
* @return array Multi-array of fields with first level being the field zones. See code comment. |
280
|
|
|
*/ |
281
|
|
|
function gravityview_get_directory_fields( $post_id, $apply_filter = true ) { |
282
|
2 |
|
return GVCommon::get_directory_fields( $post_id, $apply_filter ); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Get the widgets, as configured for a View |
287
|
|
|
* |
288
|
|
|
* @since 1.17.4 |
289
|
|
|
* |
290
|
|
|
* @param int $post_id |
291
|
|
|
* |
292
|
|
|
* @return array |
293
|
|
|
*/ |
294
|
|
|
function gravityview_get_directory_widgets( $post_id ) { |
295
|
2 |
|
return get_post_meta( $post_id, '_gravityview_directory_widgets', true ); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Set the widgets, as configured for a View |
300
|
|
|
* |
301
|
|
|
* @since 1.17.4 |
302
|
|
|
* |
303
|
|
|
* @param int $post_id |
304
|
|
|
* @param array $widgets array of widgets |
305
|
|
|
* |
306
|
|
|
* @return int|bool |
307
|
|
|
*/ |
308
|
|
|
function gravityview_set_directory_widgets( $post_id, $widgets = array() ) { |
309
|
|
|
return update_post_meta( $post_id, '_gravityview_directory_widgets', $widgets ); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Render dropdown (select) with the list of sortable fields from a form ID |
314
|
|
|
* |
315
|
|
|
* @access public |
316
|
|
|
* @param int $formid Form ID |
317
|
|
|
* @param string $current Field ID of field used to sort |
318
|
|
|
* @return string html |
319
|
|
|
*/ |
320
|
|
|
function gravityview_get_sortable_fields( $formid, $current = '' ) { |
321
|
|
|
return GVCommon::get_sortable_fields( $formid, $current ); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Returns the GF Form field type for a certain field(id) of a form |
327
|
|
|
* @param object $form Gravity Forms form |
328
|
|
|
* @param mixed $field_id Field ID or Field array |
329
|
|
|
* @return string field type |
330
|
|
|
*/ |
331
|
|
|
function gravityview_get_field_type( $form = null , $field_id = '' ) { |
|
|
|
|
332
|
|
|
return GVCommon::get_field_type( $form, $field_id ); |
|
|
|
|
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Theme function to get a GravityView view |
338
|
|
|
* |
339
|
|
|
* @access public |
340
|
|
|
* @param string $view_id (default: '') |
341
|
|
|
* @param array $atts (default: array()) |
342
|
|
|
* @return string HTML of the output. Empty string if $view_id is empty. |
343
|
|
|
*/ |
344
|
|
|
function get_gravityview( $view_id = '', $atts = array() ) { |
345
|
|
|
if( !empty( $view_id ) ) { |
|
|
|
|
346
|
|
|
$atts['id'] = $view_id; |
347
|
|
|
$args = wp_parse_args( $atts, GravityView_View_Data::get_default_args() ); |
348
|
|
|
$GravityView_frontend = GravityView_frontend::getInstance(); |
349
|
|
|
$GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) ); |
350
|
|
|
$GravityView_frontend->set_context_view_id( $view_id ); |
351
|
|
|
$GravityView_frontend->set_entry_data(); |
352
|
|
|
return $GravityView_frontend->render_view( $args ); |
353
|
|
|
} |
354
|
|
|
return ''; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Theme function to render a GravityView view |
359
|
|
|
* |
360
|
|
|
* @access public |
361
|
|
|
* @param string $view_id (default: '') |
362
|
|
|
* @param array $atts (default: array()) |
363
|
|
|
* @return void |
364
|
|
|
*/ |
365
|
|
|
function the_gravityview( $view_id = '', $atts = array() ) { |
366
|
|
|
echo get_gravityview( $view_id, $atts ); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Theme function to identify if it is a Single Entry View |
372
|
|
|
* |
373
|
|
|
* @since 1.5.4 |
374
|
|
|
* @return bool|string False if not, single entry slug if true |
375
|
|
|
*/ |
376
|
|
|
function gravityview_is_single_entry() { |
377
|
|
|
return GravityView_frontend::is_single_entry(); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Determine whether a View has a single checkbox or single radio input |
382
|
|
|
* @see GravityView_frontend::add_scripts_and_styles() |
383
|
|
|
* @since 1.15 |
384
|
|
|
* @param array $form Gravity Forms form |
385
|
|
|
* @param array $view_fields GravityView fields array |
386
|
|
|
*/ |
387
|
|
|
function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) { |
388
|
|
|
|
389
|
|
|
if( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) { |
390
|
|
|
|
391
|
|
|
/** @var GF_Field_Radio|GF_Field_Checkbox $form_field */ |
392
|
|
|
foreach( $form_fields as $form_field ) { |
393
|
|
|
$field_id = $form_field->id; |
394
|
|
|
foreach( $view_fields as $zone ) { |
395
|
|
|
|
396
|
|
|
// ACF compatibility; ACF-added fields aren't arrays |
397
|
|
|
if ( ! is_array( $zone ) ) { continue; } |
398
|
|
|
|
399
|
|
|
foreach( $zone as $field ) { |
400
|
|
|
// If it's an input, not the parent and the parent ID matches a checkbox or radio |
401
|
|
|
if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) { |
402
|
|
|
return true; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
return false; |
410
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.