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

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