1: <?php
2: /**
3: * Hook for Floor plan Buttons on Property Templates
4: *
5: * @package EPL
6: * @subpackage Hooks/FloorPlan
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 floor plan links for virtual tours on the property templates
19: *
20: * When the hook epl_buttons_single_property is used and the property
21: * has floor plans links they will be output on the template
22: *
23: * @since 1.0
24: * @since 3.3.0
25: * @since 3.4.24 Fixed floor plan label filter.
26: * @since 3.4.25 filter epl_show_{key} e.g. epl_show_property_floorplan to disable button rendering.
27: * @since 3.4.38 Added filter epl_floorplan_keys to support additional floor plans.
28: * @since 3.5 Fix for label to use esc_html instead of esc_attr.
29: */
30: function epl_button_floor_plan() {
31:
32: $keys = apply_filters( 'epl_floorplan_keys', array( 'property_floorplan', 'property_floorplan_2' ) );
33:
34: foreach ( $keys as $key ) {
35:
36: $link = get_post_meta( get_the_ID(), $key, true );
37: $count = 'property_floorplan' === $key ? '' : substr( $key, - 1 );
38: $default = __( 'Floor Plan ', 'easy-property-listings' ) . $count;
39: $meta_label = get_post_meta( get_the_ID(), $key . '_label', true );
40: $meta_label = empty( $meta_label ) ? $default : $meta_label;
41:
42: if ( is_array( $link ) ) { // Fallback if metadata is saved as an array.
43:
44: if ( ! empty( $link['image_url_or_path'] ) ) {
45: $link = $link['image_url_or_path'];
46: } else {
47: $link = '';
48: }
49: }
50: if ( ! empty( $link ) && apply_filters( 'epl_show_' . $key, true ) ) { ?>
51:
52: <button type="button" class="epl-button epl-floor-plan epl-floor-plan-<?php echo absint( $count ); ?>"
53: onclick="window.open('<?php echo esc_url( $link ); ?>')">
54: <?php
55: $filter_key = str_replace( 'property_', '', $key );
56: if ( has_filter( 'epl_button_label_' . $filter_key ) ) {
57: $label = apply_filters( 'epl_button_label_' . $filter_key, $meta_label );
58: } else {
59: $label = apply_filters( 'epl_button_label_floorplan', $meta_label );
60: }
61: ?>
62: <?php echo esc_html( $label ); ?>
63: </button>
64: <?php
65:
66: }
67: }
68: }
69:
70: add_action( 'epl_buttons_single_property', 'epl_button_floor_plan' );
71: