GravityView_API
GravityView template tags API
Since: 1.0.0
Source: includes/class-api.php:14
Details
- Kind:
class - Namespace:
(global)
Methods
| Method | Description |
|---|---|
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
| Name | Type | Default | Description |
|---|---|---|---|
$field | array | GravityView field array | |
$entry | array | [] | Gravity Forms entry array |
$force_show_label | boolean | false | Whether 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
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text to replace variables in | |
$form | array | [] | GF Form array |
$entry | array | [] | GF Entry array |
$url_encode | bool | false | Pass return value through url_encode() |
$esc_html | bool | true | Pass return value through esc_html() |
$nl2br | bool | true | Convert newlines to <br> HTML tags |
$format | string | 'html' | The format requested for the location the merge is being used. Possible values: html, text or url. |
$aux_data | array | [] | 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
\GravityView_Merge_Tags::replace_variables()Moved in 1.8.4
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
| Name | Type | Default | Description |
|---|---|---|---|
$field | array | Array of settings for the field | |
$format | string | '%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
| Name | Type | Default | Description |
|---|---|---|---|
$field | mixed | ||
$form | null | ||
$entry | null |
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
| Name | Type | Default | Description |
|---|---|---|---|
$field | array | GravityView field array passed to gravityview_field_output() | |
$form | array | [] | Gravity Forms form array, if set. |
$entry | array | [] | Gravity Forms entry array |
Returns
string— Sanitized unique HTMLidattribute 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
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array | ||
$field_settings | |||
$format | 'html' | ||
$field | array |
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
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array | [] | Gravity Forms entry array |
$anchor_text | string | '' | The text or HTML inside the link |
$passed_tag_atts | array | string | [] | Attributes to be added to the anchor tag, such as title or rel. |
$field_settings | array | [] | Array of field settings. Optional, but passed to the gravityview_field_entry_link filter |
$base_id | int | null | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$wpautop | boolean | true | Apply wpautop() to the output? |
$context | \GV\Template_Context | null | null | The context |
Returns
string— HTML of "no results" text
Since: 2.0
Source: includes/class-api.php:303
directory_link()
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
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | null | Post ID |
$add_query_args | boolean | true | Add pagination and sorting arguments |
$context | \GV\Template_Context | null | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$id_or_string | int | string | ID of the entry, or custom slug string | |
$entry | array | [] | Gravity Forms Entry array, optional. Used only to provide data to customize the gravityview_entry_slug filter |
Returns
string— Unique slug ID, passed throughsanitize_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
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array Gravity Forms entry object | ||
$form | array 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
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array | int | Entry array or entry ID. | |
$post_id | int | null | null | If wanting to define the parent post, pass a post ID. |
$add_directory_args | boolean | true | True: Add args to help return to directory; False: only include args required to get to entry. |
$view_id | int | 0 |
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. Usegravityview/entry_link/add_query_argsfilter to override.)
Source: includes/class-api.php:732