Skip to main content

GravityView_API

GravityView template tags API

Since: 1.0.0

Source: includes/class-api.php:14

Details

  • Kind: class
  • Namespace: (global)

Methods

MethodDescription
field_label()Fetch Field Label
replace_variables()Alias for GravityView_Merge_Tags::replace_variables()
field_width()Get column width from the field setting
field_class()Fetch Field class
field_html_attr_id()Fetch Field HTML ID
field_value()Given an entry and a form field id, calculate the entry value for that field.
entry_link_html()Generate an anchor tag that links to an entry.
no_results()Get the "No Results" text depending on whether there were results.
directory_link()Generate a URL to the Directory context
get_entry_slug()Get the entry slug for the entry. By default, it is the entry ID.
entry_create_custom_slug()If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta
entry_link()return href for single entry

Method Reference

field_label()

public static function field_label( $field, $entry=[], $force_show_label=false )

Fetch Field Label

Parameters

NameTypeDefaultDescription
$fieldarrayGravityView field array
$entryarray[]Gravity Forms entry array
$force_show_labelbooleanfalseWhether to always show the label, regardless of field settings

Returns

  • string

Deprecated: Use \GV\Field::get_label()

Source: includes/class-api.php:27

replace_variables()

public static function replace_variables( $text, $form=[], $entry=[], $url_encode=false, $esc_html=true, $nl2br=true, $format='html', $aux_data=[] )

Alias for GravityView_Merge_Tags::replace_variables()

Parameters

NameTypeDefaultDescription
$textstringText to replace variables in
$formarray[]GF Form array
$entryarray[]GF Entry array
$url_encodeboolfalsePass return value through url_encode()
$esc_htmlbooltruePass return value through esc_html()
$nl2brbooltrueConvert newlines to <br> HTML tags
$formatstring'html'The format requested for the location the merge is being used. Possible values: html, text or url.
$aux_dataarray[]Additional data to be used to replace merge tags https://www.gravityhelp.com/documentation/article/gform_merge_tag_data/

Returns

  • string — Text with variables maybe replaced

See Also

Since: 1.22.4 (- Added $nl2br, $format, $aux_data args)

Source: includes/class-api.php:118

field_width()

public static function field_width( $field, $format='%d%%' )

Get column width from the field setting

Parameters

NameTypeDefaultDescription
$fieldarrayArray of settings for the field
$formatstring'%d%%'Format for width. "%" (default) will return

Returns

  • string | null — If not empty, string in $format format. Otherwise, null.

Since: 1.9

Source: includes/class-api.php:132

field_class()

public static function field_class( $field, $form=null, $entry=null )

Fetch Field class

Parameters

NameTypeDefaultDescription
$fieldmixed
$formnull
$entrynull

Returns

  • string

Source: includes/class-api.php:157

field_html_attr_id()

public static function field_html_attr_id( $field, $form=[], $entry=[] )

Fetch Field HTML ID

Parameters

NameTypeDefaultDescription
$fieldarrayGravityView field array passed to gravityview_field_output()
$formarray[]Gravity Forms form array, if set.
$entryarray[]Gravity Forms entry array

Returns

  • string — Sanitized unique HTML id attribute for the field

Since: 1.11

Source: includes/class-api.php:214

field_value()

public static function field_value( $entry, $field_settings, $format='html' )

Given an entry and a form field id, calculate the entry value for that field.

Parameters

NameTypeDefaultDescription
$entryarray
$field_settings
$format'html'
$fieldarray

Returns

  • null | string

Deprecated: Use \GV\Field_Template::render() or the more low-level \GV\Field::get_value()

Source: includes/class-api.php:244

entry_link_html()

public static function entry_link_html( $entry=[], $anchor_text='', $passed_tag_atts=[], $field_settings=[], $base_id=null )

Generate an anchor tag that links to an entry.

Parameters

NameTypeDefaultDescription
$entryarray[]Gravity Forms entry array
$anchor_textstring''The text or HTML inside the link
$passed_tag_attsarray | string[]Attributes to be added to the anchor tag, such as title or rel.
$field_settingsarray[]Array of field settings. Optional, but passed to the gravityview_field_entry_link filter
$base_idintnullThe post or the view that this entry is linked from.

Returns

  • string | null — Returns HTML for an anchor link. Null if $entry isn't defined or is missing an ID.

See Also

Since:

Source: includes/class-api.php:265

no_results()

public static function no_results( $wpautop=true, $context=null )

Get the "No Results" text depending on whether there were results.

Parameters

NameTypeDefaultDescription
$wpautopbooleantrueApply wpautop() to the output?
$context\GV\Template_Context | nullnullThe context

Returns

  • string — HTML of "no results" text

Since: 2.0

Source: includes/class-api.php:303

public static function directory_link( $post_id=null, $add_query_args=true, $context=null )

Generate a URL to the Directory context

Uses local static variable to speed up repeated requests to get permalink, which improves load time. Since we may be doing this hundreds of times per request, it adds up!

Parameters

NameTypeDefaultDescription
$post_idintnullPost ID
$add_query_argsbooleantrueAdd pagination and sorting arguments
$context\GV\Template_ContextnullThe context this is being used in.

Returns

  • string — Permalink to multiple entries view

Since: 2.0

Source: includes/class-api.php:451

get_entry_slug()

public static function get_entry_slug( $id_or_string, $entry=[] )

Get the entry slug for the entry. By default, it is the entry ID.

Parameters

NameTypeDefaultDescription
$id_or_stringint | stringID of the entry, or custom slug string
$entryarray[]Gravity Forms Entry array, optional. Used only to provide data to customize the gravityview_entry_slug filter

Returns

  • string — Unique slug ID, passed through sanitize_title()

See Also

Since: 1.4

Source: includes/class-api.php:607

entry_create_custom_slug()

public static function entry_create_custom_slug( $entry, $form )

If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta

Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );

Parameters

NameTypeDefaultDescription
$entryarray Gravity Forms entry object
$formarray Gravity Forms form object

Source: includes/class-api.php:684

entry_link()

public static function entry_link( $entry, $post_id=null, $add_directory_args=true, $view_id=0 )

return href for single entry

Parameters

NameTypeDefaultDescription
$entryarray | intEntry array or entry ID.
$post_idint | nullnullIf wanting to define the parent post, pass a post ID.
$add_directory_argsbooleantrueTrue: Add args to help return to directory; False: only include args required to get to entry.
$view_idint0

Returns

  • string — Link to the entry with the directory parent slug, or empty string if embedded post or View doesn't exist

Since:

  • 1.7.3 (Added $add_directory_args parameter)
  • 2.7.2 (Added $view_id parameter)
  • 2.10 (Added $_GET args to links by default. Use gravityview/entry_link/add_query_args filter to override.)

Source: includes/class-api.php:732