I'm using Post templates plugin. But its very outdated.
I'm getting Warning: Illegal offset type at this line
$templates = $themes[$theme]['Template Files'];
Here is my full function code.
function get_post_templates() {
$themes = wp_get_themes();
$theme = wp_get_theme();
$templates = $themes[$theme]['Template Files'];
$post_templates = array();
$base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
foreach ((array)$templates as $template) {
$template = WP_CONTENT_DIR . str_replace(WP_CONTENT_DIR, '', $template);
$basename = str_replace($base, '', $template);
// don't allow template files in subdirectories
if (false !== strpos($basename, '/'))
continue;
$template_data = implode('', file( $template ));
$name = '';
if (preg_match( '|Single Post Template:(.*)$|mi', $template_data, $name))
$name = _cleanup_header_comment($name[1]);
if (!empty($name)) {
if(basename($template) != basename(__FILE__))
$post_templates[trim($name)] = $basename;
}
}
return $post_templates;
}
Can someone tell me how to fix that?