contact-info-functions.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. if ( ! function_exists( 'radcliffe_2_contact_info' ) ) :
  3. /**
  4. * Prints HTML with contact information.
  5. */
  6. function radcliffe_2_contact_info( $section ) {
  7. $location = get_theme_mod( 'radcliffe_2_contact_info_location', 'header' );
  8. $contact = get_option( 'site_contact_info' );
  9. if ( is_array( $contact ) ) {
  10. $address = isset( $contact['address'] ) ? $contact['address'] : '';
  11. $phone = isset( $contact['phone'] ) ? $contact['phone'] : '';
  12. $email = isset( $contact['email'] ) ? $contact['email'] : '';
  13. } else {
  14. $address = get_theme_mod( 'radcliffe_2_contact_info_address', '' );
  15. $phone = get_theme_mod( 'radcliffe_2_contact_info_phone', '' );
  16. $email = get_theme_mod( 'radcliffe_2_contact_info_email', '' );
  17. }
  18. $email = $email ? antispambot( $email ) : '';
  19. $hours = get_theme_mod( 'radcliffe_2_contact_info_hours', '' );
  20. // If Address, Phone, Email and Hours are empty, return.
  21. if ( ( ! $address && ! is_customize_preview() ) &&
  22. ( ! $phone && ! is_customize_preview() ) &&
  23. ( ! $email && ! is_customize_preview() ) &&
  24. ( ! $hours && ! is_customize_preview() ) ) {
  25. return;
  26. }
  27. // If we are in the Header Section and the option is disabled, return.
  28. if ( 'header' === $section && 'header' !== $location && ! is_customize_preview() ) {
  29. return;
  30. }
  31. // If we are in the Footer Section and the option is disabled, return.
  32. if ( 'footer' === $section && 'footer' !== $location && ! is_customize_preview() ) {
  33. return;
  34. }
  35. // Let's set up some stuff for the Customizer preview
  36. $class = '';
  37. if ( is_customize_preview() ) {
  38. if ( ! $address ) {
  39. $class .= ' contact-info-no-address';
  40. }
  41. if ( ! $phone ) {
  42. $class .= ' contact-info-no-phone';
  43. }
  44. if ( ! $email ) {
  45. $class .= ' contact-info-no-email';
  46. }
  47. if ( ! $hours ) {
  48. $class .= ' contact-info-no-hours';
  49. }
  50. if ( 'footer' === $location ) {
  51. $class .= ' contact-info-header-no-display';
  52. } else if ( 'header' === $location ) {
  53. $class .= ' contact-info-footer-no-display';
  54. }
  55. }
  56. ?>
  57. <div class="contact-info-area <?php echo $class; ?>">
  58. <div class="contact-info-wrapper">
  59. <?php if ( $address || is_customize_preview() ) : ?>
  60. <span class="contact-info-address">
  61. <a href="<?php echo esc_url( radcliffe_2_map_link( $address ) ); ?>" target="_blank">
  62. <?php echo radcliffe_2_get_svg( array( 'icon' => 'location', 'title' => esc_html__( 'Location', 'radcliffe-2' ) ) ); ?>
  63. <span class="contact-info-label"><?php echo esc_html( $address ); ?></span>
  64. </a>
  65. </span>
  66. <?php endif; ?>
  67. <?php if ( $phone || is_customize_preview() ) : ?>
  68. <span class="contact-info-phone">
  69. <a href="tel:<?php echo esc_html( $phone ); ?>">
  70. <?php echo radcliffe_2_get_svg( array( 'icon' => 'phone', 'title' => esc_html__( 'Phone', 'radcliffe-2' ) ) ); ?>
  71. <span class="contact-info-label"><?php echo esc_html( $phone ); ?></span>
  72. </a>
  73. </span>
  74. <?php endif; ?>
  75. <?php if ( $email || is_customize_preview() ) : ?>
  76. <span class="contact-info-email">
  77. <a href="mailto:<?php echo esc_html( $email ); ?>">
  78. <?php echo radcliffe_2_get_svg( array( 'icon' => 'mail', 'title' => esc_html__( 'E-mail', 'radcliffe-2' ) ) ); ?>
  79. <span class="contact-info-label"><?php echo esc_html( $email ); ?></span>
  80. </a>
  81. </span>
  82. <?php endif; ?>
  83. <?php if ( $hours || is_customize_preview() ) : ?>
  84. <span class="contact-info-hours">
  85. <?php echo radcliffe_2_get_svg( array( 'icon' => 'time', 'title' => esc_html__( 'Hours', 'radcliffe-2' ) ) ); ?>
  86. <span class="contact-info-hours-text"><?php echo esc_html( $hours ); ?></span>
  87. </span>
  88. <?php endif; ?>
  89. </div><!-- .contact-info-wrapper -->
  90. </div><!-- .contact-info-area -->
  91. <?php
  92. }
  93. endif;
  94. /**
  95. * Encode an address for a Google Maps link.
  96. */
  97. function radcliffe_2_urlencode_address( $address ) {
  98. $address = strtolower( $address );
  99. $address = preg_replace( "/\s+/", " ", trim( $address ) ); // Get rid of any unwanted whitespace.
  100. $address = str_ireplace( " ", "+", $address ); // Use + not %20.
  101. urlencode( $address );
  102. return $address;
  103. }
  104. /**
  105. * Return a link with a specific address to Google Maps.
  106. */
  107. function radcliffe_2_map_link( $address ) {
  108. return esc_url( 'http://maps.google.com/maps?q=' . radcliffe_2_urlencode_address( $address ) );
  109. }
  110. /**
  111. * Customizer additions.
  112. */
  113. require get_template_directory() . '/contact-info/contact-info-customizer.php';