PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.69
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.69
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 / public / classes / class-wpvr-shortcode.php

class-wpvr-shortcode.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.69, at public/classes/class-wpvr-shortcode.php

200 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 /**
4 * Responsible for managing Shortcode on frontend
5 *
6 * @link http://rextheme.com/
7 * @since 8.0.0
8 *
9 * @package Wpvr
10 * @subpackage Wpvr/public/classes
11 */
12
13 class WPVR_Shortcode {
14
15 /**
16 * The ID of this plugin.
17 *
18 * @since 8.0.0
19 * @access private
20 * @var string $plugin_name The ID of this plugin.
21 */
22 private $plugin_name;
23
24 /**
25 * Post type for wpvr
26 *
27 * @var string
28 * @since 8.0.0
29 */
30 private $post_type = 'wpvr_item';
31
32 /**
33 * Instance of WPVR_StreetView class
34 *
35 * @var object
36 * @since 8.0.0
37 */
38 private $streetview;
39
40 /**
41 * Instance of WPVR_Video class
42 *
43 * @var object
44 * @since 8.0.0
45 */
46 private $video;
47
48 /**
49 * Instance of WPVR_Scene class
50 *
51 * @var object
52 * @since 8.0.0
53 */
54 private $scene;
55
56 function __construct($plugin_name)
57 {
58 $this->plugin_name = $plugin_name;
59 $this->streetview = new WPVR_StreetView();
60 $this->video = new WPVR_Video();
61 $this->scene = new WPVR_Scene();
62 }
63
64 /**
65 * Shortcode output for the plugin
66 *
67 * @param array $atts
68 *
69 * @return string
70 * @since 8.0.0
71 */
72 public function wpvr_shortcode($atts)
73 {
74
75 extract(
76 shortcode_atts(
77 array(
78 'id' => 0,
79 'slug' => '',
80 'width' => null,
81 'height' => null,
82 'mobile_height' => null,
83 'radius' => null
84 ),
85 $atts
86 )
87 );
88 $id = esc_attr($id);
89 $slug = esc_attr($slug);
90 $width = esc_attr($width);
91 $height = esc_attr($height);
92 $mobile_height = esc_attr($mobile_height);
93 $radius = esc_attr($radius);
94 if (!$id) {
95 $obj = get_page_by_path($slug, OBJECT, $this->post_type);
96 if ($obj) {
97 $id = $obj->ID;
98 } else {
99 return __('Invalid Wpvr slug attribute', $this->plugin_name);
100 }
101 }
102
103 do_action('rex_wpvr_embadded_tour', $id);
104
105 if (empty($mobile_height)) {
106 $mobile_height = "300px";
107 }
108 $get_post = get_post_status($id);
109
110 if (empty($get_post)) {
111 return wp_kses(
112 __('Oops! It seems that the entered tour doesn\'t exist. Please enter correct shortcode.<br>', 'wpvr'),
113 ['br' => []]
114 );
115 }
116
117 if ( $get_post !== 'publish' ) {
118 return esc_html__('Oops! It seems like this post isn\'t published yet. Stay tuned for updates!', 'wpvr') ;
119 }
120 if( post_password_required( $id ) ){
121 return get_the_password_form();
122 }
123
124
125 $memberpress_active = defined('MEPR_VERSION');
126 $rcp_active = is_plugin_active( 'restrict-content-pro/restrict-content-pro.php' );
127
128 if (($memberpress_active || $rcp_active ) && apply_filters('is_wpvr_pro_active', false)) {
129
130 if (!is_user_logged_in()) {
131 return esc_html__('You need to log in to access this content.', 'wpvr');
132 }
133
134 $user_id = get_current_user_id();
135 $allowed_access = false;
136
137 // Get saved membership levels from post meta
138 $allowed_membership_levels = get_post_meta($id, '_wpvr_allowed_roles_levels', true);
139 if ( isset($allowed_membership_levels) && 'none' !== $allowed_membership_levels ) {
140 if (!is_array($allowed_membership_levels)) {
141 $allowed_membership_levels = array($allowed_membership_levels);
142 }
143
144 // Check MemberPress Access
145 if ($memberpress_active) {
146 $user = new MeprUser($user_id);
147 $active_memberships = $user->active_product_subscriptions();
148 if (array_intersect($allowed_membership_levels, $active_memberships) ) {
149 $allowed_access = true;
150 }
151 }
152
153 // Check Restrict Content Pro Access
154 if ($rcp_active) {
155 $customer = rcp_get_customer_by_user_id($user_id);
156
157 if ($customer) { // Ensure customer exists
158 $user_rcp_memberships = $customer->get_memberships(); // Use method on customer object
159
160 if (!empty($user_rcp_memberships)) { // Ensure memberships exist
161 foreach ($user_rcp_memberships as $membership) {
162 $rcp_access_level = [$membership->get_object_id()];
163
164 if (array_intersect($allowed_membership_levels, $rcp_access_level)) {
165 $allowed_access = true;
166 break;
167 }
168 }
169 }
170 }
171 }
172
173 } else {
174 // If no membership restriction is set, allow access by default
175 $allowed_access = true;
176 }
177
178 if (!$allowed_access) {
179 return esc_html__('You do not have access to this content.', 'wpvr');
180 }
181 }
182
183 $postdata = get_post_meta($id, 'panodata', true);
184 $panoid = 'pano'.$id;
185
186 if (isset($postdata['streetviewdata'])){
187 $html = $this->streetview->render_streetview_shortcode($postdata, $width, $height);
188 return $html;
189 }
190
191
192 if (isset($postdata['vidid'])) {
193 $html = $this->video->render_video_shortcode($postdata, $id, $width, $height, $radius);
194 return $html;
195 }
196
197 $html = $this->scene->render_scene_shortcode($postdata, $panoid, $id, $radius, $width, $height, $mobile_height);
198 return $html;
199 }
200 }