PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.39
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.39
9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 8.5.4 All 221 releases
wpvr / includes / class-wpvr.php

class-wpvr.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.39, at includes/class-wpvr.php

512 lines 14.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link http://rextheme.com/
10 * @since 8.0.0
11 *
12 * @package Wpvr
13 * @subpackage Wpvr/includes
14 */
15
16 use WPVR\Builder\DIVI\WPVR_Divi_modules;
17
18 /**
19 * The core plugin class.
20 *
21 * This is used to define internationalization, admin-specific hooks, and
22 * public-facing site hooks.
23 *
24 * Also maintains the unique identifier of this plugin as well as the current
25 * version of the plugin.
26 *
27 * @since 8.0.0
28 * @package Wpvr
29 * @subpackage Wpvr/includes
30 * @author Rextheme <support@rextheme.com>
31 */
32 class Wpvr
33 {
34
35 /**
36 * The loader that's responsible for maintaining and registering all hooks that power
37 * the plugin.
38 *
39 * @since 8.0.0
40 * @access protected
41 * @var Wpvr_Loader $loader Maintains and registers all hooks for the plugin.
42 */
43 protected $loader;
44
45 /**
46 * The unique identifier of this plugin.
47 *
48 * @since 8.0.0
49 * @access protected
50 * @var string $plugin_name The string used to uniquely identify this plugin.
51 */
52 protected $plugin_name;
53
54 /**
55 * The current version of the plugin.
56 *
57 * @since 8.0.0
58 * @access protected
59 * @var string $version The current version of the plugin.
60 */
61 protected $version;
62
63 /**
64 * The post type for the plugin
65 *
66 * @since 8.0.0
67 * @var string $version The current version of the plugin.
68 */
69 protected $post_type;
70
71 /**
72 * Instacne of WPVR_Post_Type
73 *
74 * @var object
75 * @since 8.0.0
76 */
77 protected $wpvr_post_type;
78
79 /**
80 * Instance of Wpvr_Admin class
81 *
82 * @var object
83 * @since 8.0.0
84 */
85 protected $plugin_admin;
86
87 /**
88 * Holds instances or information about the DIVI modules used in the builder.
89 *
90 * This property may store an array of module instances or configurations, depending
91 * on how it's utilized within the class. It's used to manage and reference DIVI modules
92 * effectively within custom builder implementations.
93 *
94 * @var array
95 */
96 protected $divi_modules;
97
98 /**
99 * Define the core functionality of the plugin.
100 *
101 * Set the plugin name and the plugin version that can be used throughout the plugin.
102 * Load the dependencies, define the locale, and set the hooks for the admin area and
103 * the public-facing side of the site.
104 *
105 * @since 8.0.0
106 */
107 public function __construct()
108 {
109 if (defined('WPVR_VERSION')) {
110 $this->version = WPVR_VERSION;
111 } else {
112 $this->version = '8.0.0';
113 }
114 $this->plugin_name = 'wpvr';
115 $this->post_type = 'wpvr_item';
116
117 $this->load_dependencies();
118 $this->set_locale();
119 $this->define_admin_hooks();
120 $this->define_public_hooks();
121 add_action('plugins_loaded', array($this, 'load_plugin'), 99);
122 add_action('init', array($this, 'register_wpvr_setup_wizard'));
123 add_action('admin_init', array($this, 'admin_redirects'));
124 add_filter('wpvr_tracking_enabled', array($this, 'wpvr_tracking_enabled'));
125 }
126 /**
127 * Initializes and loads the DIVI modules into the class property.
128 *
129 * This method sets up the DIVI modules by fetching an instance of the WPVR_Divi_modules class
130 * and storing it in the divi_modules property. It ensures that the modules are ready to be
131 * used within the plugin.
132 *
133 * @since 8.4.8 This method was introduced in version 8.4.8 to streamline the initialization of DIVI modules.
134 */
135 public function load_plugin()
136 {
137 $this->divi_modules = WPVR_Divi_modules::instance();
138 }
139
140
141 /**
142 * Load the required dependencies for this plugin.
143 *
144 * Include the following files that make up the plugin:
145 *
146 * - Wpvr_Loader. Orchestrates the hooks of the plugin.
147 * - Wpvr_i18n. Defines internationalization functionality.
148 * - Wpvr_Admin. Defines all hooks for the admin area.
149 * - Wpvr_Public. Defines all hooks for the public side of the site.
150 *
151 * Create an instance of the loader which will be used to register the hooks
152 * with WordPress.
153 *
154 * @since 8.0.0
155 * @access private
156 */
157 private function load_dependencies()
158 {
159
160 /**
161 * The class responsible for auto loading all files of the core plugin.
162 */
163 require_once plugin_dir_path(__DIR__) . 'vendor/autoload.php';
164
165 /**
166 * The class responsible for orchestrating the actions and filters of the core plugin.
167 */
168 require_once plugin_dir_path(__DIR__) . 'includes/class-wpvr-loader.php';
169
170 /**
171 * The class responsible for defining internationalization functionality of the plugin.
172 */
173 require_once plugin_dir_path(__DIR__) . 'includes/class-wpvr-i18n.php';
174
175 $this->loader = new Wpvr_Loader();
176 }
177
178
179 /**
180 * Define the locale for this plugin for internationalization.
181 *
182 * Uses the Wpvr_i18n class in order to set the domain and to register the hook
183 * with WordPress.
184 *
185 * @since 8.0.0
186 * @access private
187 */
188 private function set_locale()
189 {
190 $plugin_i18n = new Wpvr_i18n();
191 $this->loader->add_action('init', $plugin_i18n, 'load_plugin_textdomain');
192 }
193
194
195 /**
196 * Register all of the hooks related to the admin area functionality
197 * of the plugin.
198 *
199 * @since 8.0.0
200 * @access private
201 */
202 private function define_admin_hooks()
203 {
204 if ( ! function_exists( 'is_plugin_active' ) ) {
205 require_once ABSPATH . 'wp-admin/includes/plugin.php';
206 }
207 $this->plugin_admin = new Wpvr_Admin($this->get_plugin_name(), $this->get_version(), $this->get_post_type());
208
209 $this->loader->add_filter('plugin_action_links_' . WPVR_BASE, $this->plugin_admin, 'plugin_action_links_wpvr', 10, 4);
210 $this->loader->add_action('admin_enqueue_scripts', $this->plugin_admin, 'enqueue_styles');
211 $this->loader->add_action('admin_enqueue_scripts', $this->plugin_admin, 'enqueue_scripts');
212 $this->loader->add_action('publish_wpvr_item', $this->plugin_admin, 'show_review_request_markups', 99999);
213 $this->loader->add_action('admin_init', $this->plugin_admin, 'wpvr_trigger_based_review_helper', 99999);
214 $high_res_image = get_option('high_res_image');
215
216 if ($high_res_image == 'true') { //phpcs:ignore
217 add_filter('big_image_size_threshold', '__return_false');
218 }
219
220 $this->loader->add_action('admin_init', $this->plugin_admin, 'trigger_rollback');
221
222 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')){
223 $this->loader->add_action('include_floor_plan_meta_content', $this, 'include_floor_plan_meta_content', 10, 1);
224 $this->loader->add_action('include_background_tour_meta_content', $this, 'include_background_tour_meta_content', 10, 1);
225 $this->loader->add_action('include_street_view_meta_content', $this, 'include_street_view_meta_content', 10, 1);
226 $this->loader->add_action('include_export_meta_content', $this, 'include_export_meta_content', 10, 2);
227 }
228
229 }
230
231 public function include_floor_plan_meta_content($post_data)
232 {
233 ?>
234
235 <div class="rex-pano-tab floor-plan" id="floorPlan">
236 <h6 class="title"> <?php echo __('Floor Plan Settings : ', 'wpvr-pro');?> </h6>
237
238 <div class="content-wrapper">
239
240 <div class="floor-plan-left">
241 <!-- bg tour on/off -->
242 <div class="single-settings inline-style">
243 <span> <?php echo __('Enable Floor Plan: ', 'wpvr-pro') ?> </span>
244 <span class="wpvr-switcher">
245 <input id="wpvr_floor_plan_enabler" class="vr-switcher-check wpvr_floor_plan_enabler" name="wpvr_floor_plan_enabler" disabled type="checkbox"/>
246 <label for="wpvr_floor_plan_enabler"></label>
247 </span>
248
249
250 <div class="field-tooltip">
251 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'admin/icon/tooltip-icon.svg'?>" alt="icon" />
252
253 <span>
254 <?php
255 echo wp_kses(
256 sprintf(
257 __('Activate the floor plan view for your virtual tour. <a href="%s" target="_blank" rel="noopener noreferrer">View Doc</a>', 'wpvr'),
258 esc_url('https://rextheme.com/docs/virtual-floor-plans-inside-tours/#0-toc-title')
259 ),
260 array(
261 'a' => array('href' => array(), 'target' => array(), 'rel' => array())
262 )
263 );
264 ?>
265 </span>
266 </div>
267
268
269 </div>
270
271 </div>
272
273 </div>
274
275 </div>
276
277 <?php
278 }
279
280 public function include_background_tour_meta_content($post_data)
281 {
282 ?>
283
284 <div class="rex-pano-tab background-tour" id="backgroundTour">
285 <h6 class="title"> <?= __('Background Tour Settings : ', 'wpvr');?> </h6>
286
287 <div class="content-wrapper">
288 <div class="background-tour-left">
289 <!-- bg tour on/off -->
290 <div class="single-settings inline-style">
291 <span> <?= __('Enable Background Tour: ', 'wpvr') ?> </span>
292
293 <span class="wpvr-switcher">
294 <input id="wpvr_bg_tour_enabler" class="vr-switcher-check wpvr_bg_tour_enabler" name="wpvr_bg_tour_enabler" type="checkbox" disabled />
295 <label for="wpvr_bg_tour_enabler"></label>
296 </span>
297
298 <div class="field-tooltip">
299 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'admin/icon/tooltip-icon.svg'?>" alt="icon" />
300
301 <span>
302 <?php
303 echo wp_kses(
304 sprintf(
305 __('When enabled, a title and subtitle will appear at the top of the tour. <a href="%s" target="_blank" rel="noopener noreferrer">View Doc</a>', 'wpvr'),
306 esc_url('https://rextheme.com/docs/360-panorama-background-virtual-tour/')
307 ),
308 array(
309 'a' => array('href' => array(), 'target' => array(), 'rel' => array())
310 )
311 );
312 ?>
313 </span>
314 </div>
315
316 </div>
317 </div>
318 </div>
319
320 </div>
321
322 <?php
323 }
324
325 public function include_street_view_meta_content($post_data)
326 {
327 ?>
328
329 <div class="rex-pano-tab streetview" id="streetview">
330
331 <h6 class="title"> <?= __('Embed Google Street View : ', 'wpvr-pro'); ?> </h6>
332
333 <div class="single-settings">
334 <div class="wpvr-global-tooltip-area">
335 <span> <?php echo __('Enable Street View:','wpvr-pro') ?> </span>
336
337 <div class="field-tooltip">
338 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'admin/icon/tooltip-icon.svg'; ?>" alt="icon" />
339 <span>
340 <?= __('Insert a Street View iframe link.', 'wpvr-pro'); ?>
341 <a href="https://rextheme.com/docs/wp-vr-embed-google-street-view-tour/"
342 target="_blank"
343 rel="noopener noreferrer">
344 <?= __('View Doc', 'wpvr-pro'); ?>
345 </a>
346 </span>
347 </div>
348
349 </div>
350
351
352 <ul>
353 <li class="radio-btn">
354 <input class="styled-radio wpvrStreetView_off" id="styled-radio-sv-off" type="radio" name="wpvrStreetView" value="off" >
355 <label for="styled-radio-sv-off">Off</label>
356 </li>
357
358 <li class="radio-btn">
359 <input class="styled-radio wpvrStreetView_on" id="styled-radio-sv-on" type="radio" name="wpvrStreetView" value="on">
360 <label for="styled-radio-sv-on">On</label>
361 </li>
362 </ul>
363
364 </div>
365
366 </div>
367 <?php
368
369 }
370
371 public function include_export_meta_content($post_data ,$post)
372 {
373 ?>
374
375 <div class="rex-pano-tab export" id="import">
376 <h6 class="title"> <?= __('Export Tour : ', 'wpvr-pro') ?></h6>
377 <a class="vr-export"><?= __('Download', 'wpvr-pro') ?></a>
378 </div>
379 <?php
380
381 }
382
383
384 /**
385 * Register all of the hooks related to the public-facing functionality
386 * of the plugin.
387 *
388 * @since 8.0.0
389 * @access private
390 */
391 private function define_public_hooks()
392 {
393 if (apply_filters('is_wpvr_pro_active', false)) {
394 if (class_exists('Wpvrpropublic')) {
395 $plugin_public = new Wpvrpropublic($this->get_plugin_name(), $this->get_version());
396 } else {
397 $plugin_public = new Wpvr_Public($this->get_plugin_name(), $this->get_version());
398 }
399 } else {
400 $plugin_public = new Wpvr_Public($this->get_plugin_name(), $this->get_version());
401 }
402
403 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
404 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
405
406 $plugin_public->public_init();
407 }
408
409
410 /**
411 * Run the loader to execute all of the hooks with WordPress.
412 *
413 * @since 8.0.0
414 */
415 public function run()
416 {
417 $this->loader->run();
418 }
419
420
421 /**
422 * The name of the plugin used to uniquely identify it within the context of
423 * WordPress and to define internationalization functionality.
424 *
425 * @since 8.0.0
426 * @return string The name of the plugin.
427 */
428 public function get_plugin_name()
429 {
430 return $this->plugin_name;
431 }
432
433
434 /**
435 * The reference to the class that orchestrates the hooks with the plugin.
436 *
437 * @since 8.0.0
438 * @return Wpvr_Loader Orchestrates the hooks of the plugin.
439 */
440 public function get_loader()
441 {
442 return $this->loader;
443 }
444
445
446 /**
447 * Retrieve the version number of the plugin.
448 *
449 * @since 8.0.0
450 * @return string The version number of the plugin.
451 */
452 public function get_version()
453 {
454 return $this->version;
455 }
456
457
458 /**
459 * Retrieve the post type of the plugin.
460 *
461 * @since 8.0.0
462 */
463 public function get_post_type()
464 {
465 return $this->post_type;
466 }
467
468 public function register_wpvr_setup_wizard()
469 {
470 if (!empty($_GET['page']) && 'rex-wpvr-setup-wizard' == sanitize_text_field($_GET['page'])) {
471 add_action('admin_menu', function () {
472 add_dashboard_page('WPVR Setup', 'WPVR Setup', 'manage_options', 'rex-wpvr-setup-wizard', function () {
473 return '';
474 });
475 });
476 add_action('current_screen', function () {
477 (new WPVR_Setup_Wizard())->setup_wizard();
478 }, 999);
479 }
480 }
481
482 /**
483 * Handle redirects to setup/welcome page after install and updates.
484 *
485 * For setup wizard, transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters.
486 */
487 public function admin_redirects()
488 {
489 // Setup wizard redirect.
490 if (get_transient('_wpvr_activation_redirect')) {
491 $do_redirect = true;
492 // On these pages, or during these events, postpone the redirect.
493 if (wp_doing_ajax() || is_network_admin() || !current_user_can('manage_options')) {
494 $do_redirect = false;
495 }
496
497 if ( $do_redirect ) {
498 delete_transient('_wpvr_activation_redirect');
499 $url = admin_url('admin.php?page=rex-wpvr-setup-wizard');
500 wp_safe_redirect( wp_sanitize_redirect( esc_url_raw( $url ) ) );
501 exit;
502 }
503 }
504 }
505
506 public function wpvr_tracking_enabled(){
507 // Check if the tracking option is enabled
508 $tracking_enabled = get_option( 'wpvr_posthog_access_enabled', 'yes' );
509 return $tracking_enabled === 'yes';
510 }
511 }
512