GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-core.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * The core GravityView API.
11  *
12  * Returned by the wrapper gravityview() global function, exposes
13  * all the required public functionality and classes, sets up global
14  * state depending on current request context, etc.
15  */
16 final class Core {
17  /**
18  * @var \GV\Core The \GV\Core static instance.
19  */
20  private static $__instance = null;
21 
22  /**
23  * @var \GV\Plugin The WordPress plugin context.
24  *
25  * @api
26  * @since 2.0
27  */
28  public $plugin;
29 
30  /**
31  * @var \GV\Admin_Request|\GV\Frontend_Request|\GV\Request The global request.
32  *
33  * @api
34  * @since 2.0
35  */
36  public $request;
37 
38  /**
39  * @var \GV\Logger
40  *
41  * @api
42  * @since 2.0
43  */
44  public $log;
45 
46  /**
47  * Get the global instance of \GV\Core.
48  *
49  * @return \GV\Core The global instance of GravityView Core.
50  */
51  public static function get() {
52  if ( ! self::$__instance instanceof self ) {
53  self::$__instance = new self;
54  }
55  return self::$__instance;
56  }
57 
58  /**
59  * Very early initialization.
60  *
61  * Activation handlers, rewrites, post type registration.
62  */
63  public static function bootstrap() {
64  require_once dirname( __FILE__ ) . '/class-gv-plugin.php';
65  Plugin::get()->register_activation_hooks();
66  }
67 
68  /**
69  * Bootstrap.
70  *
71  * @return void
72  */
73  private function __construct() {
74  self::$__instance = $this;
75  $this->init();
76  }
77 
78  /**
79  * Early initialization.
80  *
81  * Loads dependencies, sets up the object, adds hooks, etc.
82  *
83  * @return void
84  */
85  private function init() {
86  $this->plugin = Plugin::get();
87 
88  /** Enable logging. */
89  require_once $this->plugin->dir( 'future/includes/class-gv-logger.php' );
90  /**
91  * @filter `gravityview/logger` Filter the logger instance being used for logging.
92  * @param \GV\Logger $logger The logger instance.
93  */
94  $this->log = apply_filters( 'gravityview/logger', new WP_Action_Logger() );
95 
96  /**
97  * Utilities.
98  */
99  require_once $this->plugin->dir( 'future/includes/class-gv-utils.php' );
100 
101  /** The Settings. */
102  require_once $this->plugin->dir( 'future/includes/class-gv-settings.php' );
103  require_once $this->plugin->dir( 'future/includes/class-gv-settings-view.php' );
104 
105  /** Request. */
106  require_once $this->plugin->dir( 'future/includes/class-gv-request.php' );
107 
108  if ( Request::is_admin() ) {
109  $this->request = new Admin_Request();
110  } else {
111  $this->request = new Frontend_Request();
112  }
113 
114  /** Require critical legacy core files. @todo Deprecate */
115  require_once $this->plugin->dir( 'includes/import-functions.php' );
116  require_once $this->plugin->dir( 'includes/helper-functions.php' );
117  require_once $this->plugin->dir( 'includes/class-common.php');
118  require_once $this->plugin->dir( 'includes/connector-functions.php');
119  require_once $this->plugin->dir( 'includes/class-gravityview-compatibility.php' );
120  require_once $this->plugin->dir( 'includes/class-gravityview-roles-capabilities.php' );
121  require_once $this->plugin->dir( 'includes/class-gravityview-admin-notices.php' );
122  require_once $this->plugin->dir( 'includes/class-admin.php' );
123  require_once $this->plugin->dir( 'includes/class-post-types.php');
124  require_once $this->plugin->dir( 'includes/class-cache.php');
125 
126  /**
127  * GravityView extensions and widgets.
128  */
129  require_once $this->plugin->dir( 'future/includes/class-gv-extension.php' );
130  require_once $this->plugin->dir( 'future/includes/class-gv-widget.php' );
131 
132  /** More legacy core. @todo Deprecate */
133  $this->plugin->include_legacy_core();
134 
135  /**
136  * Stop all further functionality from loading if the WordPress
137  * plugin is incompatible with the current environment.
138  *
139  * Saves some time and memory.
140  */
141  if ( ! $this->plugin->is_compatible() ) {
142  $this->log->error( 'GravityView 2.0 is not compatible with this environment. Stopped loading.' );
143  return;
144  }
145 
146  /** Register the gravityview post type upon WordPress core init. */
147  require_once $this->plugin->dir( 'future/includes/class-gv-view.php' );
148  add_action( 'init', array( '\GV\View', 'register_post_type' ) );
149  add_action( 'init', array( '\GV\View', 'add_rewrite_endpoint' ) );
150  add_filter( 'map_meta_cap', array( '\GV\View', 'restrict' ), 11, 4 );
151  add_action( 'template_redirect', array( '\GV\View', 'template_redirect' ) );
152  add_action( 'the_content', array( '\GV\View', 'content' ) );
153 
154  /** Add rewrite endpoint for single-entry URLs. */
155  require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' );
156  add_action( 'init', array( '\GV\Entry', 'add_rewrite_endpoint' ) );
157 
158  /** REST API */
159  require_once $this->plugin->dir( 'future/includes/rest/class-gv-rest-core.php' );
160  add_action( 'rest_api_init', array( '\GV\REST\Core', 'init' ) );
161 
162  /** Generate custom slugs on entry save. @todo Deprecate. */
163  add_action( 'gform_entry_created', array( '\GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
164 
165  /** Shortcodes */
166  require_once $this->plugin->dir( 'future/includes/class-gv-shortcode.php' );
167  require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gravityview.php' );
168  require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gventry.php' );
169  require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvfield.php' );
170  require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvlogic.php' );
171  add_action( 'init', array( '\GV\Shortcodes\gravityview', 'add' ) );
172  add_action( 'init', array( '\GV\Shortcodes\gventry', 'add' ) );
173  add_action( 'init', array( '\GV\Shortcodes\gvfield', 'add' ) );
174  add_action( 'init', array( '\GV\Shortcodes\gvlogic', 'add' ) );
175 
176  /** oEmbed */
177  require_once $this->plugin->dir( 'future/includes/class-gv-oembed.php' );
178  add_action( 'init', array( '\GV\oEmbed', 'init' ), 11 );
179 
180  /** Our Source generic and beloved source and form backend implementations. */
181  require_once $this->plugin->dir( 'future/includes/class-gv-source.php' );
182  require_once $this->plugin->dir( 'future/includes/class-gv-source-internal.php' );
183  require_once $this->plugin->dir( 'future/includes/class-gv-form.php' );
184  require_once $this->plugin->dir( 'future/includes/class-gv-form-gravityforms.php' );
185 
186  /** Joins */
187  require_once $this->plugin->dir( 'future/includes/class-gv-form-join.php' );
188 
189  /** Our Entry generic and beloved entry backend implementations. */
190  require_once $this->plugin->dir( 'future/includes/class-gv-entry-gravityforms.php' );
191  require_once $this->plugin->dir( 'future/includes/class-gv-entry-multi.php' );
192 
193  /** Context is everything. */
194  require_once $this->plugin->dir( 'future/includes/class-gv-context.php' );
195  require_once $this->plugin->dir( 'future/includes/class-gv-context-template.php' );
196 
197  /** Our Field generic and implementations. */
198  require_once $this->plugin->dir( 'future/includes/class-gv-field.php' );
199  require_once $this->plugin->dir( 'future/includes/class-gv-field-gravityforms.php' );
200  require_once $this->plugin->dir( 'future/includes/class-gv-field-internal.php' );
201 
202  /** Get the collections ready. */
203  require_once $this->plugin->dir( 'future/includes/class-gv-collection.php' );
204  require_once $this->plugin->dir( 'future/includes/class-gv-collection-form.php' );
205  require_once $this->plugin->dir( 'future/includes/class-gv-collection-field.php' );
206  require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry.php' );
207  require_once $this->plugin->dir( 'future/includes/class-gv-collection-widget.php' );
208  require_once $this->plugin->dir( 'future/includes/class-gv-collection-view.php' );
209 
210  /** The sorting, filtering and paging classes. */
211  require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-filter.php' );
212  require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-sort.php' );
213  require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-offset.php' );
214 
215  /** The Renderers. */
216  require_once $this->plugin->dir( 'future/includes/class-gv-renderer.php' );
217  require_once $this->plugin->dir( 'future/includes/class-gv-renderer-view.php' );
218  require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry.php' );
219  require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry-edit.php' );
220  require_once $this->plugin->dir( 'future/includes/class-gv-renderer-field.php' );
221 
222  /** Templating. */
223  require_once $this->plugin->dir( 'future/includes/class-gv-template.php' );
224  require_once $this->plugin->dir( 'future/includes/class-gv-template-view.php' );
225  require_once $this->plugin->dir( 'future/includes/class-gv-template-entry.php' );
226  require_once $this->plugin->dir( 'future/includes/class-gv-template-field.php' );
227  require_once $this->plugin->dir( 'future/includes/class-gv-template-legacy-override.php' );
228 
229  /** Magic. */
230  require_once $this->plugin->dir( 'future/includes/class-gv-wrappers.php' );
231 
232  /** Gutenberg Blocks. */
233  require_once $this->plugin->dir( 'future/includes/gutenberg/class-gv-gutenberg-blocks.php' );
234 
235  require_once $this->plugin->dir( 'includes/class-gravityview-powered-by.php' );
236 
237  /** Cache busting. */
238  add_action( 'clean_post_cache', '\GV\View::_flush_cache' );
239 
240  /**
241  * @action `gravityview/loaded` The core has been loaded.
242  *
243  * Note: this is a very early load hook, not all of WordPress core has been loaded here.
244  * `init` hasn't been called yet.
245  */
246  do_action( 'gravityview/loaded' );
247  }
248 
249  public function __clone() { }
250 
251  public function __wakeup() { }
252 
253  /**
254  * Wrapper magic.
255  *
256  * Making developers happy, since 2017.
257  */
258  public function __get( $key ) {
259  static $views;
260 
261  switch ( $key ) {
262  case 'views':
263  if ( is_null( $views ) ) {
264  $views = new \GV\Wrappers\views();
265  }
266  return $views;
267  }
268  }
269 
270  public function __set( $key, $value ) {
271  }
272 }
If this file is called directly, abort.
If this file is called directly, abort.
__construct()
Bootstrap.
__set( $key, $value)
init()
Early initialization.
If this file is called directly, abort.
If this file is called directly, abort.
static bootstrap()
Very early initialization.
__get( $key)
Wrapper magic.