1: <?php
2: /**
3: * Hook for External Link Buttons on Property Templates
4: *
5: * @package EPL
6: * @subpackage Hooks/ExternalLinks
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * Outputs any external links for virtual tours on the property templates
19: *
20: * When the hook epl_buttons_single_property is used and the property
21: * has external links they will be output on the template
22: *
23: * @since 1.0.0
24: * @since 3.4.25 filter epl_show_{key} e.g. epl_show_property_external_link to disable button rendering.
25: * @since 3.4.38 Added filter epl_external_link_keys to support additional external links.
26: * @since 3.5 Fix for label to use esc_html instead of esc_attr.
27: */
28: function epl_button_external_link() {
29:
30: $keys = apply_filters(
31: 'epl_external_link_keys',
32: array(
33: 'property_external_link',
34: 'property_external_link_2',
35: 'property_external_link_3',
36: )
37: );
38:
39: foreach ( $keys as $key ) {
40: $link = get_post_meta( get_the_ID(), $key, true );
41: $count = 'property_external_link' === $key ? '' : substr( $key, - 1 );
42: $default = __( 'Tour ', 'easy-property-listings' ) . $count;
43: $meta_label = get_post_meta( get_the_ID(), $key . '_label', true );
44: $meta_label = empty( $meta_label ) ? $default : $meta_label;
45:
46: if ( is_array( $link ) ) { // Fallback if metadata is saved as an array.
47:
48: if ( ! empty( $link['image_url_or_path'] ) ) {
49: $link = $link['image_url_or_path'];
50: } else {
51: $link = '';
52: }
53: }
54:
55: if ( ! empty( $link ) && apply_filters( 'epl_show_' . $key, true ) ) { ?>
56: <button type="button" class="epl-button epl-external-link"
57: onclick="window.open('<?php echo esc_url( $link ); ?>')">
58: <?php
59:
60: if ( has_filter( 'epl_button_label_' . $key ) ) {
61: $label = apply_filters( 'epl_button_label_' . $key, $meta_label );
62: } else {
63: $label = apply_filters( 'epl_button_label_tour', $meta_label );
64: }
65: ?>
66: <?php echo esc_html( $label ); ?>
67: </button>
68: <?php
69:
70: }
71: }
72: }
73:
74: add_action( 'epl_buttons_single_property', 'epl_button_external_link' );
75: