GravityView  2.17
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  * @see GVCommon::get_directory_fields
271  * @since 1.17.4 Added $apply_filter parameter.
272  * @since 2.17 Added $form_id parameter.
273  *
274  * @param int $post_id View ID.
275  * @param bool $apply_filter Whether to apply the `gravityview/configuration/fields` filter [Default: true]
276  * @return array Multi-array of fields with first level being the field zones.
277  */
278 function gravityview_get_directory_fields( $post_id, $apply_filter = true, $form_id = 0 ) {
279  return GVCommon::get_directory_fields( $post_id, $apply_filter, $form_id );
280 }
281 
282 /**
283  * Get the widgets, as configured for a View
284  *
285  * @since 1.17.4
286  *
287  * @param int $post_id
288  *
289  * @return array
290  */
291 function gravityview_get_directory_widgets( $post_id ) {
292  return get_post_meta( $post_id, '_gravityview_directory_widgets', true );
293 }
294 
295 /**
296  * Set the widgets, as configured for a View
297  *
298  * @since 1.17.4
299  *
300  * @param int $post_id
301  * @param array $widgets array of widgets
302  *
303  * @return int|bool
304  */
305 function gravityview_set_directory_widgets( $post_id, $widgets = array() ) {
306  return update_post_meta( $post_id, '_gravityview_directory_widgets', $widgets );
307 }
308 
309 /**
310  * Render dropdown (select) with the list of sortable fields from a form ID
311  *
312  * @param int $formid Form ID
313  * @param string $current Field ID of field used to sort
314  * @return string html
315  */
316 function gravityview_get_sortable_fields( $formid, $current = '' ) {
317  return GVCommon::get_sortable_fields( $formid, $current );
318 }
319 
320 
321 /**
322  * Returns the GF Form field type for a certain field(id) of a form
323  * @param object $form Gravity Forms form
324  * @param mixed $field_id Field ID or Field array
325  * @return string field type
326  */
327 function gravityview_get_field_type( $form = null , $field_id = '' ) {
329 }
330 
331 
332 /**
333  * Theme function to get a GravityView view
334  *
335  * @param string $view_id (default: '')
336  * @param array $atts (default: array())
337  * @return string HTML of the output. Empty string if $view_id is empty.
338  */
339 function get_gravityview( $view_id = '', $atts = array() ) {
340  if( !empty( $view_id ) ) {
341  $atts['id'] = $view_id;
342  $args = wp_parse_args( $atts, \GV\View_Settings::defaults() );
343  $GravityView_frontend = GravityView_frontend::getInstance();
344  $GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) );
345  $GravityView_frontend->set_context_view_id( $view_id );
346  $GravityView_frontend->set_entry_data();
347  return $GravityView_frontend->render_view( $args );
348  }
349  return '';
350 }
351 
352 /**
353  * Theme function to render a GravityView view
354  *
355  * @param string $view_id (default: '')
356  * @param array $atts (default: array())
357  * @return void
358  */
359 function the_gravityview( $view_id = '', $atts = array() ) {
360  echo get_gravityview( $view_id, $atts );
361 }
362 
363 
364 /**
365  * Theme function to identify if it is a Single Entry View
366  *
367  * @since 1.5.4
368  * @return bool|string False if not, single entry slug if true
369  */
372 }
373 
374 /**
375  * Determine whether a View has a single checkbox or single radio input
376  * @see GravityView_frontend::add_scripts_and_styles()
377  * @since 1.15
378  * @param array $form Gravity Forms form
379  * @param array $view_fields GravityView fields array
380  */
381 function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) {
382 
383  if( class_exists('GFFormsModel') && $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {
384 
385  /** @var GF_Field_Radio|GF_Field_Checkbox $form_field */
386  foreach( $form_fields as $form_field ) {
387  $field_id = $form_field->id;
388  foreach( $view_fields as $zone ) {
389 
390  // ACF compatibility; ACF-added fields aren't arrays
391  if ( ! is_array( $zone ) ) { continue; }
392 
393  foreach( $zone as $field ) {
394  // If it's an input, not the parent and the parent ID matches a checkbox or radio
395  if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) {
396  return true;
397  }
398  }
399  }
400  }
401  }
402 
403  return false;
404 }
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)
static get_directory_fields( $post_id, $apply_filter=true, $form_id=0)
Get the field configuration for the View.
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()
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
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.
gravityview_get_directory_fields( $post_id, $apply_filter=true, $form_id=0)
Get the field configuration for the 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.
static is_single_entry()
Verify if user requested a single entry view.
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.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22
static get_form( $form_id)
Returns the form object for a given Form ID.
$field_value
Definition: checkbox.php:24
get_gravityview( $view_id='', $atts=array())
Theme function to get a GravityView view.
static getInstance()
Get the one true instantiated self.