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