GravityView  2.10.1
The best, easiest way to display Gravity Forms entries on your website.
connector-functions.php
Go to the documentation of this file.
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 GravityView <[email protected]>
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  * @param mixed $form_id
20  * @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms
21  */
23  return GVCommon::get_form( $form_id );
24 }
25 
26 
27 /**
28  * Get the form array for an entry based only on the entry ID
29  * @see GVCommon::get_form_from_entry_id
30  * @param int|string $entry_slug Entry slug
31  * @return array Gravity Forms form array
32  */
35 }
36 
37 
38 /**
39  * Alias of GFAPI::get_forms()
40  *
41  * @see GFAPI::get_forms()
42  *
43  * @since 1.19 Allow "any" $active status option
44  * @since 2.7.2 Allow sorting forms using wp_list_sort()
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  * @param string|array $order_by Optional. Either the field name to order by or an array of multiple orderby fields as $orderby => $order.
49  * @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby is a string.
50  *
51  * @return array Empty array if GFAPI class isn't available or no forms. Otherwise, the array of Forms
52  */
53 function gravityview_get_forms( $active = true, $trash = false, $order_by = 'date_created', $order = 'ASC' ) {
54  return GVCommon::get_forms( $active, $trash, $order_by, $order );
55 }
56 
57 /**
58  * Return array of fields' id and label, for a given Form ID
59  *
60  * @see GVCommon::get_form_fields()
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  * @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  *
110  * @since 1.4 Supports custom entry slugs
111  * @since 2.6 Added $view parameter
112  *
113  * @param int|string $entry_slug Entry ID or slug
114  * @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.
115  * @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true {@since 1.14}
116  * @param \GV\View $view The View if $check_entry_display is set to true. {@since develop}
117  * @return array|boolean
118  */
119 function gravityview_get_entry( $entry_slug, $force_allow_ids = false, $check_entry_display = true, $view = null ) {
120  return GVCommon::get_entry( $entry_slug, $force_allow_ids, $check_entry_display, $view );
121 }
122 
123 /**
124  * Retrieve the label of a given field id (for a specific form)
125  *
126  * @param mixed $form
127  * @param mixed $field_id
128  * @return string
129  */
132 }
133 
134 
135 /**
136  * Returns the field details array of a specific form given the field id
137  *
138  * Alias of GFFormsModel::get_field
139  *
140  * @since 1.19 Allow passing form ID as well as form array
141  *
142  * @uses GVCommon::get_field
143  * @see GFFormsModel::get_field
144  * @param array|int $form Form array or ID
145  * @param string|int $field_id
146  * @return GF_Field|null Returns NULL if field with ID $field_id doesn't exist.
147  */
150 }
151 
152 
153 /**
154  * Check whether the post is GravityView
155  *
156  * - Check post type. Is it `gravityview`?
157  * - Check shortcode
158  *
159  * @param WP_Post $post WordPress post object
160  * @return boolean True: yep, GravityView; No: not!
161  */
162 function has_gravityview_shortcode( $post = NULL ) {
164 }
165 
166 /**
167  * Placeholder until the recursive has_shortcode() patch is merged
168  * @see https://core.trac.wordpress.org/ticket/26343#comment:10
169  */
170 function gravityview_has_shortcode_r( $content, $tag = 'gravityview' ) {
171  return GVCommon::has_shortcode_r( $content, $tag );
172 }
173 
174 /**
175  * Get the views for a particular form
176  *
177  * @since 1.22.1 Added $args param
178  *
179  * @param int $form_id Gravity Forms form ID
180  * @param array $args Pass args sent to get_posts()
181  *
182  * @return array Array with view details
183  */
186 }
187 
188 /**
189  * Get the connected form ID from a View ID
190  *
191  * @see GVCommon::get_meta_form_id
192  *
193  * @param int $view_id ID of the View you want the form of
194  *
195  * @return false|string ID of the connected Form, if exists. Empty string if not. False if not the View ID isn't valid.
196  */
199 }
200 
201 /**
202  * Get joined forms associated with a view
203  *
204  * @since 2.0.11
205  *
206  * @param int $view_id ID of the View
207  *
208  * @return \GV\GF_Form[] Array of \GV\GF_Form instances
209  */
211  return View::get_joined_forms( $view_id );
212 }
213 
214 /**
215  * Get the template ID (`list`, `table`, `datatables`, `map`) for a View
216  *
217  * @see GravityView_Template::template_id
218  *
219  * @param int $view_id The ID of the View to get the layout of
220  *
221  * @return string GravityView_Template::template_id value. Empty string if not.
222  */
223 function gravityview_get_template_id( $post_id ) {
224  return GVCommon::get_meta_template_id( $post_id );
225 }
226 
227 /**
228  * Get all the settings for a View
229  *
230  * @uses \GV\View_Settings::defaults() Parses the settings with the plugin defaults as backups.
231  * @param int $post_id View ID
232  * @return array Associative array of settings with plugin defaults used if not set by the View
233  */
234 function gravityview_get_template_settings( $post_id ) {
235  return GVCommon::get_template_settings( $post_id );
236 }
237 
238 /**
239  * Get the setting for a View
240  *
241  * If the setting isn't set by the View, it returns the plugin default.
242  *
243  * @param int $post_id View ID
244  * @param string $key Key for the setting
245  * @return mixed|null Setting value, or NULL if not set.
246  */
247 function gravityview_get_template_setting( $post_id, $key ) {
248  return GVCommon::get_template_setting( $post_id, $key );
249 }
250 
251 /**
252  * Get all available preset templates
253  * @since 1.13.2
254  * @return array Templates
255  */
257 
258  /**
259  * @filter `gravityview_register_directory_template` Fetch available View templates
260  * @param array $templates Templates to show
261  */
262  $templates = apply_filters( 'gravityview_register_directory_template', array() );
263 
264  return $templates;
265 }
266 
267 /**
268  * Get the field configuration for the View
269  *
270  * array(
271  *
272  * [other zones]
273  *
274  * 'directory_list-title' => array(
275  *
276  * [other fields]
277  *
278  * '5372653f25d44' => array(
279  * 'id' => string '9' (length=1)
280  * 'label' => string 'Screenshots' (length=11)
281  * 'show_label' => string '1' (length=1)
282  * 'custom_label' => string '' (length=0)
283  * 'custom_class' => string 'gv-gallery' (length=10)
284  * 'only_loggedin' => string '0' (length=1)
285  * 'only_loggedin_cap' => string 'read' (length=4)
286  * )
287  *
288  * [other fields]
289  * )
290  *
291  * [other zones]
292  * )
293  *
294  * @since 1.17.4 Added $apply_filter parameter
295  *
296  * @param int $post_id View ID
297  * @param bool $apply_filter Whether to apply the `gravityview/configuration/fields` filter [Default: true]
298  * @return array Multi-array of fields with first level being the field zones. See code comment.
299  */
300 function gravityview_get_directory_fields( $post_id, $apply_filter = true ) {
301  return GVCommon::get_directory_fields( $post_id, $apply_filter );
302 }
303 
304 /**
305  * Get the widgets, as configured for a View
306  *
307  * @since 1.17.4
308  *
309  * @param int $post_id
310  *
311  * @return array
312  */
313 function gravityview_get_directory_widgets( $post_id ) {
314  return get_post_meta( $post_id, '_gravityview_directory_widgets', true );
315 }
316 
317 /**
318  * Set the widgets, as configured for a View
319  *
320  * @since 1.17.4
321  *
322  * @param int $post_id
323  * @param array $widgets array of widgets
324  *
325  * @return int|bool
326  */
327 function gravityview_set_directory_widgets( $post_id, $widgets = array() ) {
328  return update_post_meta( $post_id, '_gravityview_directory_widgets', $widgets );
329 }
330 
331 /**
332  * Render dropdown (select) with the list of sortable fields from a form ID
333  *
334  * @param int $formid Form ID
335  * @param string $current Field ID of field used to sort
336  * @return string html
337  */
338 function gravityview_get_sortable_fields( $formid, $current = '' ) {
339  return GVCommon::get_sortable_fields( $formid, $current );
340 }
341 
342 
343 /**
344  * Returns the GF Form field type for a certain field(id) of a form
345  * @param object $form Gravity Forms form
346  * @param mixed $field_id Field ID or Field array
347  * @return string field type
348  */
349 function gravityview_get_field_type( $form = null , $field_id = '' ) {
351 }
352 
353 
354 /**
355  * Theme function to get a GravityView view
356  *
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  * @param string $view_id (default: '')
378  * @param array $atts (default: array())
379  * @return void
380  */
381 function the_gravityview( $view_id = '', $atts = array() ) {
382  echo get_gravityview( $view_id, $atts );
383 }
384 
385 
386 /**
387  * Theme function to identify if it is a Single Entry View
388  *
389  * @since 1.5.4
390  * @return bool|string False if not, single entry slug if true
391  */
394 }
395 
396 /**
397  * Determine whether a View has a single checkbox or single radio input
398  * @see GravityView_frontend::add_scripts_and_styles()
399  * @since 1.15
400  * @param array $form Gravity Forms form
401  * @param array $view_fields GravityView fields array
402  */
403 function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) {
404 
405  if( class_exists('GFFormsModel') && $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {
406 
407  /** @var GF_Field_Radio|GF_Field_Checkbox $form_field */
408  foreach( $form_fields as $form_field ) {
409  $field_id = $form_field->id;
410  foreach( $view_fields as $zone ) {
411 
412  // ACF compatibility; ACF-added fields aren't arrays
413  if ( ! is_array( $zone ) ) { continue; }
414 
415  foreach( $zone as $field ) {
416  // If it's an input, not the parent and the parent ID matches a checkbox or radio
417  if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) {
418  return true;
419  }
420  }
421  }
422  }
423  }
424 
425  return false;
426 }
static get_entry_meta( $form_id, $only_default_column=true)
get extra fields from entry meta
static has_shortcode_r( $content, $tag='gravityview')
Placeholder until the recursive has_shortcode() patch is merged.
gravityview_get_form_from_entry_id( $entry_slug)
Get the form array for an entry based only on the entry ID.
gravityview_get_field_label( $form, $field_id, $field_value='')
Retrieve the label of a given field id (for a specific form)
gravityview_set_directory_widgets( $post_id, $widgets=array())
Set the widgets, as configured for a View.
static get_connected_views( $form_id, $args=array())
Get the views for a particular form.
static get_form_fields( $form='', $add_default_properties=false, $include_parent_field=true)
Return array of fields&#39; id and label, for a given Form ID.
static get_form_from_entry_id( $entry_slug)
Get the form array for an entry based only on the entry ID.
static getInstance( $passed_post=NULL)
Definition: class-data.php:122
static get_template_setting( $post_id, $key)
Get the setting for a View.
gravityview_is_single_entry()
Theme function to identify if it is a Single Entry View.
static get_forms( $active=true, $trash=false, $order_by='id', $order='ASC')
Alias of GFAPI::get_forms()
gravityview_get_directory_fields( $post_id, $apply_filter=true)
Get the field configuration for the View.
static get_meta_form_id( $view_id)
Get the Gravity Forms form ID connected to a View.
gravityview_get_field_type( $form=null, $field_id='')
Returns the GF Form field type for a certain field(id) of a form.
gravityview_get_entry_meta( $form_id, $only_default_column=true)
get extra fields from entry meta
static get_directory_fields( $post_id, $apply_filter=true)
Get the field configuration for the View.
gravityview_get_form( $form_id)
Returns the form object for a given Form ID.
gravityview_get_directory_widgets( $post_id)
Get the widgets, as configured for a View.
gravityview_get_template_settings( $post_id)
Get all the settings for a View.
static get_sortable_fields( $formid, $current='')
Render dropdown (select) with the list of sortable fields from a form ID.
gravityview_get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true, $view=null)
Return a single entry object.
gravityview_get_template_setting( $post_id, $key)
Get the setting for a View.
$templates
global $post
Definition: delete-entry.php:7
if(gravityview() ->plugin->is_GF_25()) $form
gravityview_get_forms( $active=true, $trash=false, $order_by='date_created', $order='ASC')
Alias of GFAPI::get_forms()
static get_template_settings( $post_id)
Get all the settings for a View.
the_gravityview( $view_id='', $atts=array())
Theme function to render a GravityView view.
if(empty( $field_settings['content'])) $content
Definition: custom.php:37
static get_entry_ids( $form_id, $search_criteria=array())
Wrapper for the Gravity Forms GFFormsModel::search_lead_ids() method.
static get_field_type( $form=null, $field_id='')
Returns the GF Form field type for a certain field(id) of a form.
gravityview_get_field( $form, $field_id)
Returns the field details array of a specific form given the field id.
static get_field( $form, $field_id)
Returns the field details array of a specific form given the field id.
gravityview_get_form_fields( $form='', $add_default_properties=false, $include_parent_field=true)
Return array of fields&#39; id and label, for a given Form ID.
gravityview_get_connected_views( $form_id, $args=array())
Get the views for a particular form.
gravityview_get_form_id( $view_id)
Get the connected form ID from a View ID.
gravityview_has_shortcode_r( $content, $tag='gravityview')
Placeholder until the recursive has_shortcode() patch is merged.
gravityview_get_entries( $form_ids=null, $passed_criteria=null, &$total=null)
Retrieve entries given search, sort, paging criteria.
defaults()
Default settings.
static is_single_entry()
Verify if user requested a single entry view.
$field_id
Definition: time.php:17
gravityview_get_sortable_fields( $formid, $current='')
Render dropdown (select) with the list of sortable fields from a form ID.
static get_entries( $form_ids=null, $passed_criteria=null, &$total=null)
Retrieve entries given search, sort, paging criteria.
gravityview_get_registered_templates()
Get all available preset templates.
static has_gravityview_shortcode( $post=null)
Check whether the post is GravityView.
if(empty( $created_by)) $form_id
has_gravityview_shortcode( $post=NULL)
Check whether the post is GravityView.
static get_field_label( $form=array(), $field_id='', $field_value='')
Retrieve the label of a given field id (for a specific form)
gravityview_get_entry_ids( $form_id, $search_criteria=array())
Wrapper for the Gravity Forms GFFormsModel::search_lead_ids() method.
gravityview_get_template_id( $post_id)
Get the template ID (list, table, datatables, map) for a View.
$entry_slug
Definition: notes.php:30
static get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true, $view=null)
Return a single entry object.
gravityview_get_joined_forms( $view_id)
Get joined forms associated with a view.
static get_meta_template_id( $view_id)
Get the template ID (list, table, datatables, map) for a View.
static get_form( $form_id)
Returns the form object for a given Form ID.
$field_value
Definition: checkbox.php:24
$field
Definition: gquiz_grade.php:11
get_gravityview( $view_id='', $atts=array())
Theme function to get a GravityView view.
static getInstance()
Get the one true instantiated self.