I have a plugin in which I'm trying to allow users to create their own variants of the styles, and upload them as custom "templates". Essentially these templates are php files with some HTML in them.
I'm trying to add a template tag to the top of each files, so I can extract certain data such as the template name and maybe an author.
I've been doing a bit of research and came across a function I haven't used before
get_file_data();. There doesn't seem to be too much information regarding how to use the function to extract data from a template file.
Each time I try and run this function to return some data it either returns empty or with an array with one key and no value assigned. I must be doing something wrong. Unfortunately their is not much in the codex http://codex.wordpress.org/Function_Reference/get_file_data https://developer.wordpress.org/reference/functions/get_file_data/
$template_data = get_file_data( $content_path . 'template_1.php' , array( 'Template Name' => 'Template Name' ) ); print_r($template_data );
I can't seem to figure out what the default headers argument (2nd argument) is doing.
The contents of the
template_1.php file is :
<?php /* Template Name: Cool Template File Template Author: Evan */ ?>
I'm not sure what it is I'm doing wrong, or what I should be doing to extract the data at the top of this file properly.