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 / oxygen / elements / Wpvr_Tour_Element.php

Wpvr_Tour_Element.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.39, at oxygen/elements/Wpvr_Tour_Element.php

220 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP VR Tour Element for Oxygen Builder
4 *
5 * Creates a custom element to display virtual reality tours created with WP VR plugin
6 * within the Oxygen Builder interface.
7 *
8 * @package WPVR
9 * @version 8.5.21
10 * @subpackage Oxygen Integration
11 */
12
13 class Wpvr_Tour_Element extends WPVR_CUSTOM_OXY_ELEMENT {
14
15 /**
16 * Returns the name of the element for Oxygen Builder
17 *
18 * @return string Element name
19 */
20 public function name() {
21 return esc_html__('WP VR Tour', 'wpvr');
22 }
23
24 /**
25 * Defines the UI controls for this element
26 *
27 * Sets up all configuration options available to the user
28 */
29 public function controls() {
30 // Get all published VR tours
31 $posts = get_posts([
32 'post_type' => 'wpvr_item',
33 'post_status' => 'publish',
34 'orderby' => 'ID',
35 'order' => 'DESC',
36 'numberposts' => -1,
37 ]);
38
39 // Build the tour selection array
40 $tour_options = [0 => __("None", "wpvr")];
41 foreach ($posts as $post) {
42 $id = $post->ID;
43 $title = $post->post_title ? $post->post_title : __("No title", "wpvr");
44 $tour_options[$id] = "{$id} : {$title}";
45 }
46
47 // Tour selection control
48 $this->addOptionControl([
49 "type" => "dropdown",
50 "name" => __("Select Tour", "wpvr"),
51 "slug" => "tour_id",
52 "value" => $tour_options
53 ])->rebuildElementOnChange();
54
55 // Width controls
56 $this->addOptionControl([
57 "type" => "textfield",
58 "name" => __("Tour Width", "wpvr"),
59 "slug" => "tour_width",
60 "value" => "600",
61 "condition" => "tour_width_fullwidth=off",
62 ]);
63
64 $this->addOptionControl([
65 "type" => "dropdown",
66 "name" => __("Tour Width Unit", "wpvr"),
67 "slug" => "tour_width_unit",
68 "default" => "px",
69 "value" => [
70 'px' => __('px', "wpvr"),
71 '%' => __('%', "wpvr"),
72 'vw' => __('vw', "wpvr"),
73 ],
74 "condition" => "tour_width_fullwidth=off",
75 ])->rebuildElementOnChange();
76
77 $this->addOptionControl([
78 "type" => "dropdown",
79 "name" => __("Tour Width Fullwidth", "wpvr"),
80 "slug" => "tour_width_fullwidth",
81 "default" => "off",
82 "value" => [
83 'off' => __('OFF', "wpvr"),
84 'on' => __('ON', "wpvr"),
85 ]
86 ])->rebuildElementOnChange();
87
88 // Height controls
89 $this->addOptionControl([
90 "type" => "textfield",
91 "name" => __("Tour Height", "wpvr"),
92 "slug" => "tour_height",
93 "value" => "400"
94 ]);
95
96 $this->addOptionControl([
97 "type" => "dropdown",
98 "name" => __("Tour Height Unit", "wpvr"),
99 "slug" => "tour_height_unit",
100 "default" => "px",
101 "value" => [
102 'px' => __('px', "wpvr"),
103 'vh' => __('vh', "wpvr"),
104 ]
105 ])->rebuildElementOnChange();
106
107 // Mobile-specific height controls
108 $this->addOptionControl([
109 "type" => "textfield",
110 "name" => __("Tour Mobile Height", "wpvr"),
111 "slug" => "tour_mobile_height",
112 "value" => "300"
113 ])->setParam('description', __('Height on mobile devices. Leave empty to use the main height.', 'wpvr'));
114
115 $this->addOptionControl([
116 "type" => "dropdown",
117 "name" => __("Tour Mobile Height Unit", "wpvr"),
118 "slug" => "tour_mobile_height_unit",
119 "default" => "px",
120 "value" => [
121 'px' => __('px', "wpvr"),
122 'vh' => __('vh', "wpvr"),
123 ]
124 ])->rebuildElementOnChange();
125
126 // Border radius control
127 $this->addOptionControl([
128 "type" => "textfield",
129 "name" => __("Tour Radius", "wpvr"),
130 "slug" => "tour_radius",
131 "value" => "0"
132 ]);
133
134 $this->addOptionControl([
135 "type" => "dropdown",
136 "name" => __("Tour Radius Unit", "wpvr"),
137 "slug" => "tour_radius_unit",
138 "default" => "px",
139 "value" => [
140 'px' => __('px', "wpvr"),
141 ]
142 ])->rebuildElementOnChange();
143 }
144
145 /**
146 * Renders the element on the frontend
147 *
148 * @param array $options Values set in the controls
149 * @param array $defaults Default values for all controls
150 * @param array $content Shortcode content for nested elements
151 */
152 public function render($options, $defaults, $content) {
153 // Get and validate tour ID
154 $id = isset($options['tour_id']) ? absint($options['tour_id']) : 0;
155
156 if (!$id) {
157 echo '<div class="wpvr-no-tour-selected">';
158 echo esc_html__('Please select a WP VR Tour from the dropdown in the sidebar.', 'wpvr');
159 echo '</div>';
160 return;
161 }
162
163 // Process dimension settings
164 $width = !empty($options['tour_width']) ? esc_attr($options['tour_width'] . $options['tour_width_unit']) : '600px';
165 $height = !empty($options['tour_height']) ? esc_attr($options['tour_height'] . $options['tour_height_unit']) : '400px';
166 $radius = !empty($options['tour_radius']) ? esc_attr($options['tour_radius'] . $options['tour_radius_unit']) : '0px';
167
168 // Handle full width setting
169 if (isset($options['tour_width_fullwidth']) && $options['tour_width_fullwidth'] === 'on') {
170 $width = 'fullwidth';
171 }
172
173 // Process mobile height settings
174 $mobile_height = !empty($options['tour_mobile_height']) ?
175 esc_attr($options['tour_mobile_height'] . $options['tour_mobile_height_unit']) :
176 '300px';
177
178 // Construct and output the shortcode
179 $shortcode = sprintf(
180 '[wpvr id="%d" width="%s" height="%s" radius="%s" mobile_height="%s"]',
181 $id,
182 esc_attr($width),
183 esc_attr($height),
184 esc_attr($radius),
185 esc_attr($mobile_height)
186 );
187
188 echo do_shortcode(shortcode_unautop($shortcode));
189 }
190 }
191
192 // Initialize the element
193 new Wpvr_Tour_Element();
194
195
196 /**
197 * Modify the text of specific translatable strings in WordPress.
198 *
199 * This function replaces "Apply Params" with "Save Changes" anywhere it appears
200 * in WordPress translations. It uses the `gettext` filter to intercept and modify
201 * translatable strings dynamically.
202 *
203 * @param string $translated_text The translated text.
204 * @param string $text The original text.
205 * @version 8.5.21
206 * @param string $domain The text domain (used to identify different plugins/themes).
207 * @return string Modified text if it matches; otherwise, returns the original text.
208 */
209 function modify_wpvr_save_param_text($translated_text, $text, $domain) {
210 if ($text === 'Apply Params') { // Check if the text matches the target phrase
211 return 'Save Changes'; // Replace it with the desired text
212 }
213 return $translated_text; // Return unchanged text if no match is found
214 }
215
216 // Hook the function into the 'gettext' filter to modify translatable strings dynamically
217 add_filter('gettext', 'modify_wpvr_save_param_text', 10, 3);
218
219
220