contact-info-functions.php 4.1 KB

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