GravityView  1.22.6
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 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  */
25  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  */
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  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  */
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  */
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 ) {
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  return GVCommon::has_shortcode_r( $content, $tag );
171 }
172 
173 /**
174  * Get the views for a particular form
175  *
176  * @since 1.22.1 Added $args param
177  *
178  * @param int $form_id Gravity Forms form ID
179  * @param array $args Pass args sent to get_posts()
180  *
181  * @return array Array with view details
182  */
183 function gravityview_get_connected_views( $form_id, $args = array() ) {
184  return GVCommon::get_connected_views( $form_id, $args );
185 }
186 
187 /**
188  * Get the connected form ID from a View ID
189  *
190  * @see GVCommon::get_meta_form_id
191  *
192  * @param int $view_id ID of the View you want the form of
193  *
194  * @return false|string ID of the connected Form, if exists. Empty string if not. False if not the View ID isn't valid.
195  */
198 }
199 
200 /**
201  * Get the template ID (`list`, `table`, `datatables`, `map`) for a View
202  *
203  * @see GravityView_Template::template_id
204  *
205  * @param int $view_id The ID of the View to get the layout of
206  *
207  * @return string GravityView_Template::template_id value. Empty string if not.
208  */
209 function gravityview_get_template_id( $post_id ) {
210  return GVCommon::get_meta_template_id( $post_id );
211 }
212 
213 /**
214  * Get all the settings for a View
215  *
216  * @uses \GV\View_Settings::defaults() Parses the settings with the plugin defaults as backups.
217  * @param int $post_id View ID
218  * @return array Associative array of settings with plugin defaults used if not set by the View
219  */
220 function gravityview_get_template_settings( $post_id ) {
221  return GVCommon::get_template_settings( $post_id );
222 }
223 
224 /**
225  * Get the setting for a View
226  *
227  * If the setting isn't set by the View, it returns the plugin default.
228  *
229  * @param int $post_id View ID
230  * @param string $key Key for the setting
231  * @return mixed|null Setting value, or NULL if not set.
232  */
233 function gravityview_get_template_setting( $post_id, $key ) {
234  return GVCommon::get_template_setting( $post_id, $key );
235 }
236 
237 /**
238  * Get all available preset templates
239  * @since 1.13.2
240  * @return array Templates
241  */
243 
244  /**
245  * @filter `gravityview_register_directory_template` Fetch available View templates
246  * @param array $templates Templates to show
247  */
248  $templates = apply_filters( 'gravityview_register_directory_template', array() );
249 
250  return $templates;
251 }
252 
253 /**
254  * Get the field configuration for the View
255  *
256  * array(
257  *
258  * [other zones]
259  *
260  * 'directory_list-title' => array(
261  *
262  * [other fields]
263  *
264  * '5372653f25d44' => array(
265  * 'id' => string '9' (length=1)
266  * 'label' => string 'Screenshots' (length=11)
267  * 'show_label' => string '1' (length=1)
268  * 'custom_label' => string '' (length=0)
269  * 'custom_class' => string 'gv-gallery' (length=10)
270  * 'only_loggedin' => string '0' (length=1)
271  * 'only_loggedin_cap' => string 'read' (length=4)
272  * )
273  *
274  * [other fields]
275  * )
276  *
277  * [other zones]
278  * )
279  *
280  * @since 1.17.4 Added $apply_filter parameter
281  *
282  * @param int $post_id View ID
283  * @param bool $apply_filter Whether to apply the `gravityview/configuration/fields` filter [Default: true]
284  * @return array Multi-array of fields with first level being the field zones. See code comment.
285  */
286 function gravityview_get_directory_fields( $post_id, $apply_filter = true ) {
287  return GVCommon::get_directory_fields( $post_id, $apply_filter );
288 }
289 
290 /**
291  * Get the widgets, as configured for a View
292  *
293  * @since 1.17.4
294  *
295  * @param int $post_id
296  *
297  * @return array
298  */
299 function gravityview_get_directory_widgets( $post_id ) {
300  return get_post_meta( $post_id, '_gravityview_directory_widgets', true );
301 }
302 
303 /**
304  * Set the widgets, as configured for a View
305  *
306  * @since 1.17.4
307  *
308  * @param int $post_id
309  * @param array $widgets array of widgets
310  *
311  * @return int|bool
312  */
313 function gravityview_set_directory_widgets( $post_id, $widgets = array() ) {
314  return update_post_meta( $post_id, '_gravityview_directory_widgets', $widgets );
315 }
316 
317 /**
318  * Render dropdown (select) with the list of sortable fields from a form ID
319  *
320  * @access public
321  * @param int $formid Form ID
322  * @param string $current Field ID of field used to sort
323  * @return string html
324  */
325 function gravityview_get_sortable_fields( $formid, $current = '' ) {
326  return GVCommon::get_sortable_fields( $formid, $current );
327 }
328 
329 
330 /**
331  * Returns the GF Form field type for a certain field(id) of a form
332  * @param object $form Gravity Forms form
333  * @param mixed $field_id Field ID or Field array
334  * @return string field type
335  */
336 function gravityview_get_field_type( $form = null , $field_id = '' ) {
338 }
339 
340 
341 /**
342  * Theme function to get a GravityView view
343  *
344  * @access public
345  * @param string $view_id (default: '')
346  * @param array $atts (default: array())
347  * @return string HTML of the output. Empty string if $view_id is empty.
348  */
349 function get_gravityview( $view_id = '', $atts = array() ) {
350  if( !empty( $view_id ) ) {
351  $atts['id'] = $view_id;
352  $args = wp_parse_args( $atts, defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? \GV\View_Settings::defaults() : GravityView_View_Data::get_default_args() );
353  $GravityView_frontend = GravityView_frontend::getInstance();
354  $GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) );
355  $GravityView_frontend->set_context_view_id( $view_id );
356  $GravityView_frontend->set_entry_data();
357  return $GravityView_frontend->render_view( $args );
358  }
359  return '';
360 }
361 
362 /**
363  * Theme function to render a GravityView view
364  *
365  * @access public
366  * @param string $view_id (default: '')
367  * @param array $atts (default: array())
368  * @return void
369  */
370 function the_gravityview( $view_id = '', $atts = array() ) {
371  echo get_gravityview( $view_id, $atts );
372 }
373 
374 
375 /**
376  * Theme function to identify if it is a Single Entry View
377  *
378  * @since 1.5.4
379  * @return bool|string False if not, single entry slug if true
380  */
383 }
384 
385 /**
386  * Determine whether a View has a single checkbox or single radio input
387  * @see GravityView_frontend::add_scripts_and_styles()
388  * @since 1.15
389  * @param array $form Gravity Forms form
390  * @param array $view_fields GravityView fields array
391  */
392 function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) {
393 
394  if( class_exists('GFFormsModel') && $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {
395 
396  /** @var GF_Field_Radio|GF_Field_Checkbox $form_field */
397  foreach( $form_fields as $form_field ) {
398  $field_id = $form_field->id;
399  foreach( $view_fields as $zone ) {
400 
401  // ACF compatibility; ACF-added fields aren't arrays
402  if ( ! is_array( $zone ) ) { continue; }
403 
404  foreach( $zone as $field ) {
405  // If it's an input, not the parent and the parent ID matches a checkbox or radio
406  if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) {
407  return true;
408  }
409  }
410  }
411  }
412  }
413 
414  return false;
415 }
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:164
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.
gravityview_get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true)
Return a single entry object.
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.
static get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true)
Return a single entry object.
static get_forms( $active=true, $trash=false)
Alias of GFAPI::get_forms()
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_template_setting( $post_id, $key)
Get the setting for a View.
$templates
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_forms( $active=true, $trash=false)
Alias of GFAPI::get_forms()
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.
static get_default_args( $with_details=false, $group=NULL)
Retrieve the default args for shortcode and theme function.
Definition: class-data.php:713
$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
global $post
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_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.