I have recently installed Timber on to my WordPress instance but whenever I try to run single.php
for the timber-starter I get the following error:
Fatal error: Uncaught Error: Class 'Timber' not found in www\Website\wp\wp-content\plugins\timber-library\timber-starter-theme\single.php:12 Stack trace: #0 {main} thrown in www\Website\wp\wp-content\plugins\timber-library\timber-starter-theme\single.php on line 12
I have read that there can be issues with namespace and to update it to Timber\Timber. I have tried this also and get the same class not found for Timber\Timber. Interestingly, if I open it in PHPStorm I can navigate to the function directly from the class call so it is able to recognise it there.
Does anyone have any ideas? I've tried different versions of PHP, different versions of WordPress and installing via WP-Admin and manually. None of these options are fixing this issue. (Please note, I also get this error for going to index.php
in this directory).
Here is the code from single.php with the added namespace definition.
<?php
/**
* The Template for displaying all single posts
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
use Timber\Timber;
$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
if ( post_password_required( $post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );
}