1: <?php
2: /**
3: * Hook for Mini Website Links used with commercial and business listings
4: *
5: * @package EPL
6: * @subpackage Hooks/WebLink
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 commercial or business mini web links
19: *
20: * When the hook epl_buttons_single_property is used and the commercial/business
21: * property as a mini web links they will be output on the template
22: *
23: * @since 1.0.0
24: * @since 3.4.24 Refactored, added epl_button_label_{$key} filter for labels.
25: * @since 3.4.25 filter epl_show_{key} e.g. epl_show_property_com_mini_web to disable button rendering.
26: * @since 3.4.37 Added filter epl_mini_web_keys to support additional mini web links.
27: * @since 3.5 Fix for label to use esc_html instead of esc_attr.
28: */
29: function epl_button_mini_web() {
30:
31: $keys = apply_filters( 'epl_mini_web_keys', array( 'property_com_mini_web', 'property_com_mini_web_2', 'property_com_mini_web_3' ) );
32:
33: foreach ( $keys as $key ) {
34:
35: $link = get_post_meta( get_the_ID(), $key, true );
36: $count = 'property_com_mini_web' === $key ? '' : substr( $key, -1 );
37: $meta_label = __( 'Mini Web ', 'easy-property-listings' ) . $count;
38:
39: // Counter so pass.
40: $count = empty( $count ) ? '1' : $count;
41:
42: if ( ! empty( $link ) && apply_filters( 'epl_show_' . $key, true ) ) { ?>
43: <button type="button" class="epl-button epl-mini-web-link <?php echo 'epl-mini-web-link-' . esc_attr( $count ); ?>" onclick="window.open('<?php echo esc_url( $link ); ?>')">
44: <?php
45:
46: if ( has_filter( 'epl_button_label_' . $key ) ) {
47: $label = apply_filters( 'epl_button_label_' . $key, $meta_label );
48: } else {
49: $label = apply_filters( 'epl_button_label_mini_web', $meta_label );
50: }
51: ?>
52: <?php echo esc_html( $label ); ?>
53: </button>
54: <?php
55: }
56: }
57: }
58: add_action( 'epl_buttons_single_property', 'epl_button_mini_web' );
59: