<?php
/**
 * Enqueue child styles.
 */
function child_enqueue_styles() {
	wp_enqueue_style( 'child-theme', get_stylesheet_directory_uri() . '/style.css', array(), 100 );
}
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles' );

// Display page title using shortcode
function bw_page_title( ){
   return get_the_title();
}
add_shortcode( 'bw_page_title', 'bw_page_title' );

// High res image
add_filter( 'big_image_size_threshold', '__return_false' );

// Sidebars
add_action( 'widgets_init', 'bw_sidebar' );
function bw_sidebar() {

  $bw_sidebars = array(
    array(
      'name'          => 'The Resort',
      'id'            => 'the-resort-widget-area',
      'description'   => 'Widgets shown on resort pages',
    ),
    array(
      'name'          => 'Accommodations',
      'id'            => 'accommodations-widget-area',
      'description'   => 'Widgets shown on accommodations pages',
    ),
    array(
      'name'          => 'Location',
      'id'            => 'location-widget-area',
      'description'   => 'Widgets shown on location pages',
    ),  
    array(
      'name'          => 'Events',
      'id'            => 'events-widget-area',
      'description'   => 'Widgets shown on events pages',
    ),
    array(
      'name'          => 'Meetings',
      'id'            => 'meetings-widget-area',
      'description'   => 'Widgets shown on meeting pages',
    ),
    array(
      'name'          => 'Photos',
      'id'            => 'photos-widget-area',
      'description'   => 'Widgets shown on photos pages',
    ),
    array(
      'name'          => 'Press',
      'id'            => 'press-widget-area',
      'description'   => 'Widgets shown on press pages',
    ),
	array(
      'name'          => 'Ownership',
      'id'            => 'ownership-widget-area',
      'description'   => 'Widgets shown on press pages',
    ),
    array(
      'name'          => 'Contact',
      'id'            => 'contact-widget-area',
      'description'   => 'Widgets shown on contact pages',
    ),
  );

  $defaults = array(
    'name'          => 'BW Sidebar',
    'id'            => 'bw-sidebar',
    'description'   => 'Sidebar is shown on the left hand of this web',
    'class'         => '',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>' 
  );

  foreach( $bw_sidebars as $sidebar ) {
    $args = wp_parse_args( $sidebar, $defaults );
    register_sidebar( $args );
  }

}

add_filter( 'wpmem_notify_addr', function( $email ) {
    // single email example
    $email = 'info@yourvilladelmar.com';
    return $email;
});

/* Shortcode to display date using ACF shortcode */
function acf_date_shortcode( $atts )
{
extract( shortcode_atts( array(
		'field'			=> '',
		'post_id'		=> false,
		'format_value'	=> true,
		'date_format' 	=> ''
	), $atts ) );
	
	$acf_date = get_field( $field, $post_id, $format_value );
	
	$value = date_i18n( $date_format,strtotime($acf_date) );
		return $value;
}
add_shortcode( 'acf_date', 'acf_date_shortcode' );

add_action('wp_head', function() {
	echo 
		"
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-NC387N4M');</script>
<!-- End Google Tag Manager -->		
		
		";
});