hero-area-functions.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. if ( ! function_exists( 'radcliffe_2_hero_area' ) ) :
  3. /**
  4. * Prints HTML with contact information.
  5. */
  6. function radcliffe_2_hero_area() {
  7. $display = get_theme_mod( 'radcliffe_2_hero_area_display', '' );
  8. $title = get_theme_mod( 'radcliffe_2_hero_area_title', '' );
  9. $content = get_theme_mod( 'radcliffe_2_hero_area_content', '' );
  10. $button = get_theme_mod( 'radcliffe_2_hero_area_button_text', '' );
  11. $url = get_theme_mod( 'radcliffe_2_hero_area_button_url', '' );
  12. $image = get_theme_mod( 'radcliffe_2_hero_area_background', '' );
  13. $class = 'hero-area';
  14. // If we are not on the front page, return.
  15. if ( ! is_front_page() ) {
  16. return;
  17. }
  18. // If the display option is unchecked, return.
  19. if ( ! $display && ! is_customize_preview() ) {
  20. return;
  21. }
  22. // If all the options are empty, return.
  23. if ( ( ! $title && ! $content && ! $button && ! $url ) && ! is_customize_preview() ) {
  24. return;
  25. }
  26. // If we are in the Customize preview and stuff's empty, add classes
  27. if ( is_customize_preview() ) {
  28. if ( ! $title ) {
  29. $class .= ' hero-no-title';
  30. }
  31. if ( ! $content ) {
  32. $class .= ' hero-no-content';
  33. }
  34. if ( ! $button ) {
  35. $class .= ' hero-no-buttontext';
  36. }
  37. if ( ! $url ) {
  38. $class .= ' hero-no-buttonlink';
  39. }
  40. }
  41. // Add extra class if there's an image background.
  42. if ( $image ) {
  43. $class .= ' has-post-thumbnail';
  44. } ?>
  45. <div class="<?php echo $class; ?>" <?php radcliffe_2_hero_area_background_image(); ?>>
  46. <div class="hero-area-wrapper">
  47. <?php if ( $title || is_customize_preview() ) : ?>
  48. <h2 class="hero-area-title"><?php echo esc_html( $title ); ?></h2>
  49. <?php endif; ?>
  50. <?php if ( $content || is_customize_preview() ) : ?>
  51. <div class="hero-area-content"><?php echo wp_kses_post( $content ); ?></div>
  52. <?php endif; ?>
  53. <?php if ( ( $url && $button ) || is_customize_preview() ) : ?>
  54. <div class="hero-area-button">
  55. <a class="button" href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $button ); ?></a>
  56. </div>
  57. <?php endif; ?>
  58. </div><!-- .hero-area-wrapper -->
  59. </div><!-- .hero-area -->
  60. <?php
  61. }
  62. endif;
  63. /**
  64. * Add uploaded image as background image.
  65. */
  66. function radcliffe_2_hero_area_background_image() {
  67. $image = get_theme_mod( 'radcliffe_2_hero_area_background', '' );
  68. if ( ! $image ) {
  69. return;
  70. }
  71. printf( 'style="background-image: url(\'%s\');"', esc_url( $image ) );
  72. }
  73. /**
  74. * Add inline CSS needed for overlay opacity
  75. *
  76. * @see wp_add_inline_style()
  77. */
  78. function radcliffe_2_hero_opacity_css() {
  79. $opacity = get_theme_mod( 'radcliffe_2_hero_overlay_opacity', '40' );
  80. $css = '.hero-area:before { opacity: ' . $opacity/100 . '; }';
  81. wp_add_inline_style( 'radcliffe-2-style', $css );
  82. }
  83. add_filter( 'wp_enqueue_scripts', 'radcliffe_2_hero_opacity_css' );
  84. /**
  85. * Customizer additions.
  86. */
  87. require get_template_directory() . '/hero-area/hero-area-customizer.php';