| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
|
| 8 |
add_shortcode( 'avada_property_embedded_virtual_tours', function( $atts ) { |
| 9 |
$atts = shortcode_atts( array( |
| 10 |
'show_title' => '', |
| 11 |
'oembed' => '', |
| 12 |
), $atts ); |
| 13 |
|
| 14 |
if ( get_post_type( get_the_ID() ) != 'property' ) |
| 15 |
{ |
| 16 |
return ''; |
| 17 |
} |
| 18 |
|
| 19 |
fusion_element_rendering_elements( true ); |
| 20 |
|
| 21 |
global $property; |
| 22 |
|
| 23 |
if ( empty($property) ) |
| 24 |
{ |
| 25 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared frontend property global used by the Avada shortcode contract; changing $property would break the existing property context passed to these widgets. |
| 26 |
$property = new PH_Property(get_the_ID()); |
| 27 |
} |
| 28 |
|
| 29 |
ob_start(); |
| 30 |
|
| 31 |
$virtual_tours = $property->get_virtual_tours(); |
| 32 |
|
| 33 |
if ( !empty($virtual_tours) ) |
| 34 |
{ |
| 35 |
echo '<div class="embedded-virtual-tours">'; |
| 36 |
|
| 37 |
if ( $atts['show_title'] == 'yes' ) { echo '<h4>' . esc_html(__( 'Virtual Tours', 'propertyhive' )) . '</h4>'; } |
| 38 |
|
| 39 |
foreach ( $virtual_tours as $virtual_tour ) |
| 40 |
{ |
| 41 |
if ( isset($atts['oembed']) && $atts['oembed'] == 'yes' ) |
| 42 |
{ |
| 43 |
$embed_code = wp_oembed_get($virtual_tour['url']); |
| 44 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_oembed_get() uses WordPress provider trust and sanitization; preserve supported provider scripts and trusted PHP filters. |
| 45 |
echo $embed_code; |
| 46 |
} |
| 47 |
else |
| 48 |
{ |
| 49 |
$virtual_tour['url'] = preg_replace( |
| 50 |
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", |
| 51 |
"//www.youtube.com/embed/$2", |
| 52 |
$virtual_tour['url'] |
| 53 |
); |
| 54 |
|
| 55 |
$virtual_tour['url'] = preg_replace( |
| 56 |
'#https?://(www\.)?youtube\.com/shorts/([^/?]+)#', |
| 57 |
'//www.youtube.com/embed/$2', |
| 58 |
$virtual_tour['url'] |
| 59 |
); |
| 60 |
|
| 61 |
$virtual_tour['url'] = preg_replace( |
| 62 |
'/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/i', |
| 63 |
"//player.vimeo.com/video/$6", |
| 64 |
$virtual_tour['url'] |
| 65 |
); |
| 66 |
|
| 67 |
echo '<iframe src="' . esc_url($virtual_tour['url']) . '" height="500" width="100%" allowfullscreen frameborder="0" allow="fullscreen"></iframe>'; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
echo '</div>'; |
| 72 |
} |
| 73 |
|
| 74 |
$html = ob_get_clean(); |
| 75 |
|
| 76 |
fusion_element_rendering_elements( false ); |
| 77 |
|
| 78 |
return $html; |
| 79 |
}); |
| 80 |
|