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