GravityView  2.10.1
The best, easiest way to display Gravity Forms entries on your website.
class-gv-wrappers.php
Go to the documentation of this file.
1 <?php
2 namespace GV\Wrappers;
3 
4 /**
5  * This file contains magic wrapper code for `gravityview()`.
6  *
7  * Every `gravityview()` magic key maps to a class that exposes more magic.
8  * Chains of infinite magic can be constructed spanning seas of mermaids,
9  * valleys of unicorns and whirlwinds of shooting stars.
10  */
11 
12 /**
13  * The views magic wrapper.
14  */
15 class views {
16 
17  /**
18  * @var \GV\View An internal View keeper.
19  */
20  private $view = null;
21 
22  /**
23  * Gets a View.
24  *
25  * Doesn't care what you provide it. Will try to find
26  * out what you need from the current context, from the supplied
27  * args, etc.
28  *
29  * @param string|int|array|\GV\View|\WP_Post|null Anything goes.
30  *
31  * @return \GV\View|null The detected View.
32  */
33  public function get( $view = null ) {
34 
35  /**
36  * By View.
37  */
38  if ( $view instanceof \GV\View && $view->ID ) {
39  return $this->get( $view->ID );
40  }
41 
42  /**
43  * By View ID.
44  */
45  if ( is_numeric( $view ) ) {
46  return \GV\View::by_id( $view );
47  }
48 
49  /**
50  * By post object.
51  */
52  if ( $view instanceof \WP_Post ) {
53  return \GV\View::from_post( $view );
54  }
55 
56  /**
57  * By array.
58  */
59  if ( is_array( $view ) && ! empty( $view['id'] ) ) {
60  return $this->get( $view['id'] );
61  }
62 
63  /**
64  * From various contexts.
65  */
66  if ( is_null( $view ) ) {
67  if ( gravityview()->request->is_renderable() && $view = gravityview()->request->is_view() ) {
68  return $view;
69  }
70 
71  global $post;
72 
73  if ( $post instanceof \WP_Post && $post->post_type == 'gravityview' ) {
74  return $this->get( $post );
75  }
76 
77  /**
78  * Final fallback.
79  */
80  return $this->view;
81  }
82 
83  return null;
84  }
85 
86  /**
87  * Mock the internal pointer.
88  *
89  * @param \GV\View $view The View to supply on fallback in ::get()
90  *
91  * @return void
92  */
93  public function set( $view ) {
94  $this->view = $view;
95  }
96 }
This file contains magic wrapper code for gravityview().
gravityview()
Definition: _stubs.php:26
global $post
Definition: delete-entry.php:7
If this file is called directly, abort.