1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function epl_button_external_link() {
$keys = apply_filters(
'epl_external_link_keys',
array(
'property_external_link',
'property_external_link_2',
'property_external_link_3',
)
);
foreach ( $keys as $key ) {
$link = get_post_meta( get_the_ID(), $key, true );
$count = 'property_external_link' === $key ? '' : substr( $key, - 1 );
$default = __( 'Tour ', 'easy-property-listings' ) . $count;
$meta_label = get_post_meta( get_the_ID(), $key . '_label', true );
$meta_label = empty( $meta_label ) ? $default : $meta_label;
if ( is_array( $link ) ) {
if ( ! empty( $link['image_url_or_path'] ) ) {
$link = $link['image_url_or_path'];
} else {
$link = '';
}
}
if ( ! empty( $link ) && apply_filters( 'epl_show_' . $key, true ) ) { ?>
<button type="button" class="epl-button epl-external-link"
onclick="window.open('<?php echo esc_url( $link ); ?>')">
<?php
if ( has_filter( 'epl_button_label_' . $key ) ) {
$label = apply_filters( 'epl_button_label_' . $key, $meta_label );
} else {
$label = apply_filters( 'epl_button_label_tour', $meta_label );
}
?>
<?php echo esc_html( $label ); ?>
</button>
<?php
}
}
}
add_action( 'epl_buttons_single_property', 'epl_button_external_link' );