GravityView  1.19.4
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 Member Functions | Static Private Attributes
GravityView_frontend Class Reference

Public Member Functions

 add_columns_sort_links ($label= '', $field, $form)
 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...
 
 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 ($title, $passed_post_id=null)
 Filter the title for the single entry view. More...
 

Static Public Member Functions

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...
 
static updateViewSorting ($args, $form_id)
 Updates the View sorting criteria. 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...
 
 enqueue_default_style ($css_dependencies=array())
 Handle enqueuing the gravityview_default_style stylesheet. More...
 
 initialize ()
 

Static Private Member Functions

static _override_sorting_id_by_field_type ($sort_field_id, $form_id)
 Override sorting per field. More...
 

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 ( )
private

Class constructor, enforce Singleton pattern.

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

Member Function Documentation

static _override_sorting_id_by_field_type (   $sort_field_id,
  $form_id 
)
staticprivate

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
Parameters
int | string$sort_field_idField used for sorting (id or 1.2)
int$form_idGF Form ID
Returns
string Possibly modified sorting ID

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
[in,out]string$name_partSort by first or last (default: first)
[in]string$sort_field_idField used for sorting
[in]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
[in,out]string$name_partField used for sorting
[in]int$form_idGF Form ID

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

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

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

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
Returns
string Field Label

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

Since
1.12

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

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

add_scripts_and_styles ( )

Register styles and scripts.

public

Returns
void

Don't enqueue the scripts or styles if it's not going to be displayed.

Since
1.15
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:
gravity_view_lightbox_style Modify the lightbox CSS slug. Default: thickbox
Parameters
string$script_slugIf you want to use a different lightbox script, return the name of its CSS file here.

If the form has checkbox fields, enqueue dashicons

See also
https://github.com/katzwebservices/GravityView/issues/536
Since
1.15
Runs Filter:
gravityview_js_localization Modify the array passed to wp_localize_script()
Parameters
array$js_localizationThe data padded to the Javascript file
array$viewsArray of View data arrays with View settings

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

References $post, $view_id, enqueue_default_style(), getGvOutputData(), GRAVITYVIEW_FILE, GVCommon\has_cap(), and GravityView_Plugin\version.

static add_style (   $template_id)
static

Add template extra style if exists.

Parameters
string$template_id

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

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 544 of file class-frontend-views.php.

References isGravityviewPostType().

context_not_configured_warning (   $view_id = 0)

Display a warning when a View has not been configured.

Since
1.19.2
Parameters
int$view_idThe ID of the View currently being displayed
Returns
void

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

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

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 1493 of file class-frontend-views.php.

References gravityview_css_url(), and GravityView_Plugin\version.

Referenced by add_scripts_and_styles().

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
string

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

References $context_view_id.

Referenced by render_view(), and single_entry_title().

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.
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
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 1041 of file class-frontend-views.php.

References $entries, $form_id, and gravityview_get_entries().

Referenced by GravityView_Admin_ApproveEntries\process_bulk_action().

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 1196 of file class-frontend-views.php.

getEntry ( )
Returns
array

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

References $entry.

Referenced by render_view(), and single_entry_title().

getGvOutputData ( )
static getInstance ( )
static
getPostId ( )
Returns
int

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

References $post_id.

Referenced by parse_content(), and render_view().

getSingleEntry ( )
Returns
bool|int

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

References $single_entry.

Referenced by is_searching(), render_view(), and single_entry_title().

initialize ( )
private

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

insert_view_in_content (   $content)
static

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

public

Parameters
mixed$content
Returns
string Add the View output into View CPT content
Since
1.7.4

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

References $content, $view_id, getGvOutputData(), gravityview_get_form_id(), isGravityviewPostType(), and render_view().

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 1009 of file class-frontend-views.php.

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

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
Runs Filter:
gravityview/sortable/field_blacklist Modify what fields should never be sortable.
Since
1.7
Parameters
[in,out]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 1596 of file class-frontend-views.php.

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

Referenced by add_columns_sort_links().

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 380 of file class-frontend-views.php.

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

Referenced by parse_content().

static is_single_entry ( )
static

Verify if user requested a single entry view.

Returns
boolean|string false if not, single entry slug if true

Deprecated. Use ::get_endpoint_name instead.

Modify the entry that is being displayed.

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

References $single_entry, Entry\get_endpoint_name(), and GravityView_Post_Types\get_entry_var_name().

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

isGravityviewPostType ( )
Returns
boolean

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

References $is_gravityview_post_type.

Referenced by comments_open(), insert_view_in_content(), parse_content(), and render_view().

isPostHasShortcode ( )
Returns
boolean

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

References $post_has_shortcode.

Referenced by render_view().

isSearch ( )
Returns
boolean

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

References $is_search.

Referenced by render_view().

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 337 of file class-frontend-views.php.

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

Referenced by render_view().

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 278 of file class-frontend-views.php.

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 894 of file class-frontend-views.php.

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 969 of file class-frontend-views.php.

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

Referenced by GravityView_Recent_Entries_Widget\get_entries().

render_view (   $passed_args)
static

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

public

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' or 'DESC')
 @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

Don't render View if user isn't allowed to see it

Since
1.15
1.17.2 Added check for if a user has no caps but is logged in (member of multisite, but not any site). Treat as if logged-out.
Runs Filter:
gravityview_direct_access Should Views be directly accessible, or only visible using the shortcode?
See also
https://codex.wordpress.org/Function_Reference/register_post_type#public
::get_endpoint_name
Since
1.15.2
Parameters
[in,out]booleantrue: allow Views to be accessible directly. false: Only allow Views to be embedded via shortcode. Default: true
int$view_idThe ID of the View currently being requested. 0 for general setting

Set globals for templating

Disable fetching initial entries for views that don't need it (DataTables)

Hide View data until search is performed

Since
1.5.4
Runs Actions:
gravityview_render_entry_{View ID} Before rendering a single entry for a specific View ID
Since
1.17
Runs Filter:
gravityview/render/entry/not_visible Modify the message shown to users when the entry doesn't exist or they aren't allowed to view it.
Since
1.6
Parameters
string$messageDefault: "You have attempted to view an entry that is not visible or may not exist."
Since
1.6

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

References $entry, $gravityview_view, $output, $view_id, get_context_view_id(), getEntry(), getGvOutputData(), getPostId(), getSingleEntry(), gravityview_get_context(), GVCommon\has_cap(), isGravityviewPostType(), isPostHasShortcode(), isSearch(), and parse_content().

Referenced by insert_view_in_content().

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
GravityView_View_Data::getInstance()->has_multiple_views()

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

References $view_id, and getGvOutputData().

Referenced by parse_content().

set_entry_data ( )

Set the entry.

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

References setEntry(), and setSingleEntry().

setEntry (   $entry)

Set the current entry.

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

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

References $entry, and GVCommon\get_entry().

Referenced by set_entry_data().

setGvOutputData (   $gv_output_data)
Parameters
GravityView_View_Data$gv_output_data

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

References $gv_output_data.

Referenced by parse_content().

setIsGravityviewPostType (   $is_gravityview_post_type)
Parameters
boolean$is_gravityview_post_type

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

References $is_gravityview_post_type.

Referenced by parse_content().

setIsSearch (   $is_search)
Parameters
boolean$is_search

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

References $is_search.

Referenced by parse_content().

setPostHasShortcode (   $post_has_shortcode)
Parameters
boolean$post_has_shortcode

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

References $post_has_shortcode.

Referenced by parse_content().

setPostId (   $post_id)
Parameters
int$post_id

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

References $post_id.

Referenced by parse_content().

setSingleEntry (   $single_entry)

Sets the single entry ID and also the entry.

Parameters
bool | int | string$single_entry

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

References $single_entry.

Referenced by set_entry_data().

single_entry_title (   $title,
  $passed_post_id = null 
)

Filter the title for the single entry view.

Parameters
string$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 430 of file class-frontend-views.php.

References $post, $title, $view_id, get_context_view_id(), getEntry(), getGvOutputData(), getSingleEntry(), and GravityView_API\replace_variables().

static updateViewSorting (   $args,
  $form_id 
)
static

Updates the View sorting criteria.

Since
1.7
Parameters
array$argsView settings. Required to have sort_field and sort_direction keys
int$form_idThe ID of the form used to sort
Returns
array $sorting Array with key, direction and is_numeric keys

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

References $form_id, GravityView_View\getInstance(), and GVCommon\is_field_numeric().

Field Documentation

$context_view_id = null

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

Referenced by get_context_view_id().

$entry = false

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

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

$gv_output_data = null

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

Referenced by getGvOutputData(), and setGvOutputData().

$instance
static

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

$is_gravityview_post_type = false

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

Referenced by isGravityviewPostType(), and setIsGravityviewPostType().

$is_search = false

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

Referenced by isSearch(), and setIsSearch().

$post_has_shortcode = false

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

Referenced by isPostHasShortcode(), and setPostHasShortcode().

$post_id = null

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

Referenced by getPostId(), and setPostId().

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

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

$single_entry = false

Definition at line 48 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: