4 if ( ! defined(
'ABSPATH' ) ) {
19 $this->views = new \GV\View_Collection();
21 if ( ! empty( $passed_post ) ) {
23 foreach( is_array( $id_or_id_array ) ? $id_or_id_array : array( $id_or_id_array ) as
$view_id ) {
24 if ( \
GV\View::exists( $view_id ) && ! $this->views->contains( $view_id ) ) {
25 $this->views->add( \
GV\View::by_id( $view_id ) );
38 return $this->views->count() > 1;
61 if ( empty( $passed_post ) ) {
67 if ( is_numeric( $passed_post ) ) {
68 $passed_post = get_post( $passed_post );
72 if ( $passed_post instanceof WP_Post ) {
73 $passed_post = array( $passed_post );
76 if ( is_array( $passed_post ) ) {
78 foreach ( $passed_post as &
$post ) {
80 foreach (
$views->all() as $view ) {
84 if ( ! $this->views->contains( $view->ID ) ) {
85 $this->views->add( $view );
92 if ( is_string( $passed_post ) ) {
94 foreach ( $shortcodes as $shortcode ) {
95 if ( $shortcode->name ==
'gravityview' && !empty( $shortcode->atts[
'id'] ) ) {
96 $ids []= $shortcode->atts[
'id'];
99 if ( ! $this->views->contains( $shortcode->atts[
'id'] ) &&
\GV\View::exists( $shortcode->atts[
'id'] ) ) {
100 $this->views->add( $shortcode->atts[
'id'] );
106 $ids[] = intval( $id );
110 if ( empty( $ids ) ) {
116 return ( count( $ids ) === 1 ) ? $ids[0] : $ids;
124 if( empty( self::$instance ) ) {
128 return self::$instance;
136 if ( ! $this->views->count() ) {
139 return array_combine(
140 array_map(
function ( $view ) {
return $view->ID; }, $this->views->all() ),
141 array_map(
function ( $view ) {
return $view->as_data(); }, $this->views->all() )
150 if ( ! $view = $this->views->get(
$view_id ) ) {
158 $view->settings->update( $atts );
160 $this->views->add( $view );
162 $view->settings->update( $atts );
169 return $view->as_data();
186 return \GV\View::exists(
$view_id );
219 return $view->fields->by_visible( $view )->as_configuration();
233 $settings->update( shortcode_parse_atts( $atts ) );
254 foreach ( \
GV\Shortcode::parse(
$content ) as $shortcode ) {
255 if ( $shortcode->name ==
'gravityview' && is_numeric( $shortcode->atts[
'id'] ) ) {
256 if ( \
GV\View::exists( $shortcode->atts[
'id'] ) && ! $this->views->contains( $shortcode->atts[
'id'] ) ) {
257 $this->views->add( \
GV\View::by_id( $shortcode->atts[
'id'] ) );
264 $ids []= $shortcode->atts[
'id'];
267 if ( empty ( $ids ) ) {
270 return (
sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
291 if ( empty( $post_id ) || empty(
$view_id ) ) {
293 if( $empty_is_valid ) {
297 $message = esc_html__(
'The ID is required.',
'gk-gravityview' );
301 $status = get_post_status( $post_id );
304 if ( ! is_numeric( $post_id ) ) {
305 $message = esc_html__(
'You did not enter a number. The value entered should be a number, representing the ID of the post or page the View is embedded on.',
'gk-gravityview' );
308 $message .=
' ' .
gravityview_get_link(
'https://docs.gravityview.co/article/222-the-search-widget', __(
'Learn more…',
'gk-gravityview' ),
'target=_blank' );
315 if ( empty( $status ) || in_array( $status, array(
'revision',
'attachment' ) ) ) {
316 $message = esc_html__(
'There is no post or page with that ID.',
'gk-gravityview' );
321 if ( ! $message &&
$post = get_post( $post_id ) ) {
323 $view_ids_in_post = array_map(
function( $view ) {
return $view->ID; },
$views->all() );
326 if (
false === in_array(
$view_id, (array) $view_ids_in_post ) ) {
327 $message = sprintf( esc_html__(
'The Post ID entered is not valid. You may have entered a post or page that does not contain the selected View. Make sure the post contains the following shortcode: %s',
'gk-gravityview' ),
'<br /><code>[gravityview id="' . intval(
$view_id ) .
'"]</code>' );
333 if ( \
GV\View::exists( $post_id ) ) {
334 $message = esc_html__(
'The ID is already a View.',
'gk-gravityview' );;
339 return new WP_Error(
'invalid_embed_id', $message );
355 if ( ! isset(
$args[ $key ] ) ) {
359 return $args[ $key ];
382 return \GV\View_Settings::defaults( $with_details, $group );
GravityView_View_Data_add_view( $view_id, $atts, $_this)
This file contains mock code for deprecated functions.
__construct( $passed_post=NULL)
static getInstance( $passed_post=NULL)
maybe_get_view_id( $passed_post=null)
Figure out what the View ID is for a variable, if any.
static with_defaults( $detailed=false)
Retrieve an instance of the settings with default values.
get_view( $view_id, $atts=NULL)
add_view( $view_id, $atts=NULL)
Add a view to the views array.
view_exists( $view_id)
Determines if a post, identified by the specified ID, exist within the WordPress database.
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
static from_post(\WP_Post $post)
Get a list of objects inside the supplied .
static is_valid_embed_id( $post_id='', $view_id='', $empty_is_valid=false)
Checks if the passed post id has the passed View id embedded.
If this file is called directly, abort.
if(empty( $field_settings['content'])) $content
get_fields( $view_id)
Get the visible fields for a View gravityview_get_directory_fields() Fetch the configured fields for...
static exists( $view)
Determines if a view exists to begin with.
static by_id( $post_id)
Construct a instance from a post ID.
static get_default_args( $with_details=false, $group=NULL)
Retrieve the default args for shortcode and theme function.
parse_post_content( $content)
Parse content to determine if there is a GV shortcode to allow for enqueing necessary files in the he...
get_id_from_atts( $atts)
Retrieves view ID from an array.
static parse( $content)
Parse a string of content and figure out which ones there are.
static defaults( $detailed=false, $group=null)
Retrieve the default View settings.
static get_default_arg( $key, $with_details=false)
Get a specific default setting.