GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Private Member Functions | Static Private Attributes
GravityView_frontend Class Reference

Public Member Functions

 add_columns_sort_links ( $label='', $field=array(), $form=array())
 Inject the sorting links on the table columns. More...
 
 add_scripts_and_styles ()
 Register styles and scripts. More...
 
 comments_open ( $open, $post_id)
 Disable comments on GravityView post types. More...
 
 context_not_configured_warning ( $view_id=0)
 Display a warning when a View has not been configured. More...
 
 detect_views_in_block_content ( $block_content)
 Detect GV Views in parsed Gutenberg block content. More...
 
 filter_no_entries_output ( $no_entries_text, $is_search, $context=null)
 Modify what happens when there are no entries in the View based on View settings. More...
 
 get_context_view_id ()
 Returns the the view_id context when page contains multiple embedded views or displaying single entry view. More...
 
 getEntry ()
 
 getGvOutputData ()
 
 getPostId ()
 
 getSingleEntry ()
 
 is_field_sortable ( $field_id='', $form=array())
 Checks if field (column) is sortable. More...
 
 is_searching ()
 Checks if the current View is presenting search results. More...
 
 isGravityviewPostType ()
 
 isPostHasShortcode ()
 
 isSearch ()
 
 parse_content ( $wp=array())
 Read the $post and process the View data inside. More...
 
 parse_query_fix_frontpage (&$query)
 Allow GravityView entry endpoints on the front page of a site. More...
 
 set_context_view_id ( $view_id=null)
 Set the context view ID used when page contains multiple embedded views or displaying the single entry view. More...
 
 set_entry_data ()
 Set the entry. More...
 
 setEntry ( $entry)
 Set the current entry. More...
 
 setGvOutputData ( $gv_output_data)
 
 setIsGravityviewPostType ( $is_gravityview_post_type)
 
 setIsSearch ( $is_search)
 
 setPostHasShortcode ( $post_has_shortcode)
 
 setPostId ( $post_id)
 
 setSingleEntry ( $single_entry)
 Sets the single entry ID and also the entry. More...
 
 single_entry_title ( $passed_title, $passed_post_id=null)
 Filter the title for the single entry view. More...
 

Static Public Member Functions

static _override_sorting_id_by_field_type ( $sort_field_id, $form_id)
 Override sorting per field. More...
 
static add_style ( $template_id)
 Add template extra style if exists. More...
 
static get_search_criteria ( $args, $form_id)
 Parse search criteria for a entries search. More...
 
static get_search_criteria_paging ( $args)
 Get the paging array for the View. More...
 
static getInstance ()
 Get the one true instantiated self. More...
 
 insert_view_in_content ( $content)
 In case View post is called directly, insert the view in the post content. More...
 
static is_entry_approved ( $entry, $args=array())
 Check if a certain entry is approved. More...
 
static is_single_entry ()
 Verify if user requested a single entry view. More...
 
static process_search_dates ( $args, $search_criteria=array())
 Process the start and end dates for a view - overrides values defined in shortcode (if needed) More...
 
static process_search_only_approved ( $args, $search_criteria)
 Process the approved only search criteria according to the View settings. More...
 
 render_view ( $passed_args)
 Core function to render a View based on a set of arguments. More...
 

Data Fields

 $context_view_id = null
 
 $entry = false
 
 $gv_output_data = null
 
 $is_gravityview_post_type = false
 
 $is_search = false
 
 $post_has_shortcode = false
 
 $post_id = null
 
 $single_entry = false
 

Static Public Attributes

static $instance
 

Private Member Functions

 __construct ()
 Class constructor, enforce Singleton pattern. More...
 
 _get_single_entry_title ( $view, $entry=array(), $passed_title='')
 Returns the single entry title for a View with variables replaced and shortcodes parsed. More...
 
 enqueue_default_style ( $css_dependencies=array())
 Handle enqueuing the gravityview_default_style stylesheet. More...
 
 initialize ()
 

Static Private Attributes

static $search_parameters = array( 'gv_search', 'gv_start', 'gv_end', 'gv_id', 'gv_by', 'filter_*' )
 

Detailed Description

Definition at line 15 of file class-frontend-views.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )
private

Class constructor, enforce Singleton pattern.

Definition at line 93 of file class-frontend-views.php.

Member Function Documentation

◆ _get_single_entry_title()

_get_single_entry_title (   $view,
  $entry = array(),
  $passed_title = '' 
)
private

Returns the single entry title for a View with variables replaced and shortcodes parsed.

Since
2.7.2
Parameters
\GV\View | null$view
array$entry
string$passed_title
Returns
string
Runs Filter:
gravityview/single/title/check_entry_display Override whether to check entry display rules against filters

Definition at line 578 of file class-frontend-views.php.

References GV\$form, $title, GVCommon\check_entry_display(), GVCommon\get_form(), and GravityView_API\replace_variables().

Referenced by single_entry_title().

◆ _override_sorting_id_by_field_type()

static _override_sorting_id_by_field_type (   $sort_field_id,
  $form_id 
)
static

Override sorting per field.

Currently only modifies sorting ID when sorting by the full name. Sorts by first name. Use the gravityview/sorting/full-name filter to override.

Since
1.7.4

Override how to sort when sorting address

Since
1.8
Parameters
string$address_partstreet, street2, city, state, zip, or country (default: city)
string$sort_field_idField used for sorting
int$form_idGF Form ID
Runs Filter:
gravityview/sorting/full-name Override how to sort when sorting full name.
Since
1.7.4
Parameters
string$name_partSort by first or last (default: first)
string$sort_field_idField used for sorting
int$form_idGF Form ID
Runs Filter:
gravityview/sorting/time Override how to sort when sorting time
See also
GravityView_Field_Time
Since
1.14
Parameters
string$name_partField used for sorting
int$form_idGF Form ID

Definition at line 1346 of file class-frontend-views.php.

References GV\$form, $form_id, and gravityview_get_form().

Referenced by View_Table_Template\add_columns_sort_links(), and View\get_entries().

◆ add_columns_sort_links()

add_columns_sort_links (   $label = '',
  $field = array(),
  $form = array() 
)

Inject the sorting links on the table columns.

Callback function for hook 'gravityview/template/field_label'

See also
GravityView_API::field_label() (in includes/class-api.php)
Since
1.7
Parameters
string$labelField label.
array$fieldField settings.
array$formForm object.
Returns
string Field Label.

Not a table-based template; don't add sort icons

Since
1.12

Definition at line 1648 of file class-frontend-views.php.

References $class, $field, GV\$form, $label, $url, GravityView_View\getInstance(), and is_field_sortable().

◆ add_scripts_and_styles()

add_scripts_and_styles ( )

Register styles and scripts.

Returns
void
Runs Filter:
gravity_view_lightbox_script Override the lightbox script to enqueue. Default: thickbox
Parameters
string$script_slugIf you want to use a different lightbox script, return the name of it here.
Runs Filter:
gravityview_lightbox_script Override the lightbox script to enqueue. Default: thickbox
Since
2.5.1
Parameters
string$script_slugIf you want to use a different lightbox script, return the name of it here.

Definition at line 1483 of file class-frontend-views.php.

References $post, $view_id, View\by_id(), enqueue_default_style(), getGvOutputData(), GRAVITYVIEW_FILE, gravityview_get_template_id(), and GV_PLUGIN_VERSION.

◆ add_style()

static add_style (   $template_id)
static

Add template extra style if exists.

Parameters
string$template_id

Definition at line 1619 of file class-frontend-views.php.

References gravityview().

◆ comments_open()

comments_open (   $open,
  $post_id 
)

Disable comments on GravityView post types.

Parameters
boolean$openexisting status
int$post_idPost ID
Returns
boolean
Runs Filter:
gravityview/comments_open Whether to set comments to open or closed.
Since
1.5.4
Parameters
boolean$openOpen or closed status
int$post_idPost ID to set comment status for

Definition at line 637 of file class-frontend-views.php.

References isGravityviewPostType().

◆ context_not_configured_warning()

context_not_configured_warning (   $view_id = 0)

Display a warning when a View has not been configured.

Since
1.19.2 -by ::maybe_print_notices() 2.0
Parameters
int$view_idThe ID of the View currently being displayed
Returns
void

Definition at line 665 of file class-frontend-views.php.

References $image, $output, $title, $view_id, GVCommon\generate_notice(), GravityView_View\getInstance(), and GRAVITYVIEW_FILE.

◆ detect_views_in_block_content()

detect_views_in_block_content (   $block_content)

Detect GV Views in parsed Gutenberg block content.

Since
2.13.4
See also
::render()
Parameters
string$block_contentGutenberg block content
Returns
false|string

Definition at line 357 of file class-frontend-views.php.

References View_Collection\from_content(), and GravityView_View_Data\getInstance().

◆ enqueue_default_style()

enqueue_default_style (   $css_dependencies = array())
private

Handle enqueuing the gravityview_default_style stylesheet.

Since
1.17
Parameters
array$css_dependenciesDependencies for the gravityview_default_style stylesheet
Returns
void
Runs Filter:
gravityview_use_legacy_search_css Should GravityView use the legacy Search Bar stylesheet (from before Version 1.17)?
Since
1.17
Parameters
bool$use_legacy_search_styleIf true, loads gv-legacy-search(-rtl).css. If false, loads gv-default-styles(-rtl).css. -rtl is added on RTL websites. Default: false

Definition at line 1596 of file class-frontend-views.php.

References gravityview_css_url(), and GV_PLUGIN_VERSION.

Referenced by add_scripts_and_styles().

◆ filter_no_entries_output()

filter_no_entries_output (   $no_entries_text,
  $is_search,
  $context = null 
)

Modify what happens when there are no entries in the View based on View settings.

Since
2.17
Parameters
string$outputThe existing 'No Entries' text.
boolean$is_searchIs the current page a search result, or just a multiple entries screen?
\GV\Template_Context | null$contextThe context, if available.
Returns
string|void If search, existing text. If form, new 'No Entries' text.

Definition at line 714 of file class-frontend-views.php.

References $form_id, and $output.

◆ get_context_view_id()

get_context_view_id ( )

Returns the the view_id context when page contains multiple embedded views or displaying single entry view.

Since
1.5.4
Returns
int|null

Definition at line 273 of file class-frontend-views.php.

References $context_view_id.

◆ get_search_criteria()

static get_search_criteria (   $args,
  $form_id 
)
static

Parse search criteria for a entries search.

array( 'search_field' => 1, // ID of the field 'search_value' => '', // Value of the field to search 'search_operator' => 'contains', // 'is', 'isnot', '>', '<', 'contains' 'show_only_approved' => 0 or 1 // Boolean )

Parameters
array$argsArray of args
int$form_idGravity Forms form ID
Returns
array Array of search parameters, formatted in Gravity Forms mode, using status key set to "active" by default, field_filters array with key, value and operator keys.

Compatibility with filters hooking in gravityview_search_criteria instead of gravityview_fe_search_criteria.

Runs Filter:
gravityview_fe_search_criteria Modify the search criteria
See also
GravityView_Widget_Search::filter_entries Adds the default search criteria
Parameters
array$search_criteriaEmpty field_filters key
int$form_idID of the Gravity Forms form that is being searched
array$argsThe View settings.
Runs Filter:
gravityview_status Modify entry status requirements to be included in search results.
Parameters
string$statusDefault: active. Accepts all Gravity Forms entry statuses, including spam and trash

Definition at line 991 of file class-frontend-views.php.

References $args, $criteria, $entries, $form_id, gravityview(), and GV\Mocks\GravityView_frontend_get_view_entries().

Referenced by GravityView_Bulk_Actions\process_bulk_action().

◆ get_search_criteria_paging()

static get_search_criteria_paging (   $args)
static

Get the paging array for the View.

Since
1.19.5
Parameters
$args
int$form_id
Runs Filter:
gravityview_default_page_size The default number of entries displayed in a View
Since
1.1.6
Parameters
int$default_page_sizeDefault: 25

Definition at line 1205 of file class-frontend-views.php.

References $args, $field, GV\$form, $form_id, Utils\get(), GravityView_View\getInstance(), gravityview(), and GVCommon\is_field_numeric().

◆ getEntry()

getEntry ( )
Returns
array

Definition at line 178 of file class-frontend-views.php.

References $entry.

◆ getGvOutputData()

getGvOutputData ( )
Returns
GravityView_View_Data

Definition at line 132 of file class-frontend-views.php.

References $gv_output_data.

Referenced by add_scripts_and_styles(), and set_context_view_id().

◆ getInstance()

static getInstance ( )
static

◆ getPostId()

getPostId ( )
Returns
int

Definition at line 199 of file class-frontend-views.php.

References $post_id.

Referenced by parse_content().

◆ getSingleEntry()

getSingleEntry ( )
Returns
bool|int

Definition at line 160 of file class-frontend-views.php.

References $single_entry.

Referenced by is_searching().

◆ initialize()

initialize ( )
private

Definition at line 95 of file class-frontend-views.php.

◆ insert_view_in_content()

insert_view_in_content (   $content)
static

In case View post is called directly, insert the view in the post content.

See also
::content()} instead.
Parameters
mixed$content
Returns
string Add the View output into View CPT content

Definition at line 625 of file class-frontend-views.php.

References $content, and gravityview().

◆ is_entry_approved()

static is_entry_approved (   $entry,
  $args = array() 
)
static

Check if a certain entry is approved.

If we pass the View settings ($args) it will check the 'show_only_approved' setting before checking the entry approved field, returning true if show_only_approved = false.

Since
1.7
1.18 Converted check to use GravityView_Entry_Approval_Status::is_approved

GravityView_Entry_Approval_Status::is_approved

Parameters
array$entryEntry object
array$argsView settings (optional)
Returns
bool
Since
1.19

Definition at line 959 of file class-frontend-views.php.

References $args, gravityview(), GVCommon\has_cap(), GravityView_Entry_Approval_Status\is_approved(), and GravityView_Entry_Approval\meta_key.

◆ is_field_sortable()

is_field_sortable (   $field_id = '',
  $form = array() 
)

Checks if field (column) is sortable.

Parameters
string$fieldField settings
array$formGravity Forms form array
Since
1.7
Returns
bool True: Yes, field is sortable; False: not sortable

2.14

Since
1.7
Runs Filter:
gravityview/sortable/field_blocklist Modify what fields should never be sortable.
Since
2.14
Parameters
array$not_sortableArray of field types that aren't sortable.
string$field_typeField type to check whether the field is sortable.
array$formGravity Forms form.

Definition at line 1703 of file class-frontend-views.php.

References $field, $field_id, GV\$form, and getInstance().

Referenced by add_columns_sort_links().

◆ is_searching()

is_searching ( )

Checks if the current View is presenting search results.

Since
1.5.4
Returns
boolean True: Yes, it's a search; False: No, not a search.

Definition at line 446 of file class-frontend-views.php.

References $search_method, GravityView_Widget_Search\getInstance(), and getSingleEntry().

Referenced by parse_content().

◆ is_single_entry()

static is_single_entry ( )
static

Verify if user requested a single entry view.

Since
2.3.3 Added return null
Returns
boolean|string|null false if not, single entry slug if true, null if doesn't exist yet

Modify the entry that is being displayed.

Definition at line 1447 of file class-frontend-views.php.

References $single_entry, and Entry\get_endpoint_name().

Referenced by GravityView_Edit_Entry_Render\get_entry(), gravityview_is_single_entry(), and GravityView_Edit_Entry_Render\is_edit_entry().

◆ isGravityviewPostType()

isGravityviewPostType ( )
Returns
boolean

Definition at line 227 of file class-frontend-views.php.

References $is_gravityview_post_type.

Referenced by comments_open(), and parse_content().

◆ isPostHasShortcode()

isPostHasShortcode ( )
Returns
boolean

Definition at line 213 of file class-frontend-views.php.

References $post_has_shortcode.

◆ isSearch()

isSearch ( )
Returns
boolean

Definition at line 146 of file class-frontend-views.php.

References $is_search.

◆ parse_content()

parse_content (   $wp = array())

Read the $post and process the View data inside.

Parameters
array$wpPassed in the wp hook. Not used.
Returns
void

Definition at line 381 of file class-frontend-views.php.

References $post, GravityView_View_Data\getInstance(), getPostId(), gravityview(), gravityview_has_shortcode_r(), is_searching(), isGravityviewPostType(), set_context_view_id(), setGvOutputData(), setIsGravityviewPostType(), setIsSearch(), setPostHasShortcode(), and setPostId().

◆ parse_query_fix_frontpage()

parse_query_fix_frontpage ( $query)

Allow GravityView entry endpoints on the front page of a site.

Fixes this core issue https://wordpress.org/plugins/cpt-on-front-page/ Code is based on this 1.17.3 WP_Query &$query (passed by reference) void

Definition at line 289 of file class-frontend-views.php.

References Utils\get().

◆ process_search_dates()

static process_search_dates (   $args,
  $search_criteria = array() 
)
static

Process the start and end dates for a view - overrides values defined in shortcode (if needed)

The start_date and end_date keys need to be in a format processable by GFFormsModel::get_date_range_where(), which uses () format.

You can set the start_date or end_date to any value allowed by strtotime(), including strings like "now" or "-1 year" or "-3 days".

See also
GFFormsModel::get_date_range_where
Parameters
array$argsView settings
array$search_criteriaSearch being performed, if any
Returns
array Modified $search_criteria array

If the end date is formatted as 'Y-m-d', it should be formatted without hours and seconds so that Gravity Forms can convert the day to 23:59:59 the previous day.

If it's a relative date ("now" or "-1 day"), then it should use the precise date format

See also
GFFormsModel::get_date_range_where

Definition at line 839 of file class-frontend-views.php.

References $args, and gravityview().

◆ process_search_only_approved()

static process_search_only_approved (   $args,
  $search_criteria 
)
static

Process the approved only search criteria according to the View settings.

Parameters
array$argsView settings
array$search_criteriaSearch being performed, if any
Returns
array Modified $search_criteria array
Since
1.19

Definition at line 919 of file class-frontend-views.php.

References $args, GravityView_Entry_Approval_Status\APPROVED, gravityview(), GVCommon\has_cap(), and GravityView_Entry_Approval\meta_key.

◆ render_view()

render_view (   $passed_args)
static

Core function to render a View based on a set of arguments.

Parameters
array$passed_args{
 Settings for rendering the View

 @type int $id View id
 @type int $page_size Number of entries to show per page
 @type string $sort_field Form field id to sort
 @type string $sort_direction Sorting direction ('ASC', 'DESC', or 'RAND')
 @type string $start_date - Ymd
 @type string $end_date - Ymd
 @type string $class - assign a html class to the view
 @type string $offset (optional) - This is the start point in the current data set (0 index based).
}
Returns
string|null HTML output of a View, NULL if View isn't found

We can use a shortcode here, since it's pretty much the same.

But we do need to check embed permissions, since shortcodes don't do this.

Definition at line 798 of file class-frontend-views.php.

References gravityview(), and GVCommon\has_cap().

◆ set_context_view_id()

set_context_view_id (   $view_id = null)

Set the context view ID used when page contains multiple embedded views or displaying the single entry view.

Parameters
null$view_id

used on a has_multiple_views context

See also
GravityView_API::entry_link

Definition at line 243 of file class-frontend-views.php.

References $view_id, and getGvOutputData().

Referenced by parse_content().

◆ set_entry_data()

set_entry_data ( )

Set the entry.

Definition at line 433 of file class-frontend-views.php.

References setEntry(), and setSingleEntry().

◆ setEntry()

setEntry (   $entry)

Set the current entry.

Parameters
array | int$entryEntry array or entry slug or ID

Definition at line 187 of file class-frontend-views.php.

References $entry, and GVCommon\get_entry().

Referenced by set_entry_data().

◆ setGvOutputData()

setGvOutputData (   $gv_output_data)
Parameters
\GravityView_View_Data$gv_output_data

Definition at line 139 of file class-frontend-views.php.

References $gv_output_data.

Referenced by parse_content().

◆ setIsGravityviewPostType()

setIsGravityviewPostType (   $is_gravityview_post_type)
Parameters
boolean$is_gravityview_post_type

Definition at line 234 of file class-frontend-views.php.

References $is_gravityview_post_type.

Referenced by parse_content().

◆ setIsSearch()

setIsSearch (   $is_search)
Parameters
boolean$is_search

Definition at line 153 of file class-frontend-views.php.

References $is_search.

Referenced by parse_content().

◆ setPostHasShortcode()

setPostHasShortcode (   $post_has_shortcode)
Parameters
boolean$post_has_shortcode

Definition at line 220 of file class-frontend-views.php.

References $post_has_shortcode.

Referenced by parse_content().

◆ setPostId()

setPostId (   $post_id)
Parameters
int$post_id

Definition at line 206 of file class-frontend-views.php.

References $post_id.

Referenced by parse_content().

◆ setSingleEntry()

setSingleEntry (   $single_entry)

Sets the single entry ID and also the entry.

Parameters
bool | int | string$single_entry

Definition at line 169 of file class-frontend-views.php.

References $single_entry.

Referenced by set_entry_data().

◆ single_entry_title()

single_entry_title (   $passed_title,
  $passed_post_id = null 
)

Filter the title for the single entry view.

Parameters
string$passed_titleCurrent title
int$passed_post_idPost ID
Returns
string (modified) title
Runs Filter:
gravityview/single/title/out_loop Apply the Single Entry Title filter outside the WordPress loop?
Parameters
boolean$in_the_loopWhether to apply the filter to the menu title and the meta tag <title> - outside the loop
array$entryCurrent entry

Definition at line 496 of file class-frontend-views.php.

References $entry, $post, Utils\_GET(), _get_single_entry_title(), View\by_id(), View_Collection\from_post(), and gravityview().

Field Documentation

◆ $context_view_id

$context_view_id = null

Definition at line 67 of file class-frontend-views.php.

Referenced by get_context_view_id().

◆ $entry

$entry = false

Definition at line 60 of file class-frontend-views.php.

Referenced by getEntry(), setEntry(), and single_entry_title().

◆ $gv_output_data

$gv_output_data = null

Definition at line 83 of file class-frontend-views.php.

Referenced by getGvOutputData(), and setGvOutputData().

◆ $instance

$instance
static

Definition at line 88 of file class-frontend-views.php.

Referenced by Legacy_Context\reset().

◆ $is_gravityview_post_type

$is_gravityview_post_type = false

Definition at line 31 of file class-frontend-views.php.

Referenced by isGravityviewPostType(), and setIsGravityviewPostType().

◆ $is_search

$is_search = false

Definition at line 75 of file class-frontend-views.php.

Referenced by isSearch(), and setIsSearch().

◆ $post_has_shortcode

$post_has_shortcode = false

Definition at line 38 of file class-frontend-views.php.

Referenced by isPostHasShortcode(), and setPostHasShortcode().

◆ $post_id

$post_id = null

Definition at line 45 of file class-frontend-views.php.

Referenced by getPostId(), and setPostId().

◆ $search_parameters

$search_parameters = array( 'gv_search', 'gv_start', 'gv_end', 'gv_id', 'gv_by', 'filter_*' )
staticprivate

Definition at line 24 of file class-frontend-views.php.

◆ $single_entry

$single_entry = false

Definition at line 53 of file class-frontend-views.php.

Referenced by getSingleEntry(), is_single_entry(), and setSingleEntry().


The documentation for this class was generated from the following file: