GravityKit\GravityView\View\View
Source: src/View/View.php:58
Details
-
Kind:
class -
Namespace:
GravityKit\GravityView\View -
Implements:
ArrayAccess
Properties
| Property | Type | Description |
|---|---|---|
$settings | \GV\View_Settings | The settings. |
$widgets | \GV\Widget_Collection | The widgets attached here. |
$form | \GV\GF_Form | \GV\Form | The backing form for this view. Contains the form that is sourced for entries in this view. |
$fields | \GV\Field_Collection | The fields for this view. Contains all the fields that are attached to this view. |
$styles | \GravityKit\GravityView\Settings\ViewStyles | The design-token registry adapter for this View. Provides token discovery, sanitisation, and CSS emission for the View's saved palette / typography / spacing / effects overrides. Backed by static methods; the property is a thin namespace handle so callers can write $view->styles->emit_css_declarations( ... ) (see also scoped_selector(), sticky_header_css(), and prefers_contrast_css() for the per-View emission helpers). |
$joins | \GV\Join[] | The joins for all sources in this view. |
$unions | \GV\Field[][] | The unions for all sources in this view. An array of fields grouped by form_id keyed by main field_id: array( $form_id => array( $field_id => $field, $field_id => $field, ) ) |
Methods
| Method | Description |
|---|---|
__construct() | The constructor. |
add_rewrite_endpoint() | Add extra rewrite endpoints. |
content() | A renderer filter for the View post type content. |
can_render() | Checks whether this view can be accessed or not. |
lists_entries_from() | Whether the View lists entries of a form as its own rows: its form or a unioned form. |
get_entry() | The entry, when this View lists it as a row of its own form or a unioned form. |
lists_entry() | Whether this View lists the entry for the request, with all its filters applied. |
can_render_entry() | Whether this View shows the entry on its Single Entry page. |
get_form_ids() | The IDs of every form this View spans: its own form plus any joined or unioned forms. |
get_joins() | Get joins associated with a view |
get_joined_forms() | Get joined forms associated with a view |
get_unions() | Get unions associated with a view |
maybe_union_field() | Resolves a configured field to its unioned counterpart, if the form has a union mapping. |
apply_embed_settings() | Applies the attributes of the embed being rendered, such as a shortcode's, over the View's own settings. |
restore_embed_settings() | Undoes what {@see View::apply_embed_settings()} changed for a render, where nothing changed it since. |
add_embed_settings() | Adds an embed's attributes, read from a page without rendering it, to the View's settings. |
apply_embed() | Applies the attributes of one embed read from a page, over the View's own settings. |
has_embed() | Whether a page read for this View holds the embed with this key. |
embed_count() | Returns how many different embeds of this View were read from a post. |
entry_link_args() | Returns the query arguments an entry link needs to name the embed it came from. |
with_embed() | Runs a callback with one embed's settings applied, then puts the settings back. |
embed_key() | Returns a key naming an embed by its View, page, and attributes as written, the same for its render and for reading its page. |
from_post() | Construct a \GV\View instance from a \WP_Post. |
by_id() | Construct a \GV\View instance from a post ID. |
get_source() | Gets the source of the field. |
exists() | Determines if a view exists to begin with. |
is_hidden_until_searched() | Whether the View withholds its entries from this request because nothing was searched yet. |
get_entries() | Retrieve the entries for the current view and request. |
template_redirect() | Last chance to configure the output. |
get_query_class() | Return the query class for this View. |
restrict() | Restrict View access to specific capabilities. |
set_anchor_id() | Sets the anchor ID of a View, without the prefix. |
get_anchor_id() | Returns the anchor ID to be used in the View container HTML id attribute. |
__get() | Magic getter forwarded to the backing \WP_Post. |
get_post() | Return associated WP post |
get_validation_secret() | Calculates and returns the View's validation secret. |
get_validation_secret_by_id() | Calculates and returns a View's validation secret without hydrating the View. |
maybe_establish_secret_key_boundary() | Establishes the per-site secret-key boundary on this site's first run. |
validate_secret() | Returns whether the provided secret validates for this View. |
start_post_content() | Notes which post's content is being filtered, so a secret in it can be traced to who wrote it. |
start_acf_field() | Notes the post an ACF WYSIWYG field belongs to, so a secret in it is traced to that post's writers. |
end_post_content() | Ends what start_post_content() or start_acf_field() started. |
start_rest_callback() | Notes the route of the REST request whose callback is about to run. |
end_rest_callback() | Ends what start_rest_callback() started. |
remember_new_post_saver() | Remembers who wrote a new post's content. |
remember_post_saver() | Remembers who changed a post's content, from any editor. |
remember_meta_saver() | Remembers who changed a layout a post shows from its meta, such as an Elementor or View layout. |
maybe_record_legacy_secret_last_post_id() | Saves, once, the highest post ID on this site, so posts created later cannot pass as unchanged since the key. |
get_shortcode() | Returns the shortcode for this View. |
Method Reference
__construct()
public function __construct()
The constructor.
Source: src/View/View.php:314
add_rewrite_endpoint()
public static function add_rewrite_endpoint()
Add extra rewrite endpoints.
Returns
void
Source: src/View/View.php:456
content()
public static function content( $content )
A renderer filter for the View post type content.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$content | string | Should be empty, as we don't store anything there. |
Returns
string— $content The view content as output by the renderers.
Source: src/View/View.php:489
can_render()
public function can_render( $context=null, $request=null )
Checks whether this view can be accessed or not.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$context | string[] | null | The context we're asking for access from. Can any and as many of one of: edit An edit context. single A single context. cpt The custom post type single page accessed. shortcode Embedded as a shortcode. lightbox Rendered inside a GravityView entry lightbox. oembed Embedded as an oEmbed. rest A REST call. csv A CSV export. |
$request | Request | \WP_REST_Request | null | null | The request. |
Returns
bool|\WP_Error— An error if this View shouldn't be rendered here.
See Also
\View::can_render_entry()Whether the View shows a given entry on its Single Entry page.
Source: src/View/View.php:603
lists_entries_from()
public function lists_entries_from( $form_id ): bool
Whether the View lists entries of a form as its own rows: its form or a unioned form.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form_id | int | string | The form ID. |
Returns
bool
Since: 3.7.0
Source: src/View/View.php:707
get_entry()
public function get_entry( $entry_id ): ?Entry
The entry, when this View lists it as a row of its own form or a unioned form.
Like the View's Single Entry page, the page's search, sort and paging do not narrow the check.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$entry_id | int | string | The entry ID or slug. On a joined View, the IDs or slugs of one row, joined with commas. |
Returns
Entry|null— Null when the entry does not exist or the View leaves it out. On a joined View, the first row in the View's sort order that holds every entry named.
Since:
3.7.03.8.0(Returns the joined row on a joined View, and takes the View's own entry slugs for joined rows, such as12,34.)
Source: src/View/View.php:731
lists_entry()
public function lists_entry( Entry $entry, ?Request $request=null ): bool
Whether this View lists the entry for the request, with all its filters applied.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$entry | Entry | The entry. | |
$request | Request | null | null | The request. Default: the current request. |
Returns
bool
See Also
\View::can_render_entry()The Single Entry answer, which also checks the entry's status, approval and slug.
Since: 3.7.0
Source: src/View/View.php:760
can_render_entry()
public function can_render_entry( Entry $entry )
Whether this View shows the entry on its Single Entry page.
Checks the entry, or each entry of a joined row, the way the View's Single Entry page does:
the entry's status, approval and slug (\Entry::check_access()), Embed Only on the
View's own page, ?gvid= naming another View, and the View's filters (\View::lists_entry()).
All of them judge the current request. Users who may bypass Embed Only
(\DirectAccess::may_bypass()) pass it here, as they do on the View's list. Whether the
View itself renders is \View::can_render(); call that first.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$entry | Entry | The entry, or a joined entry. |
Returns
true|\WP_Error— True when the View shows the entry, or the first reason it does not.
See Also
\View::can_render()Whether the View itself renders; call it first.\View::lists_entry()Whether the View's filters list the entry.\Entry::check_access()The entry's status, approval and slug.\DirectAccess::may_bypass()Who may open an Embed Only View at its own address.\GVCommon::check_entry_display()The legacy check add-ons call: the View's rules only.\GravityKit\GravityView\Permissions\Permissions Capability checks for managing Views, not whether a visitor sees an entry.
Since: 3.10.0
Source: src/View/View.php:786
get_form_ids()
public function get_form_ids(): array
The IDs of every form this View spans: its own form plus any joined or unioned forms.
Returns
int[]
Since:
3.0.13.2.0(Includes unioned forms.)
Source: src/View/View.php:972
get_joins()
public static function get_joins( $post )
Get joins associated with a view
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post | \WP_Post | GravityView CPT to get joins for. |
Returns
\GV\Join[]— Array of \GV\Join instances
Since: 2.0.11
Source: src/View/View.php:1030
get_joined_forms()
public static function get_joined_forms( $post_id )
Get joined forms associated with a view
In no particular order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | ID of the View. |
Returns
\GV\GF_Form[]— Array of \GV\GF_Form instances
Since:
2.0.112.0
Source: src/View/View.php:1082
get_unions()
public static function get_unions( $post )
Get unions associated with a view
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post | \WP_Post | GravityView CPT to get unions for. |
Returns
- \GV\Field[][] — Array of unions (see self::$unions)
Since: 2.2.2
Source: src/View/View.php:1140
maybe_union_field()
public function maybe_union_field( $field, $form_id )
Resolves a configured field to its unioned counterpart, if the form has a union mapping.
The slot's display configuration (position, label, visibility, class, and link settings) is copied so the unioned field is presented exactly as the slot it replaces; only the value comes from the unioned form. A unioned form field of the same type also takes the slot's other settings.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field | \GV\Field | The configured field from the primary form. | |
$form_id | int | string | The form ID of the entry being rendered. |
Returns
- \GV\Field — The unioned field for the form, or the original field when there is no mapping.
Since: 3.2.0
Source: src/View/View.php:1204
apply_embed_settings()
public function apply_embed_settings( array $atts ): array
Applies the attributes of the embed being rendered, such as a shortcode's, over the View's own settings.
Every embed of a View on a page shares this object. A setting another embed gave a value this
embed does not set goes back to its value from before any embed, until the render ends and
\View::restore_embed_settings() puts it back. A value something else set since is kept.
An embed inside a render of this same View keeps the settings around it, such as a
detail="page_size" shortcode in the View's own widget.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array | The embed's attributes, in shortcode form. |
Returns
array— What the render changed, for {@see View::restore_embed_settings()}.
Since: 3.7.0
Source: src/View/View.php:1330
restore_embed_settings()
public function restore_embed_settings( array $state, bool $everything=false )
Undoes what {@see View::apply_embed_settings()} changed for a render, where nothing changed it since.
The other embeds' values set aside always come back. A nested render, such as a View counting its own entries in one of its fields, also puts back the settings it applied, so the render around it goes on with its own.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$state | array | What the render changed. | |
$everything | bool | false | Whether to put back the render's own attributes too. |
Returns
void
Since: 3.7.0
Source: src/View/View.php:1382
add_embed_settings()
public function add_embed_settings( array $atts, string $key='', int $post_id=0 )
Adds an embed's attributes, read from a page without rendering it, to the View's settings.
Settings from the page's other embeds of this View stay. Code that reads the page without knowing which embed it serves (the lightbox, REST, DataTables) then keeps every embed's search. A secured View skips an embed without its secret, since that embed never renders. While the View renders, as when an entry link reads the page, only the embed is recorded so the render keeps its own settings.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array | The embed's attributes, in shortcode form. | |
$key | string | '' | Optional. The embed's \View::embed_key(), so a request can name it later. |
$post_id | int | 0 | Optional. The ID of the post the embed was read from. |
Returns
void
Since: 3.7.0
Source: src/View/View.php:1426
apply_embed()
public function apply_embed( string $key ): bool
Applies the attributes of one embed read from a page, over the View's own settings.
Requests that come from a rendered embed (the lightbox, a live refresh) name it, so the page's other embeds of this View do not narrow or widen the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The embed's \View::embed_key(). |
Returns
bool— Whether an embed with that key was read from the page and applied.
Since: 3.7.0
Source: src/View/View.php:1464
has_embed()
public function has_embed( string $key ): bool
Whether a page read for this View holds the embed with this key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The embed's \View::embed_key(). |
Returns
bool
Since: 3.7.0
Source: src/View/View.php:1483
embed_count()
public function embed_count( int $post_id ): int
Returns how many different embeds of this View were read from a post.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | The ID of the post. |
Returns
int
Since: 3.7.0
Source: src/View/View.php:1496
entry_link_args()
public function entry_link_args( int $post_id ): array
Returns the query arguments an entry link needs to name the embed it came from.
Only a post that holds this View more than once needs them.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | The ID of the post the link points into. |
Returns
array
Since: 3.7.0
Source: src/View/View.php:1511
with_embed()
public function with_embed( string $key, callable $callback )
Runs a callback with one embed's settings applied, then puts the settings back.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The embed's \View::embed_key(). An embed not read from the page is ignored. | |
$callback | callable | The callback. |
Returns
mixed— What the callback returns.
Since: 3.7.0
Source: src/View/View.php:1531
embed_key()
public static function embed_key( array $atts, int $post_id=0 ): string
Returns a key naming an embed by its View, page, and attributes as written, the same for its render and for reading its page.
The key is signed with the site's salt, so a visitor learns only the keys of embeds rendered for them.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array | The embed's attributes as written, in shortcode form, including the View id. | |
$post_id | int | 0 | The ID of the post holding the embed, or 0 if unknown. |
Returns
string
Since: 3.7.0
Source: src/View/View.php:1557
from_post()
public static function from_post( $post )
Construct a \GV\View instance from a \WP_Post.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post | \WP_Post | The \WP_Post instance to wrap. |
Returns
- \GV\View |
null— An instance around this \WP_Post if valid, null otherwise.
Since: 2.0
Source: src/View/View.php:1609
by_id()
public static function by_id( $post_id )
Construct a \GV\View instance from a post ID.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | string | The post ID. |
Returns
- \GV\View |
null— An instance around this \WP_Post or null if not found.
Since: 2.0
Source: src/View/View.php:1740
get_source()
public static function get_source( $field, $view )
Gets the source of the field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field | \GV\Field | The field. | |
$view | \GV\View | The view. |
Returns
\GV\GF_Form|\GV\Internal_Source
Since: 2.33
Source: src/View/View.php:1816
exists()
public static function exists( $view )
Determines if a view exists to begin with.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$view | int | \WP_Post | null | The WordPress post ID, a \WP_Post object or null for global $post. |
Returns
bool— Whether the post exists or not.
Since: 2.0
Source: src/View/View.php:1848
is_hidden_until_searched()
public function is_hidden_until_searched( $request=null ): bool
Whether the View withholds its entries from this request because nothing was searched yet.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$request | Request | null | null | The request. Default: the current request. |
Returns
bool— True when "Hide View data until search is performed" is on and the request does not search this View.
Since: 3.6.0
Source: src/View/View.php:2191
get_entries()
public function get_entries( $request=null )
Retrieve the entries for the current view and request.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$request | Request | null | null | The request. |
Returns
- \GV\Entry_Collection — The entries.
Source: src/View/View.php:2252
template_redirect()
public static function template_redirect()
Last chance to configure the output.
Used for CSV output, for example.
Returns
void
Source: src/View/View.php:2987
get_query_class()
public function get_query_class()
Return the query class for this View.
Returns
string— The class name.
Source: src/View/View.php:3122
restrict()
public static function restrict( $caps, $cap, $user_id, $args )
Restrict View access to specific capabilities.
Hooked into map_meta_cap WordPress filter.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$caps | array | The output capabilities. | |
$cap | string | The cap that is being checked. | |
$user_id | int | The User ID. | |
$args | array | Additional arguments to the capability. |
Returns
array— The resulting capabilities.
Since: 3.0.0
Source: src/View/View.php:3146
set_anchor_id()
public function set_anchor_id( $counter=1 )
Sets the anchor ID of a View, without the prefix.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$counter | int | 1 | An incremental counter reflecting how many times this View has been rendered. |
Returns
void
Since: 2.15
Source: src/View/View.php:3191
get_anchor_id()
public function get_anchor_id()
Returns the anchor ID to be used in the View container HTML id attribute.
Returns
string— Unsanitized anchor ID.
Since: 2.15
Source: src/View/View.php:3202
__get()
public function __get( $key )
Magic getter forwarded to the backing \WP_Post.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The property name. |
Returns
mixed— The property value, or null if not set.
Source: src/View/View.php:3220
get_post()
public function get_post()
Return associated WP post
Returns
\WP_Post|null
Since: 2.13.2
Source: src/View/View.php:3235
get_validation_secret()
final public function get_validation_secret( bool $is_forced=false ): ?string
Calculates and returns the View's validation secret.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$is_forced | bool | false | Whether to compute the secret for non-secure Views too. |
Returns
string|null— The View's secret.
Since: 2.21
Source: src/View/View.php:3261
get_validation_secret_by_id()
public static function get_validation_secret_by_id( int $view_id, bool $is_forced=false ): ?string
Calculates and returns a View's validation secret without hydrating the View.
Bulk callers (e.g. the block editor View picker) use this so listing thousands of Views does not pay full View hydration per row.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$view_id | int | The View ID. | |
$is_forced | bool | false | Whether to compute the secret for non-secure Views too. |
Returns
string|null— The View's secret.
Since:
3.0.03.1.0(The secret is derived from a per-site random key stored in thegravityview_view_secret_keyoption. Embeds of Views that predate the per-site key keep working because validate_secret() still accepts the previous secret for them.)
Source: src/View/View.php:3282
maybe_establish_secret_key_boundary()
public static function maybe_establish_secret_key_boundary(): int
Establishes the per-site secret-key boundary on this site's first run.
Hooked to gravityview/loaded (an early, every-request action), so the
stored GMT timestamp is the moment this site first ran the per-site-key
code: activation time on a fresh install, first request after the update
on an upgrade. Writes once and returns the same boundary thereafter.
Returns
int— The boundary as a GMT Unix timestamp, or 0 if it cannot be persisted.
Since: 3.1.0
Source: src/View/View.php:3417
validate_secret()
final public function validate_secret( #[\SensitiveParameter] string $secret, ?\WP_Post $embed_post=null ): bool
Returns whether the provided secret validates for this View.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$secret | string | The provided secret. | |
$embed_post | \WP_Post | null | null | Optional. The post the embed was read from, when it is not being rendered. |
Returns
bool
Since:
2.213.1.0(The current secret is derived from a per-site key. The previous secret is accepted only for Views that predate the per-site key, so existing embeds keep working while newly created Views use only the per-site secret. Override with thegk/gravityview/view/secret/allow-legacyfilter.)3.9.0(The previous secret is accepted only where someone who can edit the View put it.)
Source: src/View/View.php:3483
start_post_content()
public static function start_post_content( $content )
Notes which post's content is being filtered, so a secret in it can be traced to who wrote it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$content | mixed | The post content. |
Returns
mixed— The content, unchanged.
Since: 3.9.0
Source: src/View/View.php:3547
start_acf_field()
public static function start_acf_field( $value, $post_id )
Notes the post an ACF WYSIWYG field belongs to, so a secret in it is traced to that post's writers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | mixed | The field value. | |
$post_id | int | string | What ACF loaded the value from: a post ID, or another ID such as options or user_2. |
Returns
mixed— The value, unchanged.
Since: 3.9.0
Source: src/View/View.php:3563
end_post_content()
public static function end_post_content( $content )
Ends what start_post_content() or start_acf_field() started.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$content | mixed | The post content. |
Returns
mixed— The content, unchanged.
Since: 3.9.0
Source: src/View/View.php:3606
start_rest_callback()
public static function start_rest_callback( $response, $handler, $request )
Notes the route of the REST request whose callback is about to run.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$response | mixed | The response so far. | |
$handler | array | The route's handler. | |
$request | \WP_REST_Request | The request. |
Returns
mixed— The response, unchanged.
Since: 3.9.0
Source: src/View/View.php:3653
end_rest_callback()
public static function end_rest_callback( $response )
Ends what start_rest_callback() started.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$response | mixed | The response. |
Returns
mixed— The response, unchanged.
Since: 3.9.0
Source: src/View/View.php:3668
remember_new_post_saver()
public static function remember_new_post_saver( $post_id, $post, $update )
Remembers who wrote a new post's content.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | Post ID. | |
$post | \WP_Post | The post. | |
$update | bool | Whether this is an update, which remember_post_saver() handles. |
Returns
void
Since: 3.9.0
Source: src/View/View.php:3795
remember_post_saver()
public static function remember_post_saver( $post_id, $post_after, $post_before )
Remembers who changed a post's content, from any editor.
Revisions can be turned off and _edit_last is not kept up to date, so neither is a reliable record.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | Post ID. | |
$post_after | \WP_Post | The post after the save. | |
$post_before | \WP_Post | The post before the save. |
Returns
void
Since: 3.9.0
Source: src/View/View.php:3814
remember_meta_saver()
public static function remember_meta_saver( $meta_id, $post_id, $meta_key )
Remembers who changed a layout a post shows from its meta, such as an Elementor or View layout.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$meta_id | int | Meta ID. | |
$post_id | int | Post ID. | |
$meta_key | string | Meta key. |
Returns
void
Since: 3.9.0
Source: src/View/View.php:3833
maybe_record_legacy_secret_last_post_id()
public static function maybe_record_legacy_secret_last_post_id(): void
Saves, once, the highest post ID on this site, so posts created later cannot pass as unchanged since the key.
Returns
void
Since: 3.9.0
Source: src/View/View.php:3920
get_shortcode()
final public function get_shortcode( array $atts=[] ): string
Returns the shortcode for this View.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array | [] | Additional attributes for the shortcode. |
Returns
string
Since:
2.212.22(Added$attsparameter.)
Source: src/View/View.php:3947