<?php
/**
 * HolyCross functions and definitions
 *
 * @package WordPress
 * @subpackage HolyCross
 * @since 1.0
 */

/**
 * Sets the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
error_reporting(0);
function holycross_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'holycross_content_width', 840 );
}
add_action( 'after_setup_theme', 'holycross_content_width', 0 );

include_once get_template_directory() . '/includes/constants.php';
include_once get_template_directory() . '/includes/init.php';

function update_active_based_on_date()
{

	$id = $_GET['post'];
	$start_date	=	get_field('start_date', $id);
	$end_date	=	get_field('end_date', $id);
	$duration	=	get_field('duration', $id);
	// echo $end_date;?
	$today_date = 	date('d-m-Y');
	$start_value = date('d-m-Y', strtotime($start_date . '+' . $duration[0]));
	//strtotime($start_date . '+' . $duration[0])
	$end_value = date('d-m-Y', strtotime($end_date . '+' . $duration[0]));
	$start_key = "field_642124f6e59da";
	$end_key = "field_64212503e59db";
	// end while have_posts
	if (strtotime($end_date) < strtotime($today_date)) {
		update_field($start_key, $start_value, $id);
		update_field($end_key, $end_value, $id);
	}
}

add_action('init', 'update_active_based_on_date');

function my_enqueue($hook)
{
	// Only add to the edit.php admin page.
	// See WP docs.
	if (get_post_type() === 'slz-event') {  ?>
		<script type="text/javascript">
			setTimeout(function() {
				location.reload();
			}, 86400000);
		</script>
 <?php  }
}

add_action('admin_enqueue_scripts', 'my_enqueue');

