| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPVR – Virtual Tour WPBakery Element |
| 4 |
* |
| 5 |
* Place this file at: /builders/wpbakery/wpvr-element.php |
| 6 |
* @since 8.5.48 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Register VC element |
| 15 |
* @since 8.5.48 |
| 16 |
*/ |
| 17 |
add_action( 'vc_before_init', 'wpvr_vc_map_wpvr_virtual_tour' ); |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
function wpvr_vc_map_wpvr_virtual_tour() { |
| 22 |
if ( ! function_exists( 'vc_map' ) ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$tours = array( __( 'Select a tour', 'wpvr' ) => '' ); |
| 27 |
$items = get_posts( array( |
| 28 |
'post_type' => 'wpvr_item', |
| 29 |
'posts_per_page' => -1, |
| 30 |
'post_status' => 'publish', |
| 31 |
'orderby' => 'title', |
| 32 |
'order' => 'ASC', |
| 33 |
) ); |
| 34 |
|
| 35 |
if ( $items ) { |
| 36 |
foreach ( $items as $p ) { |
| 37 |
$tours[ $p->post_title . ' (ID:' . $p->ID . ')' ] = $p->ID; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
vc_map( array( |
| 42 |
'name' => __( 'WPVR - Virtual Tour', 'wpvr' ), |
| 43 |
'base' => 'wpvr_virtual_tour', |
| 44 |
'category' => __( 'WPVR', 'wpvr' ), |
| 45 |
'icon' => plugins_url( 'images/icon.png', dirname(dirname(__FILE__)) ), // Correct icon path |
| 46 |
'description' => __( 'Embed a WPVR virtual tour with full analytics and tracking support.', 'wpvr' ), |
| 47 |
|
| 48 |
'params' => array( |
| 49 |
|
| 50 |
// TOUR DROPDOWN. |
| 51 |
array( |
| 52 |
'type' => 'dropdown', |
| 53 |
'heading' => __( 'Select Tour', 'wpvr' ), |
| 54 |
'param_name' => 'id', |
| 55 |
'value' => $tours, |
| 56 |
'admin_label' => true, |
| 57 |
), |
| 58 |
|
| 59 |
// WIDTH VALUE. |
| 60 |
array( |
| 61 |
'type' => 'textfield', |
| 62 |
'heading' => __( 'Width (number only)', 'wpvr' ), |
| 63 |
'param_name' => 'width_value', |
| 64 |
'value' => '600', |
| 65 |
), |
| 66 |
|
| 67 |
// WIDTH UNIT. |
| 68 |
array( |
| 69 |
'type' => 'dropdown', |
| 70 |
'heading' => __( 'Width Unit', 'wpvr' ), |
| 71 |
'param_name' => 'width_unit', |
| 72 |
'value' => array( |
| 73 |
'px' => 'px', |
| 74 |
'%' => '%', |
| 75 |
'vw' => 'vw', |
| 76 |
'Fullwidth' => 'fullwidth', |
| 77 |
), |
| 78 |
'std' => 'px', |
| 79 |
), |
| 80 |
|
| 81 |
// HEIGHT VALUE. |
| 82 |
array( |
| 83 |
'type' => 'textfield', |
| 84 |
'heading' => __( 'Height (number only)', 'wpvr' ), |
| 85 |
'param_name' => 'height_value', |
| 86 |
'value' => '400', |
| 87 |
), |
| 88 |
|
| 89 |
// HEIGHT UNIT |
| 90 |
array( |
| 91 |
'type' => 'dropdown', |
| 92 |
'heading' => __( 'Height Unit', 'wpvr' ), |
| 93 |
'param_name' => 'height_unit', |
| 94 |
'value' => array( |
| 95 |
'px' => 'px', |
| 96 |
'vh' => 'vh', |
| 97 |
), |
| 98 |
'std' => 'px', |
| 99 |
), |
| 100 |
|
| 101 |
// MOBILE HEIGHT VALUE |
| 102 |
array( |
| 103 |
'type' => 'textfield', |
| 104 |
'heading' => __( 'Mobile Height (number only)', 'wpvr' ), |
| 105 |
'param_name' => 'height_secondary_value', |
| 106 |
'value' => '', |
| 107 |
), |
| 108 |
|
| 109 |
// MOBILE HEIGHT UNIT |
| 110 |
array( |
| 111 |
'type' => 'dropdown', |
| 112 |
'heading' => __( 'Mobile Height Unit', 'wpvr' ), |
| 113 |
'param_name' => 'height_secondary_unit', |
| 114 |
'value' => array( |
| 115 |
'px' => 'px', |
| 116 |
'vh' => 'vh', |
| 117 |
), |
| 118 |
'std' => 'px', |
| 119 |
), |
| 120 |
), |
| 121 |
)); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
/** |
| 126 |
* Shortcode class (for backend & frontend editors) |
| 127 |
* @since 8.5.48 |
| 128 |
*/ |
| 129 |
if ( ! class_exists( 'WPBakeryShortCode_Wpvr_Virtual_Tour' ) ) { |
| 130 |
|
| 131 |
class WPBakeryShortCode_Wpvr_Virtual_Tour extends WPBakeryShortCode { |
| 132 |
|
| 133 |
protected function content( $atts, $content = null ) { |
| 134 |
|
| 135 |
$atts = shortcode_atts( array( |
| 136 |
'id' => '', |
| 137 |
'width_value' => '600', |
| 138 |
'width_unit' => 'px', |
| 139 |
'height_value' => '400', |
| 140 |
'height_unit' => 'px', |
| 141 |
'height_secondary_value' => '', |
| 142 |
'height_secondary_unit' => 'px', |
| 143 |
'options' => array(), |
| 144 |
'el_class' => '', |
| 145 |
), $atts, 'wpvr_virtual_tour' ); |
| 146 |
|
| 147 |
// Tour ID. |
| 148 |
$tour_id = intval( $atts['id'] ); |
| 149 |
if ( $tour_id <= 0 ) { |
| 150 |
return '<div class="wpvr-vc-error">WPVR: Please select a tour.</div>'; |
| 151 |
} |
| 152 |
|
| 153 |
// WIDTH. |
| 154 |
if ( $atts['width_unit'] === 'fullwidth' ) { |
| 155 |
$width = '100%'; |
| 156 |
} else { |
| 157 |
$width = esc_attr( trim( $atts['width_value'] ) . $atts['width_unit'] ); |
| 158 |
} |
| 159 |
|
| 160 |
// HEIGHT. |
| 161 |
$height = esc_attr( trim( $atts['height_value'] ) . $atts['height_unit'] ); |
| 162 |
|
| 163 |
// OPTIONS. |
| 164 |
$opt_attrs = array(); |
| 165 |
if ( ! empty( $atts['options'] ) ) { |
| 166 |
foreach ( $atts['options'] as $o ) { |
| 167 |
$opt_attrs[] = $o . '="true"'; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
// Shortcode assembly. |
| 172 |
$shortcode = '[wpvr id="' . $tour_id . '" width="' . $width . '" height="' . $height . '"'; |
| 173 |
if ( ! empty( $opt_attrs ) ) { |
| 174 |
$shortcode .= ' ' . implode( ' ', $opt_attrs ); |
| 175 |
} |
| 176 |
$shortcode .= ']'; |
| 177 |
|
| 178 |
// If WPVR disabled → fallback. |
| 179 |
if ( ! shortcode_exists( 'wpvr' ) ) { |
| 180 |
return '<div class="wpvr-fallback">WPVR plugin is not active.</div>'; |
| 181 |
} |
| 182 |
|
| 183 |
// Secondary height saved as data-attr for theme usage (not part of shortcode). |
| 184 |
$data_attr = ''; |
| 185 |
if ( $atts['height_secondary_value'] !== '' ) { |
| 186 |
$data_attr = ' data-height-secondary="' . |
| 187 |
esc_attr( $atts['height_secondary_value'] . $atts['height_secondary_unit'] ) . '"'; |
| 188 |
} |
| 189 |
|
| 190 |
// Output wrapper. |
| 191 |
$out = '<div class="wpvr-vc-wrapper ' . esc_attr( $atts['el_class'] ) . '"' . $data_attr . '>'; |
| 192 |
$out .= do_shortcode( $shortcode ); |
| 193 |
$out .= '</div>'; |
| 194 |
|
| 195 |
return $out; |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|