title: Theme Files getting include in .ics downloaded file
body: <p>Im working on a simple script to include a &quot;Add to calendar&quot; button.
  Im using the idea and ICS.php file from <a href="https://gist.github.com/jakebellacera/635416" rel="nofollow noreferrer">https://gist.github.com/jakebellacera/635416</a> that is a old post.</p>
  <p>Im getting the file to download through a function using add_action( 'template_redirect', 'cl_download_ics' ); [The theme is Avada]. But what is happening now is that the download invite is including the themes template file to the file that I don't want and even after removing the template code that was added extra the file still does not want to add the event to the iCalendar.</p>
  <p>Here is the code I have so var.</p>
  <pre><code>include_once (plugin_dir_path(__DIR__).'cl-add-to-calendar/ics.php');
  
  function cl_download_ics(){
  
    if (isset( $_GET['ics'])) {
  
  
      $query_data_get = $_POST;
      //$query_data = $query_data_get['calendar_data'];
  
      $dtstart = date_create($query_data_get['date_start']);
      $dtstart = date_format($dtstart,&quot;Y/m/d H:i:s&quot;);
  
      $dtend = date_create($query_data_get['date_end']);
      $dtend = date_format($dtend,&quot;Y/m/d H:i:s&quot;);
  
  
      header('Content-Type: text/calendar; charset=utf-8');
      header('Content-Disposition: attachment; filename=Invite.ics');
  
      $ics = new ICS(array(
        'location' =&gt; $query_data_get['location'],
        'description' =&gt; $query_data_get['description'],
        'dtstart' =&gt; $dtstart,
        'dtend' =&gt; $dtend,
        'summary' =&gt; $query_data_get['summary'],
        'url' =&gt; $query_data_get['url']
      ));
  
      echo $ics-&gt;to_string();
    }
  
  }
  
  add_action( 'template_redirect', 'cl_download_ics' );
  
  
  function calendar_btn_ad($atts){
  
    // Shortcode atts with examples
    // dtsrart      --- 2017-1-16 9:00AM
    // dtend        --- 2017-1-16 9:00AM
    // location     --- 123 Fake St, New York, NY
    // description  --- This is my description
    // summary      --- This is my summary
    // url          --- http://example.com
  
    $form_input_fields = array();
    if (! empty($atts['dtsrart'])) {
      $form_input_fields[] = '&lt;input type=&quot;hidden&quot; name=&quot;date_start&quot; value=&quot;'.$atts['dtsrart'].'&quot;&gt;';
    };
  
    if (! empty($atts['dtend'])) {
      $form_input_fields[] = '&lt;input type=&quot;hidden&quot; name=&quot;date_end&quot; value=&quot;'.$atts['dtend'].'&quot;&gt;';
    };
  
    if (! empty($atts['location'])) {
      $form_input_fields[] = '&lt;input type=&quot;hidden&quot; name=&quot;location&quot; value=&quot;'.$atts['location'].'&quot;&gt;';
    };
  
    if (! empty($atts['description'])) {
      $form_input_fields[] = '&lt;input type=&quot;hidden&quot; name=&quot;description&quot; value=&quot;'.$atts['description'].'&quot;&gt;';
    };
  
    if (! empty($atts['summary'])) {
      $form_input_fields[] = '&lt;input type=&quot;hidden&quot; name=&quot;summary&quot; value=&quot;'.$atts['summary'].'&quot;&gt;';
    };
  
    if (! empty($atts['url'])) {
      $form_input_fields[] = '&lt;input type=&quot;hidden&quot; name=&quot;url&quot; value=&quot;'.$atts['url'].'&quot;&gt;';
    };
  
  
    $download_link = WP_PLUGIN_URL.'/cl-add-to-calendar/download-ics.php';
  
    ob_start();
    ?&gt;
  
    &lt;form action=&quot;?ics=true&quot; method=&quot;post&quot;&gt;
      &lt;?php foreach ($form_input_fields as $input_field): ?&gt;
        &lt;?php echo $input_field; ?&gt;
      &lt;?php endforeach; ?&gt;
      &lt;input type=&quot;submit&quot; id=&quot;cl-add-calendar-submit&quot; value=&quot;Add to Calendar&quot;&gt;
    &lt;/form&gt;
  
    &lt;div id=&quot;cl-btn-ajax-result&quot;&gt;
  
    &lt;/div&gt;
  
    &lt;?php
    $output = ob_get_clean();
    return $output;
  }
  
  add_shortcode('cl_calendar_btn', 'calendar_btn_ad');
  </code></pre>