PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.75
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.75
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.75, at bricks/Wpvr-widget.php

226 lines 6.1 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 if ( method_exists( $this, 'register_control_group' ) ) {
87 $this->register_control_group(
88 'wpvr',
89 [
90 'title' => esc_html__('WPVR', 'wpvr'),
91 'tab' => 'content',
92 ]
93 );
94 } else {
95 $this->control_groups['wpvr'] = [
96 'title' => esc_html__('WPVR', 'wpvr'),
97 'tab' => 'content',
98 ];
99 }
100 }
101
102 /**
103 * Set builder controls
104 *
105 * @since 8.5.19
106 */
107 /**
108 * Set controls for the WPVR Bricks Builder element.
109 *
110 * @since 8.5.19
111 * @return void
112 */
113 public function set_controls()
114 {
115 $common_number_settings = [
116 'tab' => 'content',
117 'group' => 'wpvr',
118 'type' => 'number',
119 'min' => 0,
120 'max' => 2000,
121 'step' => 1,
122 'validation' => 'numeric',
123 'class' => 'wpvr-number-field-width',
124 ];
125
126 $controls = [
127 'select_wpvr' => [
128 'tab' => 'content',
129 'group' => 'wpvr',
130 'label' => esc_html__('Select Tour', 'wpvr'),
131 'type' => 'select',
132 'options' => $this->getPublishedTour(),
133 'inline' => true,
134 'clearable' => false,
135 'pasteStyles' => false,
136 'default' => '',
137 'width' => '100%',
138 ],
139 'vr_width' => array_merge($common_number_settings, [
140 'label' => esc_html__('Width(px)', 'wpvr'),
141 'default' => 600,
142 ]),
143 'vr_height' => array_merge($common_number_settings, [
144 'label' => esc_html__('Height(px)', 'wpvr'),
145 'default' => 400,
146 ]),
147 'vr_radius' => array_merge($common_number_settings, [
148 'label' => esc_html__('Radius(px)', 'wpvr'),
149 'default' => 0,
150 'max' => 1000,
151 ])
152 ];
153
154 if ( method_exists( $this, 'register_control' ) ) {
155 foreach ( $controls as $control_id => $control_args ) {
156 $this->register_control( $control_id, $control_args );
157 }
158 } else {
159 foreach ( $controls as $control_id => $control_args ) {
160 $this->controls[ $control_id ] = $control_args;
161 }
162 }
163 }
164
165
166 /**
167 * Render the WPVR tour shortcode or a placeholder message in Bricks Builder editor.
168 *
169 * @since 8.5.19
170 */
171 public function render() {
172 // Retrieve settings with default fallbacks
173 $settings = $this->settings ?? [];
174 $id = $settings['select_wpvr'] ?? 0;
175 $width = ($settings['vr_width'] ?? 600) . 'px';
176 $height = ($settings['vr_height'] ?? 400) . 'px';
177 $radius = ($settings['vr_radius'] ?? 0) . 'px';
178
179 // Check if a valid tour ID is available
180 if ($id) {
181 // Prevent rendering preview in Bricks Builder editor or during REST API calls
182 if ((function_exists('bricks_is_builder') && bricks_is_builder()) ||
183 (function_exists('bricks_is_builder_main') && bricks_is_builder_main()) ||
184 (function_exists('bricks_is_rest_call') && bricks_is_rest_call())
185 ) {
186 echo '<p>' . esc_html__('Bricks Editor Mode - WPVR Preview is not available.', 'wpvr') . '</p>';
187 return;
188 }
189
190 // Render the WPVR tour using the shortcode
191 echo do_shortcode('[wpvr id="' . esc_attr($id) . '" width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" radius="' . esc_attr($radius) . '"]');
192 } else {
193 // Display message when no tour is selected
194 echo '<p>' . esc_html__('No tour has been selected.', 'wpvr') . '</p>';
195 }
196 }
197
198
199 /**
200 * Get all published tours
201 *
202 * @since 8.5.19
203 *
204 * @access public
205 */
206 public function getPublishedTour() {
207 $posts = get_posts([
208 'post_type' => 'wpvr_item',
209 'post_status' => 'publish',
210 'orderby' => 'ID',
211 'order' => 'DESC',
212 'numberposts' => -1,
213 'fields' => 'ids',
214 ]);
215
216 $tours = [];
217 foreach ($posts as $id) {
218 $title = get_the_title($id) ?: 'No title';
219 $tours[$id] = "{$title} (ID: {$id})";
220 }
221 return $tours;
222 }
223
224 }
225
226