PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.37
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.37
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 / bricks / Wpvr-widget.php

Wpvr-widget.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.37, at bricks/Wpvr-widget.php

206 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPVR Bricks Widget
4 *
5 * @package WPVR
6 * @since 8.5.19
7 */
8 namespace WpvrElement\Bricks\Wpvr;
9
10 require_once get_template_directory() . '/includes/elements/base.php';
11
12 use \Bricks\Element;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Class WpvrWidget
20 *
21 * @package WpvrElement\Bricks\Wpvr
22 * @since 8.5.19
23 */
24 class WpvrWidget extends Element {
25
26 /**
27 * Category under which the WPVR element will appear in Bricks Builder.
28 *
29 * @since 8.5.19
30 * @var string
31 */
32 public $category = 'wpvr';
33
34 /**
35 * Unique name/identifier for the WPVR element in Bricks Builder.
36 *
37 * @since 8.5.19
38 * @var string
39 */
40 public $name = 'wpvr';
41
42 /**
43 * Font Awesome icon class for the WPVR element in the Bricks Builder panel.
44 *
45 * @since 8.5.19
46 * @var string
47 */
48 public $icon = 'fa-solid fa-vr-cardboard';
49 // public $icon = 'wpvr-custom-icon';
50
51 /**
52 * Custom CSS selector for styling the WPVR element in Bricks Builder.
53 *
54 * @since 8.5.19
55 * @var string
56 */
57 public $css_selector = '.wpvr-bricks-icon';
58
59 /**
60 * Scripts required for the WPVR element in Bricks Builder.
61 *
62 * @since 8.5.19
63 * @var array
64 */
65 public $scripts = [];
66
67
68 /**
69 * Return localised element label
70 *
71 * @return string
72 * @since 8.5.19
73 */
74 public function get_label()
75 {
76 return esc_html__('WPVR', 'wpvr');
77 }
78
79 /**
80 * Set builder control groups
81 *
82 * @since 8.5.19
83 */
84 public function set_control_groups()
85 {
86 $this->control_groups['wpvr'] = [
87 'title' => esc_html__('WPVR', 'wpvr'),
88 'tab' => 'content',
89 ];
90 }
91
92 /**
93 * Set builder controls
94 *
95 * @since 8.5.19
96 */
97 /**
98 * Set controls for the WPVR Bricks Builder element.
99 *
100 * @since 8.5.19
101 * @return void
102 */
103 public function set_controls()
104 {
105 $common_number_settings = [
106 'tab' => 'content',
107 'group' => 'wpvr',
108 'type' => 'number',
109 'min' => 0,
110 'max' => 2000,
111 'step' => 1,
112 'validation' => 'numeric',
113 'class' => 'wpvr-number-field-width',
114 ];
115
116 $this->controls['select_wpvr'] = [
117 'tab' => 'content',
118 'group' => 'wpvr',
119 'label' => esc_html__('Select Tour', 'wpvr'),
120 'type' => 'select',
121 'options' => $this->getPublishedTour(),
122 'inline' => true,
123 'clearable' => false,
124 'pasteStyles' => false,
125 'default' => '',
126 'width' => '100%',
127 ];
128
129 $this->controls['vr_width'] = array_merge($common_number_settings, [
130 'label' => esc_html__('Width(px)', 'wpvr'),
131 'default' => 600,
132 ]);
133
134 $this->controls['vr_height'] = array_merge($common_number_settings, [
135 'label' => esc_html__('Height(px)', 'wpvr'),
136 'default' => 400,
137 ]);
138
139 $this->controls['vr_radius'] = array_merge($common_number_settings, [
140 'label' => esc_html__('Radius(px)', 'wpvr'),
141 'default' => 0,
142 'max' => 1000,
143 ]);
144 }
145
146
147 /**
148 * Render the WPVR tour shortcode or a placeholder message in Bricks Builder editor.
149 *
150 * @since 8.5.19
151 */
152 public function render() {
153 // Retrieve settings with default fallbacks
154 $settings = $this->settings ?? [];
155 $id = $settings['select_wpvr'] ?? 0;
156 $width = ($settings['vr_width'] ?? 600) . 'px';
157 $height = ($settings['vr_height'] ?? 400) . 'px';
158 $radius = ($settings['vr_radius'] ?? 0) . 'px';
159
160 // Check if a valid tour ID is available
161 if ($id) {
162 // Prevent rendering preview in Bricks Builder editor or during REST API calls
163 if ((function_exists('bricks_is_builder') && bricks_is_builder()) ||
164 (function_exists('bricks_is_builder_main') && bricks_is_builder_main()) ||
165 (function_exists('bricks_is_rest_call') && bricks_is_rest_call())
166 ) {
167 echo '<p>' . esc_html__('Bricks Editor Mode - WPVR Preview is not available.', 'wpvr') . '</p>';
168 return;
169 }
170
171 // Render the WPVR tour using the shortcode
172 echo do_shortcode('[wpvr id="' . esc_attr($id) . '" width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" radius="' . esc_attr($radius) . '"]');
173 } else {
174 // Display message when no tour is selected
175 echo '<p>' . esc_html__('No tour has been selected.', 'wpvr') . '</p>';
176 }
177 }
178
179
180 /**
181 * Get all published tours
182 *
183 * @since 8.5.19
184 *
185 * @access public
186 */
187 public function getPublishedTour() {
188 $posts = get_posts([
189 'post_type' => 'wpvr_item',
190 'post_status' => 'publish',
191 'orderby' => 'ID',
192 'order' => 'DESC',
193 'numberposts' => -1,
194 'fields' => 'ids',
195 ]);
196
197 foreach ($posts as $id) {
198 $title = get_the_title($id) ?: 'No title';
199 $tours[$id] = "{$title} (ID: {$id})";
200 }
201 return $tours;
202 }
203
204 }
205
206