GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-data.php
Go to the documentation of this file.
1 <?php
2 
3 /** If this file is called directly, abort. */
4 if ( ! defined( 'ABSPATH' ) ) {
5  die;
6 }
7 
9 
10  static $instance = NULL;
11 
12  protected $views = array();
13 
14  /**
15  *
16  * @param null $passed_post
17  */
18  private function __construct( $passed_post = NULL ) {
19 
20  if( !empty( $passed_post ) ) {
21 
22  $id_or_id_array = $this->maybe_get_view_id( $passed_post );
23 
24  if( !empty( $id_or_id_array ) ) {
25  $this->add_view( $id_or_id_array );
26  }
27  }
28 
29  }
30 
31  /**
32  * @return boolean
33  */
34  public function has_multiple_views() {
35 
36  //multiple views
37  return count( $this->get_views() ) > 1 ? true : false;
38  }
39 
40 
41  /**
42  * Figure out what the View ID is for a variable, if any.
43  *
44  * Can be:
45  * - WP_Post (Either a `gravityview` post type or not)
46  * - Multi-dimensional array of WP_Post objects
47  * - Array with `view_id` or `id` key(s) set
48  * - String of content that may include GravityView shortcode
49  * - Number representing the Post ID or View ID
50  *
51  * @param mixed $passed_post See method description
52  *
53  * @return int|null|array ID of the View. If there are multiple views in the content, array of IDs parsed.
54  */
55  public function maybe_get_view_id( $passed_post ) {
56 
57  $ids = array();
58 
59  if( ! empty( $passed_post ) ) {
60 
61  if( is_numeric( $passed_post ) ) {
62  $passed_post = get_post( $passed_post );
63  }
64 
65  // Convert WP_Posts into WP_Posts[] array
66  if( $passed_post instanceof WP_Post ) {
67  $passed_post = array( $passed_post );
68  }
69 
70  if( is_array( $passed_post ) ) {
71 
72  foreach ( $passed_post as &$post) {
73  if( ( get_post_type( $post ) === 'gravityview' ) ) {
74  $ids[] = $post->ID;
75  } else{
76  // Parse the Post Content
77  $id = $this->parse_post_content( $post->post_content );
78  if( $id ) {
79  $ids = array_merge( $ids, (array) $id );
80  }
81 
82  // Parse the Post Meta
83  $id = $this->parse_post_meta( $post->ID );
84  if( $id ) {
85  $ids = array_merge( $ids, (array) $id );
86  }
87  }
88 
89  }
90 
91  } else {
92 
93  if ( is_string( $passed_post ) ) {
94 
95  $id = $this->parse_post_content( $passed_post );
96  if( $id ) {
97  $ids = array_merge( $ids, (array) $id );
98  }
99 
100  } else {
101  $id = $this->get_id_from_atts( $passed_post );
102  $ids[] = intval( $id );
103  }
104  }
105  }
106 
107  if( empty($ids) ) {
108  return NULL;
109  }
110 
111  // If it's just one ID, return that.
112  // Otherwise, return array of IDs
113  return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
114  }
115 
116  /**
117  * @return GravityView_View_Data
118  */
119  public static function getInstance( $passed_post = NULL ) {
120 
121  if( empty( self::$instance ) ) {
122  self::$instance = new GravityView_View_Data( $passed_post );
123  }
124 
125  return self::$instance;
126  }
127 
128  function get_views() {
129  return $this->views;
130  }
131 
132  function get_view( $view_id, $atts = NULL ) {
133 
134  if( ! is_numeric( $view_id) ) {
135  do_action('gravityview_log_error', sprintf('GravityView_View_Data[get_view] $view_id passed is not numeric.', $view_id) );
136  return false;
137  }
138 
139  // Backup: the view hasn't been fetched yet. Doing it now.
140  if ( ! isset( $this->views[ $view_id ] ) ) {
141  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] View #%s not set yet.', $view_id) );
142  return $this->add_view( $view_id, $atts );
143  }
144 
145  if ( empty( $this->views[ $view_id ] ) ) {
146  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] Returning; View #%s was empty.', $view_id) );
147  return false;
148  }
149 
150  return $this->views[ $view_id ];
151  }
152 
153  /**
154  * Determines if a post, identified by the specified ID, exist
155  * within the WordPress database.
156  *
157  * @see http://tommcfarlin.com/wordpress-post-exists-by-id/ Fastest check available
158  * @param int $view_id The ID of the post to check
159  * @return bool True if the post exists; otherwise, false.
160  * @since 1.0.0
161  */
162  function view_exists( $view_id ) {
163  return is_string( get_post_status( $view_id ) );
164  }
165 
166  /**
167  *
168  * Add a view to the views array
169  *
170  * @param int|array $view_id View ID or array of View IDs
171  * @param array|string $atts Combine other attributes (eg. from shortcode) with the view settings (optional)
172  * @return array
173  */
174  function add_view( $view_id, $atts = NULL ) {
175 
176  // Handle array of IDs
177  if( is_array( $view_id ) ) {
178  foreach( $view_id as $id ) {
179 
180  $this->add_view( $id, $atts );
181  }
182 
183  return $this->views;
184  }
185 
186  // The view has been set already; returning stored view.
187  if ( !empty( $this->views[ $view_id ] ) ) {
188  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id) );
189  return $this->views[ $view_id ];
190  }
191 
192  if( ! $this->view_exists( $view_id ) ) {
193  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id) );
194  return false;
195  }
196 
197  $form_id = gravityview_get_form_id( $view_id );
198 
199  if( empty( $form_id ) ) {
200 
201  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id) );
202 
203  return false;
204  }
205 
206  // Get the settings for the View ID
208 
209  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Settings pulled in from View #%s', $view_id), $view_settings );
210 
211  // Merge the view settings with the defaults
212  $view_defaults = wp_parse_args( $view_settings, self::get_default_args() );
213 
214  do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] View Defaults after merging View Settings with the default args.', $view_defaults );
215 
216  if( ! empty( $atts ) && is_array( $atts ) ) {
217 
218  do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts before merging with the $view_defaults', $atts );
219 
220  // Get the settings from the shortcode and merge them with defaults.
221  $atts = shortcode_atts( $view_defaults, $atts );
222 
223  do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts after merging with the $view_defaults', $atts );
224 
225  } else {
226 
227  // If there are no passed $atts, the defaults will be used.
228  $atts = $view_defaults;
229 
230  }
231 
232  unset( $atts['id'], $view_defaults, $view_settings );
233 
234  $data = array(
235  'id' => $view_id,
236  'view_id' => $view_id,
237  'form_id' => $form_id,
238  'template_id' => gravityview_get_template_id( $view_id ),
239  'atts' => $atts,
240  'fields' => $this->get_fields( $view_id ),
241  'widgets' => gravityview_get_directory_widgets( $view_id ),
242  'form' => gravityview_get_form( $form_id ),
243  );
244 
245  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] View #%s being added.', $view_id), $data );
246 
247  $this->views[ $view_id ] = $data;
248 
249  return $this->views[ $view_id ];
250  }
251 
252  /**
253  * Get the visible fields for a View
254  * @uses gravityview_get_directory_fields() Fetch the configured fields for a View
255  * @uses GravityView_View_Data::filter_fields() Only show visible fields
256  * @param int $view_id View ID
257  * @return array Array of fields as passed by `gravityview_get_directory_fields()`
258  */
259  function get_fields( $view_id ) {
260 
262  do_action( 'gravityview_log_debug', '[render_view] Fields: ', $dir_fields );
263 
264  // remove fields according to visitor visibility permissions (if logged-in)
265  $dir_fields = $this->filter_fields( $dir_fields );
266  do_action( 'gravityview_log_debug', '[render_view] Fields after visibility filter: ', $dir_fields );
267 
268  return $dir_fields;
269  }
270 
271  /**
272  * Filter area fields based on specified conditions
273  *
274  * @access public
275  * @param array $dir_fields
276  * @return array
277  */
278  private function filter_fields( $dir_fields ) {
279 
280  if( empty( $dir_fields ) || !is_array( $dir_fields ) ) {
281  return $dir_fields;
282  }
283 
284  foreach( $dir_fields as $area => $fields ) {
285 
286  foreach( (array)$fields as $uniqid => $properties ) {
287 
288  if( $this->hide_field_check_conditions( $properties ) ) {
289  unset( $dir_fields[ $area ][ $uniqid ] );
290  }
291 
292  }
293  }
294 
295  return $dir_fields;
296 
297  }
298 
299 
300  /**
301  * Check whether a certain field should not be presented based on its own properties.
302  *
303  * @access public
304  * @param array $properties
305  * @return boolean True: (field should be hidden) or False: (field should be presented)
306  */
307  private function hide_field_check_conditions( $properties ) {
308 
309  // logged-in visibility
310  if( ! empty( $properties['only_loggedin'] ) && ! GVCommon::has_cap( $properties['only_loggedin_cap'] ) ) {
311  return true;
312  }
313 
314  return false;
315  }
316 
317  function get_id_from_atts( $atts ) {
318 
319  $atts = is_array( $atts ) ? $atts : shortcode_parse_atts( $atts );
320 
321  // Get the settings from the shortcode and merge them with defaults.
322  $atts = wp_parse_args( $atts, self::get_default_args() );
323 
324  $view_id = ! empty( $atts['view_id'] ) ? (int)$atts['view_id'] : NULL;
325 
326  if( empty( $view_id ) && !empty( $atts['id'] ) ) {
327  $view_id = (int)$atts['id'];
328  }
329 
330  if( empty( $view_id ) ) {
331  do_action('gravityview_log_error', 'GravityView_View_Data[get_id_from_atts] Returning; no ID defined (Atts)', $atts );
332  return;
333  }
334 
335  return $view_id;
336  }
337 
338  /**
339  * Parse content to determine if there is a GV shortcode to allow for enqueing necessary files in the head.
340  *
341  * @uses gravityview_has_shortcode_r() Check whether shortcode exists (recursively)
342  * @uses shortcode_parse_atts() Parse each GV shortcode
343  * @uses gravityview_get_template_settings() Get the settings for the View ID
344  * @param string $content $post->post_content content
345  * @return int|null|array If a single View is found, the ID of the View. If there are multiple views in the content, array of IDs parsed. If not found, NULL
346  */
347  public function parse_post_content( $content ) {
348 
349  /**
350  * @hack This is so that the shortcode is registered for the oEmbed preview in the Admin
351  * @since 1.6
352  */
353  if( ! shortcode_exists('gravityview') && class_exists( 'GravityView_Shortcode' ) ) {
355  }
356 
357  $shortcodes = gravityview_has_shortcode_r( $content, 'gravityview' );
358 
359  if( empty( $shortcodes ) ) {
360  return NULL;
361  }
362 
363  do_action('gravityview_log_debug', 'GravityView_View_Data[parse_post_content] Parsing content, found shortcodes:', $shortcodes );
364 
365  $ids = array();
366 
367  foreach ($shortcodes as $key => $shortcode) {
368 
369  $shortcode[3] = htmlspecialchars_decode( $shortcode[3], ENT_QUOTES );
370 
371  $args = shortcode_parse_atts( $shortcode[3] );
372 
373  if( empty( $args['id'] ) ) {
374  do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_content] Returning; no ID defined in shortcode atts for Post #%s (Atts)', $post->ID ), $shortcode );
375  continue;
376  }
377 
378  do_action('gravityview_log_debug', sprintf('GravityView_View_Data[parse_post_content] Adding view #%s with shortcode args', $args['id']), $args );
379 
380  // Store the View to the object for later fetching.
381  $this->add_view( $args['id'], $args );
382 
383  $ids[] = $args['id'];
384  }
385 
386  if( empty($ids) ) {
387  return NULL;
388  }
389 
390  // If it's just one ID, return that.
391  // Otherwise, return array of IDs
392  return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
393 
394  }
395 
396  /**
397  * Parse specific custom fields (Post Meta) to determine if there is a GV shortcode to allow for enqueuing necessary files in the head.
398  * @since 1.15.1
399  * @uses \GravityView_View_Data::parse_post_content
400  * @param int $post_id WP_Post ID
401  * @return int|null|array If a single View is found, the ID of the View. If there are multiple views in the content, array of IDs parsed. If not found, or meta not parsed, NULL
402  */
403  private function parse_post_meta( $post_id ) {
404 
405  /**
406  * @filter `gravityview/data/parse/meta_keys` Define meta keys to parse to check for GravityView shortcode content
407  * This is useful when using themes that store content that may contain shortcodes in custom post meta
408  * @param[in,out] array $meta_keys Array of key values to check. If empty, do not check. Default: empty array
409  * @param[in] int $post_id ID of the post being checked
410  */
411  $meta_keys = (array)apply_filters( 'gravityview/data/parse/meta_keys', array(), $post_id );
412 
413  if( empty( $meta_keys ) ) {
414  return NULL;
415  }
416 
417  do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_meta] Search for GravityView shortcodes on the following custom fields keys:', $meta_keys );
418 
419  $meta_content = '';
420 
421  foreach( $meta_keys as $key ) {
422  $meta = get_post_meta( $post_id, $key , true );
423  if( ! is_string( $meta ) ) {
424  continue;
425  }
426  $meta_content .= $meta . ' ';
427  }
428 
429  if( empty( $meta_content ) ) {
430  do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_meta] Returning; Empty custom fields for Post #%s (Custom fields keys:)', $post_id ), $meta_keys );
431  return NULL;
432  }
433 
434  do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_meta] Combined content retrieved from custom fields:', $meta_content );
435 
436  return $this->parse_post_content( $meta_content );
437 
438  }
439 
440  /**
441  * Checks if the passed post id has the passed View id embedded.
442  *
443  * Returns
444  *
445  * @since 1.6.1
446  *
447  * @param string $post_id Post ID where the View is embedded
448  * @param string $view_id View ID
449  *
450  * @return bool|WP_Error If valid, returns true. If invalid, returns WP_Error containing error message.
451  */
452  public static function is_valid_embed_id( $post_id = '', $view_id = '', $empty_is_valid = true ) {
453 
454  $message = NULL;
455 
456  // Not invalid if not set!
457  if( empty( $post_id ) || empty( $view_id ) ) {
458 
459  if( $empty_is_valid ) {
460  return true;
461  }
462 
463  $message = esc_html__( 'The ID is required.', 'gravityview' );
464  }
465 
466  if( ! $message ) {
467  $status = get_post_status( $post_id );
468 
469  // Nothing exists with that post ID.
470  if ( ! is_numeric( $post_id ) ) {
471  $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.', 'gravityview' );
472 
473  // @todo Convert to generic article about Embed IDs
474  $message .= ' ' . gravityview_get_link( 'http://docs.gravityview.co/article/222-the-search-widget', __( 'Learn more&hellip;', 'gravityview' ), 'target=_blank' );
475  }
476  }
477 
478  if( ! $message ) {
479 
480  // Nothing exists with that post ID.
481  if ( empty( $status ) || in_array( $status, array( 'revision', 'attachment' ) ) ) {
482  $message = esc_html__( 'There is no post or page with that ID.', 'gravityview' );
483  }
484 
485  }
486 
487  if( ! $message ) {
488  $view_ids_in_post = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id );
489 
490  // The post or page specified does not contain the shortcode.
491  if ( false === in_array( $view_id, (array) $view_ids_in_post ) ) {
492  $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', 'gravityview' ), '<br /><code>[gravityview id="' . intval( $view_id ) . '"]</code>' );
493  }
494  }
495 
496  if( ! $message ) {
497 
498  // It's a View
499  if( 'gravityview' === get_post_type( $post_id ) ) {
500  $message = esc_html__( 'The ID is already a View.', 'gravityview' );;
501  }
502 
503  }
504 
505  if( $message ) {
506  return new WP_Error( 'invalid_embed_id', $message );
507  }
508 
509  return true;
510  }
511 
512  /**
513  * Get a specific default setting
514  * @param string $key The key of the setting array item
515  * @param boolean $with_details Include details
516  * @return mixed|array If using $with_details, return array. Otherwise, mixed.
517  */
518  public static function get_default_arg( $key, $with_details = false ) {
519 
520  $args = self::get_default_args( $with_details );
521 
522  if( !isset( $args[ $key ] ) ) { return NULL; }
523 
524  return $args[ $key ];
525  }
526 
527  /**
528  * Retrieve the default args for shortcode and theme function
529  *
530  * @param boolean $with_details True: Return array with full default settings information, including description, name, etc. False: Return an array with only key => value pairs.
531  * @param string $group Only fetch
532  *
533  * @return array $args Associative array of default settings for a View
534  * @param[out] string $label Setting label shown in admin
535  * @param[out] string $type Gravity Forms field type
536  * @param[out] string $group The field group the setting is associated with. Default: "default"
537  * @param[out] mixed $value The default value for the setting
538  * @param[out] string $tooltip Tooltip displayed for the setting
539  * @param[out] boolean $show_in_shortcode Whether to show the setting in the shortcode configuration modal
540  * @param[out] array $options Array of values to use when generating select, multiselect, radio, or checkboxes fields
541  * @param[out] boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering.
542  */
543  public static function get_default_args( $with_details = false, $group = NULL ) {
544 
545  /**
546  * @filter `gravityview_default_args` Modify the default settings for new Views
547  * @param[in,out] array $default_args Array of default args.
548  */
549  $default_settings = apply_filters( 'gravityview_default_args', array(
550  'id' => array(
551  'label' => __('View ID', 'gravityview'),
552  'type' => 'number',
553  'group' => 'default',
554  'value' => NULL,
555  'tooltip' => NULL,
556  'show_in_shortcode' => false,
557  ),
558  'page_size' => array(
559  'label' => __('Number of entries per page', 'gravityview'),
560  'type' => 'number',
561  'class' => 'small-text',
562  'group' => 'default',
563  'value' => 25,
564  'show_in_shortcode' => true,
565  ),
566  'lightbox' => array(
567  'label' => __( 'Enable lightbox for images', 'gravityview' ),
568  'type' => 'checkbox',
569  'group' => 'default',
570  'value' => 1,
571  'tooltip' => NULL,
572  'show_in_shortcode' => true,
573  ),
574  'show_only_approved' => array(
575  'label' => __( 'Show only approved entries', 'gravityview' ),
576  'type' => 'checkbox',
577  'group' => 'default',
578  'value' => 0,
579  'show_in_shortcode' => true,
580  ),
581  'admin_show_all_statuses' => array(
582  'label' => __( 'Show all entries to administrators', 'gravityview' ),
583  'desc' => __('Administrators will be able to see entries with any approval status.', 'gravityview'),
584  'tooltip' => __('Logged-out visitors and non-administrators will only see approved entries, while administrators will see entries with all statuses. This makes it easier for administrators to moderate entries from a View.', 'gravityview'),
585  'requires' => 'show_only_approved',
586  'type' => 'checkbox',
587  'group' => 'default',
588  'value' => 0,
589  'show_in_shortcode' => false,
590  ),
591  'hide_until_searched' => array(
592  'label' => __( 'Hide View data until search is performed', 'gravityview' ),
593  'type' => 'checkbox',
594  'group' => 'default',
595  'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ),
596  'value' => 0,
597  'show_in_shortcode' => false,
598  ),
599  'hide_empty' => array(
600  'label' => __( 'Hide empty fields', 'gravityview' ),
601  'group' => 'default',
602  'type' => 'checkbox',
603  'value' => 1,
604  'show_in_shortcode' => false,
605  ),
606  'user_edit' => array(
607  'label' => __( 'Allow User Edit', 'gravityview' ),
608  'group' => 'default',
609  'desc' => __('Allow logged-in users to edit entries they created.', 'gravityview'),
610  'value' => 0,
611  'tooltip' => __('Display "Edit Entry" fields to non-administrator users if they created the entry. Edit Entry fields will always be displayed to site administrators.', 'gravityview'),
612  'type' => 'checkbox',
613  'show_in_shortcode' => true,
614  ),
615  'user_delete' => array(
616  'label' => __( 'Allow User Delete', 'gravityview' ),
617  'group' => 'default',
618  'desc' => __('Allow logged-in users to delete entries they created.', 'gravityview'),
619  'value' => 0,
620  'tooltip' => __('Display "Delete Entry" fields to non-administrator users if they created the entry. Delete Entry fields will always be displayed to site administrators.', 'gravityview'),
621  'type' => 'checkbox',
622  'show_in_shortcode' => true,
623  ),
624  'sort_field' => array(
625  'label' => __('Sort by field', 'gravityview'),
626  'type' => 'select',
627  'value' => '',
628  'group' => 'sort',
629  'options' => array(
630  '' => __( 'Default', 'gravityview'),
631  'date_created' => __( 'Date Created', 'gravityview'),
632  ),
633  'show_in_shortcode' => true,
634  ),
635  'sort_direction' => array(
636  'label' => __('Sort direction', 'gravityview'),
637  'type' => 'select',
638  'value' => 'ASC',
639  'group' => 'sort',
640  'options' => array(
641  'ASC' => __('ASC', 'gravityview'),
642  'DESC' => __('DESC', 'gravityview'),
643  //'RAND' => __('Random', 'gravityview'),
644  ),
645  'show_in_shortcode' => true,
646  ),
647  'sort_columns' => array(
648  'label' => __( 'Enable sorting by column', 'gravityview' ),
649  'left_label' => __( 'Column Sorting', 'gravityview' ),
650  'type' => 'checkbox',
651  'value' => false,
652  'group' => 'sort',
653  'tooltip' => NULL,
654  'show_in_shortcode' => true,
655  'show_in_template' => array( 'default_table' ),
656  ),
657  'start_date' => array(
658  'label' => __('Filter by Start Date', 'gravityview'),
659  'class' => 'gv-datepicker',
660  'desc' => __('Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
661  'type' => 'text',
662  'value' => '',
663  'group' => 'filter',
664  'show_in_shortcode' => true,
665  ),
666  'end_date' => array(
667  'label' => __('Filter by End Date', 'gravityview'),
668  'class' => 'gv-datepicker',
669  'desc' => __('Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
670  'type' => 'text',
671  'value' => '',
672  'group' => 'filter',
673  'show_in_shortcode' => true,
674  ),
675  'class' => array(
676  'label' => __('CSS Class', 'gravityview'),
677  'desc' => __('CSS class to add to the wrapping HTML container.', 'gravityview'),
678  'group' => 'default',
679  'type' => 'text',
680  'value' => '',
681  'show_in_shortcode' => false,
682  ),
683  'search_value' => array(
684  'label' => __('Search Value', 'gravityview'),
685  'desc' => __('Define a default search value for the View', 'gravityview'),
686  'type' => 'text',
687  'value' => '',
688  'group' => 'filter',
689  'show_in_shortcode' => false,
690  ),
691  'search_field' => array(
692  'label' => __('Search Field', 'gravityview'),
693  'desc' => __('If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview'),
694  'type' => 'number',
695  'value' => '',
696  'group' => 'filter',
697  'show_in_shortcode' => false,
698  ),
699  'single_title' => array(
700  'label' => __('Single Entry Title', 'gravityview'),
701  'type' => 'text',
702  'desc' => __('When viewing a single entry, change the title of the page to this setting. Otherwise, the title will not change between the Multiple Entries and Single Entry views.', 'gravityview'),
703  'group' => 'default',
704  'value' => '',
705  'show_in_shortcode' => false,
706  'full_width' => true,
707  ),
708  'back_link_label' => array(
709  'label' => __('Back Link Label', 'gravityview'),
710  'group' => 'default',
711  'desc' => __('The text of the link that returns to the multiple entries view.', 'gravityview'),
712  'type' => 'text',
713  'value' => '',
714  'show_in_shortcode' => false,
715  'full_width' => true,
716  ),
717  'embed_only' => array(
718  'label' => __('Prevent Direct Access', 'gravityview'),
719  'group' => 'default',
720  'desc' => __('Only allow access to this View when embedded using the shortcode.', 'gravityview'),
721  'type' => 'checkbox',
722  'value' => '',
723  'show_in_shortcode' => false,
724  'full_width' => true,
725  ),
726  'post_id' => array(
727  'type' => 'number',
728  'value' => '',
729  'show_in_shortcode' => false,
730  ),
731  ));
732 
733  // By default, we only want the key => value pairing, not the whole array.
734  if( empty( $with_details ) ) {
735 
736  $defaults = array();
737 
738  foreach( $default_settings as $key => $value ) {
739  $defaults[ $key ] = $value['value'];
740  }
741 
742  return $defaults;
743 
744  }
745  // But sometimes, we want all the details.
746  else {
747 
748  foreach ($default_settings as $key => $value) {
749 
750  // If the $group argument is set for the method,
751  // ignore any settings that aren't in that group.
752  if( !empty( $group ) && is_string( $group ) ) {
753  if( empty( $value['group'] ) || $value['group'] !== $group ) {
754  unset( $default_settings[ $key ] );
755  }
756  }
757 
758  }
759 
760  return $default_settings;
761 
762  }
763  }
764 
765 
766 }
get_fields($view_id)
Get the visible fields for a View gravityview_get_directory_fields() Fetch the configured fields for...
Definition: class-data.php:259
static is_valid_embed_id($post_id= '', $view_id= '', $empty_is_valid=true)
Checks if the passed post id has the passed View id embedded.
Definition: class-data.php:452
maybe_get_view_id($passed_post)
Figure out what the View ID is for a variable, if any.
Definition: class-data.php:55
gravityview_get_template_id($post_id)
Get the template ID (list, table, datatables, map) for a View.
hide_field_check_conditions($properties)
Check whether a certain field should not be presented based on its own properties.
Definition: class-data.php:307
static has_cap($caps= '', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
$view_settings
gravityview_has_shortcode_r($content, $tag= 'gravityview')
Placeholder until the recursive has_shortcode() patch is merged.
static get_default_args($with_details=false, $group=NULL)
Retrieve the default args for shortcode and theme function.
Definition: class-data.php:543
If this file is called directly, abort.
Definition: class-data.php:8
filter_fields($dir_fields)
Filter area fields based on specified conditions.
Definition: class-data.php:278
view_exists($view_id)
Determines if a post, identified by the specified ID, exist within the WordPress database.
Definition: class-data.php:162
static getInstance($passed_post=NULL)
Definition: class-data.php:119
gravityview_get_directory_fields($post_id, $apply_filter=true)
Get the field configuration for the View.
__construct($passed_post=NULL)
Definition: class-data.php:18
gravityview_get_form($form_id)
Returns the form object for a given Form ID.
gravityview_get_directory_widgets($post_id)
Get the widgets, as configured for a View.
add_view($view_id, $atts=NULL)
Add a view to the views array.
Definition: class-data.php:174
gravityview_get_link($href= '', $anchor_text= '', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
get_view($view_id, $atts=NULL)
Definition: class-data.php:132
if(empty($created_by)) $form_id
static get_default_arg($key, $with_details=false)
Get a specific default setting.
Definition: class-data.php:518
global $post
gravityview_get_template_settings($post_id)
Get all the settings for a View.
gravityview_get_form_id($view_id)
Get the connected form ID from a View ID.
parse_post_meta($post_id)
Parse specific custom fields (Post Meta) to determine if there is a GV shortcode to allow for enqueui...
Definition: class-data.php:403
if(empty($field_settings['content'])) $content
Definition: custom.php:37
parse_post_content($content)
Parse content to determine if there is a GV shortcode to allow for enqueing necessary files in the he...
Definition: class-data.php:347