PluginProbe
Yatra – Travel Booking & Tour Operator Software / 1.0.0
Yatra – Travel Booking & Tour Operator Software v1.0.0
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / includes / class-yatra.php

class-yatra.php in Yatra – Travel Booking & Tour Operator Software 1.0.0, at includes/class-yatra.php

287 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Yatra setup
4 *
5 * @package Yatra
6 * @since 1.0.0
7 */
8
9 defined('ABSPATH') || exit;
10
11 /**
12 * Main Yatra Class.
13 *
14 * @class Yatra
15 */
16 final class Yatra
17 {
18
19 /**
20 * Yatra version.
21 *
22 * @var string
23 */
24 public $version = YATRA_VERSION;
25
26 /**
27 * The single instance of the class.
28 *
29 * @var Yatra
30 * @since 1.0.0
31 */
32 protected static $_instance = null;
33
34
35 /**
36 * Main Yatra Instance.
37 *
38 * Ensures only one instance of Yatra is loaded or can be loaded.
39 *
40 * @since 1.0.0
41 * @static
42 * @see mb_aec_addons()
43 * @return Yatra - Main instance.
44 */
45 public static function instance()
46 {
47 if (is_null(self::$_instance)) {
48 self::$_instance = new self();
49 }
50 return self::$_instance;
51 }
52
53 /**
54 * Cloning is forbidden.
55 *
56 * @since 1.0.0
57 */
58 public function __clone()
59 {
60 _doing_it_wrong(__FUNCTION__, __('Cloning is forbidden.', 'yatra'), '1.0.0');
61 }
62
63 /**
64 * Unserializing instances of this class is forbidden.
65 *
66 * @since 1.0.0
67 */
68 public function __wakeup()
69 {
70 _doing_it_wrong(__FUNCTION__, __('Unserializing instances of this class is forbidden.', 'yatra'), '1.0.0');
71 }
72
73 /**
74 * Auto-load in-accessible properties on demand.
75 *
76 * @param mixed $key Key name.
77 * @return mixed
78 */
79 public function __get($key)
80 {
81 if (in_array($key, array(''), true)) {
82 return $this->$key();
83 }
84 }
85
86 /**
87 * Yatra Constructor.
88 */
89 public function __construct()
90 {
91 $this->define_constants();
92 $this->includes();
93 $this->init_hooks();
94 do_action('yatra_loaded');
95 }
96
97 /**
98 * Hook into actions and filters.
99 *
100 * @since 1.0.0
101 */
102 private function init_hooks()
103 {
104
105 register_activation_hook(YATRA_FILE, array('Yatra_Install', 'install'));
106
107 add_action('init', array($this, 'init'), 0);
108 add_action('init', array('Yatra_Shortcodes', 'init'));
109
110
111 }
112
113 /**
114 * Define Yatra Constants.
115 */
116 private function define_constants()
117 {
118
119 $this->define('YATRA_ABSPATH', dirname(YATRA_FILE) . '/');
120 $this->define('YATRA_BASENAME', plugin_basename(YATRA_FILE));
121 }
122
123 /**
124 * Define constant if not already set.
125 *
126 * @param string $name Constant name.
127 * @param string|bool $value Constant value.
128 */
129 private function define($name, $value)
130 {
131 if (!defined($name)) {
132 define($name, $value);
133 }
134 }
135
136 /**
137 * What type of request is this?
138 *
139 * @param string $type admin, ajax, cron or frontend.
140 * @return bool
141 */
142 private function is_request($type)
143 {
144 switch ($type) {
145 case 'admin':
146 return is_admin();
147 case 'ajax':
148 return defined('DOING_AJAX');
149 case 'cron':
150 return defined('DOING_CRON');
151 case 'frontend':
152 return (!is_admin() || defined('DOING_AJAX')) && !defined('DOING_CRON') && !defined('REST_REQUEST');
153 }
154 }
155
156 /**
157 * Include required core files used in admin and on the frontend.
158 */
159 public function includes()
160 {
161
162 /**
163 * Class autoloader.
164 */
165 include_once YATRA_ABSPATH . 'includes/class-yatra-autoloader.php';
166 include_once YATRA_ABSPATH . 'includes/functions.php';
167 include_once YATRA_ABSPATH . 'includes/yatra-hooks.php';
168 include_once YATRA_ABSPATH . 'includes/class-yatra-page-templater.php';
169 include_once YATRA_ABSPATH . 'includes/class-yatra-custom-post-type.php';
170 include_once YATRA_ABSPATH . 'includes/class-yatra-taxonomy.php';
171 include_once YATRA_ABSPATH . 'includes/class-yatra-metabox.php';
172 include_once YATRA_ABSPATH . 'includes/class-yatra-shortcodes.php';
173 include_once YATRA_ABSPATH . 'includes/class-yatra-ajax.php';
174
175
176 // Compatibility
177 include_once YATRA_ABSPATH . 'includes/class-yatra-compatibility.php';
178
179
180 if ($this->is_request('admin')) {
181 Yatra_Admin::instance();
182 }
183
184 if ($this->is_request('frontend')) {
185 Yatra_Frontend::instance();
186 }
187
188 }
189
190
191 /**
192 * Init Yatra when WordPress Initialises.
193 */
194 public function init()
195 {
196 // Before init action.
197 do_action('before_yatra_init');
198
199 // Set up localisation.
200 $this->load_plugin_textdomain();
201
202
203 // Init action.
204 do_action('yatra_init');
205 }
206
207 /**
208 * Load Localisation files.
209 *
210 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
211 *
212 * Locales found in:
213 * - WP_LANG_DIR/yatra/yatra-LOCALE.mo
214 * - WP_LANG_DIR/plugins/yatra-LOCALE.mo
215 */
216 public function load_plugin_textdomain()
217 {
218 $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
219 $locale = apply_filters('plugin_locale', $locale, 'yatra');
220 unload_textdomain('yatra');
221 load_textdomain('yatra', WP_LANG_DIR . '/yatra/yatra-' . $locale . '.mo');
222 load_plugin_textdomain('yatra', false, plugin_basename(dirname(YATRA_FILE)) . '/i18n/languages');
223 }
224
225 /**
226 * Ensure theme and server variable compatibility and setup image sizes.
227 */
228 public function setup_environment()
229 {
230
231 $this->define('YATRA_TEMPLATE_PATH', $this->template_path());
232
233 }
234
235 /**
236 * Get the plugin url.
237 *
238 * @return string
239 */
240 public function plugin_url()
241 {
242 return untrailingslashit(plugins_url('/', YATRA_FILE));
243 }
244
245 /**
246 * Get the plugin path.
247 *
248 * @return string
249 */
250 public function plugin_path()
251 {
252 return untrailingslashit(plugin_dir_path(YATRA_FILE));
253 }
254
255 /**
256 * Get the template path.
257 *
258 * @return string
259 */
260 public function template_path()
261 {
262 return apply_filters('yatra_template_path', 'yatra/');
263 }
264
265 /**
266 * Get the template path.
267 *
268 * @return string
269 */
270 public function plugin_template_path()
271 {
272 return apply_filters('yatra_plugin_template_path', $this->plugin_path() . '/templates/');
273 }
274
275 /**
276 * Get Ajax URL.
277 *
278 * @return string
279 */
280 public function ajax_url()
281 {
282 return admin_url('admin-ajax.php', 'relative');
283 }
284
285
286 }
287