| @@ -56,13 +56,16 @@ | ||
| 56 | 56 | $page_title = $tour_id |
| 57 | 57 | ? __( 'Edit Tour', 'wpvr' ) |
| 58 | 58 | : __( 'Add New Tour', 'wpvr' ); |
| 59 | 59 | |
| 60 | + $post_type_obj = get_post_type_object( self::POST_TYPE ); | |
| 61 | + $capability = $post_type_obj ? $post_type_obj->cap->edit_posts : 'edit_wpvr_tours'; | |
| 62 | + | |
| 60 | 63 | add_submenu_page( |
| 61 | 64 | '', |
| 62 | 65 | $page_title, |
| 63 | 66 | $page_title, |
| 64 | - 'edit_posts', | |
| 67 | + $capability, | |
| 65 | 68 | self::PAGE_SLUG, |
| 66 | 69 | [ $this, 'render_editor_page' ] |
| 67 | 70 | ); |
| 68 | 71 | } |
| @@ -127,8 +130,16 @@ | ||
| 127 | 130 | // Step 4 — Render + enqueue |
| 128 | 131 | // ------------------------------------------------------------------------- |
| 129 | 132 | |
| 130 | 133 | public function render_editor_page(): void { |
| 134 | + $tour_id = isset( $_GET['tour_id'] ) ? (int) $_GET['tour_id'] : 0; | |
| 135 | + if ( $tour_id ) { | |
| 136 | + $post = get_post( $tour_id ); | |
| 137 | + if ( ! $post || $post->post_type !== self::POST_TYPE || ! current_user_can( 'edit_post', $tour_id ) ) { | |
| 138 | + wp_die( esc_html__( 'Sorry, you are not allowed to edit this tour.', 'wpvr' ), 403 ); | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 131 | 142 | echo '<div id="wpvr-tour-editor-root"></div>'; |
| 132 | 143 | |
| 133 | 144 | if ( ! wpvr_is_pro_active() ) { |
| 134 | 145 | require WPVR_PLUGIN_LEGACY_DIR_PATH . 'admin/partials/wpvr-premium-feature-popup.php'; |
| @@ -149,8 +160,16 @@ | ||
| 149 | 160 | if ( ! $this->is_editor_page( $hook ) ) { |
| 150 | 161 | return; |
| 151 | 162 | } |
| 152 | 163 | |
| 164 | + $tour_id_cfg = isset( $_GET['tour_id'] ) ? (int) $_GET['tour_id'] : 0; | |
| 165 | + if ( $tour_id_cfg ) { | |
| 166 | + $post = get_post( $tour_id_cfg ); | |
| 167 | + if ( ! $post || $post->post_type !== self::POST_TYPE || ! current_user_can( 'edit_post', $tour_id_cfg ) ) { | |
| 168 | + return; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 153 | 172 | $plugin_url = plugin_dir_url( WPVR_FILE ); |
| 154 | 173 | $plugin_path = plugin_dir_path( WPVR_FILE ); |
| 155 | 174 | $build_dir = $plugin_path . 'build/tour-editor/'; |
| 156 | 175 | |
| @@ -159,8 +178,15 @@ | ||
| 159 | 178 | wp_enqueue_style( 'wpvr-pannellum-css', $pano_base . 'css/pannellum.css', [], WPVR_VERSION ); |
| 160 | 179 | wp_enqueue_script( 'wpvr-libpannellum', $pano_base . 'js/libpannellum.js', [], WPVR_VERSION, true ); |
| 161 | 180 | wp_enqueue_script( 'wpvr-pannellum', $pano_base . 'js/pannellum.js', [ 'wpvr-libpannellum' ], WPVR_VERSION, true ); |
| 162 | 181 | |
| 182 | + // Load Video.js & VideoJS-VR (for 360 video tours). | |
| 183 | + $public_base = $plugin_url . 'legacy/public/'; | |
| 184 | + wp_enqueue_style( 'wpvr-videojs-css', $public_base . 'lib/pannellum/src/css/video-js.css', [], WPVR_VERSION ); | |
| 185 | + wp_enqueue_style( 'wpvr-videojs-vr-css', $public_base . 'lib/videojs-vr/videojs-vr.css', [], WPVR_VERSION ); | |
| 186 | + wp_enqueue_script( 'wpvr-videojs', $public_base . 'js/video.js', [], WPVR_VERSION, true ); | |
| 187 | + wp_enqueue_script( 'wpvr-videojs-vr', $public_base . 'lib/videojs-vr/videojs-vr.js', [ 'wpvr-videojs' ], WPVR_VERSION, true ); | |
| 188 | + | |
| 163 | 189 | wp_enqueue_style( 'wpvr-fontawesome', $plugin_url . 'legacy/admin/lib/fontawesome/css/all.min.css', [], WPVR_VERSION ); |
| 164 | 190 | |
| 165 | 191 | // Tour editor React bundle. |
| 166 | 192 | $js_file = $build_dir . 'index.js'; |
| @@ -177,9 +203,9 @@ | ||
| 177 | 203 | |
| 178 | 204 | wp_enqueue_script( |
| 179 | 205 | 'wpvr-tour-editor', |
| 180 | 206 | $plugin_url . 'build/tour-editor/index.js', |
| 181 | - array_merge( $asset['dependencies'], [ 'wpvr-pannellum' ] ), | |
| 207 | + array_merge( $asset['dependencies'], [ 'wpvr-pannellum', 'wpvr-videojs-vr' ] ), | |
| 182 | 208 | $asset['version'], |
| 183 | 209 | true |
| 184 | 210 | ); |
| 185 | 211 | |
| @@ -190,21 +216,33 @@ | ||
| 190 | 216 | if ( class_exists( 'Wpvr_fontawesome_icons' ) ) { |
| 191 | 217 | $fa_icons = ( new \Wpvr_fontawesome_icons() )->icon; |
| 192 | 218 | } |
| 193 | 219 | |
| 220 | + $is_embed_addon_active = apply_filters( 'is_wpvr_embed_addon_premium', false ); | |
| 221 | + if ( $is_embed_addon_active ) { | |
| 222 | + if ( wp_script_is( 'custom-qrcode', 'registered' ) ) { | |
| 223 | + wp_enqueue_script( 'custom-qrcode' ); | |
| 224 | + } elseif ( defined( 'WPVR_PRO_PLUGIN_DIR_URL' ) ) { | |
| 225 | + wp_enqueue_script( 'custom-qrcode', trailingslashit( WPVR_PRO_PLUGIN_DIR_URL ) . 'admin/lib/qr-code/custom-qrcode.js', [ 'jquery' ], null, true ); | |
| 226 | + } | |
| 227 | + } | |
| 228 | + | |
| 194 | 229 | wp_localize_script( 'wpvr-tour-editor', 'wpvrTourEditor', [ |
| 195 | - 'tourId' => $tour_id_cfg ?: null, | |
| 196 | - 'tourStatus' => $tour_status, | |
| 197 | - 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 198 | - 'apiBase' => rest_url( 'wpvr/v1' ), | |
| 199 | - 'mediaUrl' => rest_url( 'wp/v2/media' ), | |
| 200 | - 'isPro' => wpvr_is_pro_active(), | |
| 201 | - 'pluginUrl' => $plugin_url, | |
| 202 | - 'listUrl' => admin_url( 'edit.php?post_type=' . self::POST_TYPE ), | |
| 203 | - 'postEditUrl' => admin_url( 'post.php' ), | |
| 204 | - 'faIcons' => $fa_icons, | |
| 205 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 206 | - 'exportNonce' => wp_create_nonce( 'wpvr_export_tour' ), | |
| 230 | + 'tourId' => $tour_id_cfg ?: null, | |
| 231 | + 'tourStatus' => $tour_status, | |
| 232 | + 'tourTitle' => $tour_id_cfg ? get_the_title( $tour_id_cfg ) : '', | |
| 233 | + 'homeUrl' => home_url( '/' ), | |
| 234 | + 'isEmbedAddonActive' => $is_embed_addon_active, | |
| 235 | + 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 236 | + 'apiBase' => rest_url( 'wpvr/v1' ), | |
| 237 | + 'mediaUrl' => rest_url( 'wp/v2/media' ), | |
| 238 | + 'isPro' => wpvr_is_pro_active(), | |
| 239 | + 'pluginUrl' => $plugin_url, | |
| 240 | + 'listUrl' => admin_url( 'edit.php?post_type=' . self::POST_TYPE ), | |
| 241 | + 'postEditUrl' => admin_url( 'post.php' ), | |
| 242 | + 'faIcons' => $fa_icons, | |
| 243 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 244 | + 'exportNonce' => wp_create_nonce( 'wpvr_export_tour' ), | |
| 207 | 245 | 'imageResizeWarning' => [ |
| 208 | 246 | 'ajaxNonce' => wp_create_nonce( 'wpvr' ), |
| 209 | 247 | 'canManageSettings' => current_user_can( 'manage_options' ), |
| 210 | 248 | 'settingEnabled' => get_option( 'high_res_image' ) === 'true', |