Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with latest release #2655

Closed
bwalker5 opened this issue Oct 19, 2022 · 10 comments
Closed

Bug with latest release #2655

bwalker5 opened this issue Oct 19, 2022 · 10 comments

Comments

@bwalker5
Copy link

We received the latest Timber update last night 1.21 and our web site wasn't available after that (error message on page). The issue was resolved by going back to 1.20.

Here is part of the error that was in our WordPress logs - PHP Fatal error: Uncaught Error: Class "Twig_Filter_Function" not found***

Expected behavior

Actual behavior

Steps to reproduce behavior

What version of WordPress, PHP and Timber are you using?

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

@GaelenN
Copy link

GaelenN commented Oct 19, 2022

Also having this problem with a client site.

@mrfsrf
Copy link

mrfsrf commented Oct 20, 2022

you have to specify more information. Did you install Timber using composer and than switched to wp plugin version, or vise versa?
Make sure to remove autoloading if you switched from composer to plugin..

Have a look at the timber starter theme functions.php

https://github.com/timber/starter-theme/blob/1.x/functions.php#L159

@gchtr
Copy link
Member

gchtr commented Oct 20, 2022

We have a pretty good idea where this is issue might be coming from and are currently investigating.

@bwalker5
Copy link
Author

We have a pretty good idea where this is issue might be coming from and are currently investigating.

do you need any info from me to help troubleshoot the issue?

@jarednova
Copy link
Member

@bwalker5 if you're interested in lending a hand, we just published to WP.org. Are you able to download and verify in one of your setups?

https://wordpress.org/plugins/timber-library/

@Luckyfella73
Copy link

I'm not sure why this issue arouse "out of nothing" in my project - but I think there is still an issue.
My PHP error logs sais:

[17-Nov-2022 18:46:40 UTC] PHP Fatal error:  Uncaught Twig\Error\SyntaxError: Unknown "filter" tag.
in /project-path/content/themes/mbtk-wp-theme/app/public/templates/includes/footer.twig:11

Stack trace:
#0 /project-path/vendor/twig/twig/src/Parser.php(83):
Twig\Parser->subparse(NULL, false)

#1 /project-path/vendor/twig/twig/src/Environment.php(488):
Twig\Parser->parse(Object(Twig\TokenStream))

#2 /project-path/vendor/twig/twig/src/Environment.php(516):
Twig\Environment->parse(Object(Twig\TokenStream))

#3 /project-path/vendor/twig/twig/src/Environment.php(348):
Twig\Environment->compileSource(Object(Twig\Source))

#4 /project-path/vendor/twig/twig/src/Template.php(322):
Twig\Environment->loadTemplate('__TwigTemplate_...', 'templates/inclu...', NULL)

#5 /project-path/vendor/twig/twig/src/Environment.php(358) :
eval()'d code(342): Twig\Template->loadTemplate('templates/inclu...', '@templates/base...', 88)

#6 /Users/iMs in /project-path/content/themes/mbtk-wp-theme/app/public/templates/includes/footer.twig on line 11

I load Timber via composer (Composer version 2.4.4)

...
"require": {
        "php": ">=7.0",
        "timber/timber": "^1.22"
    },
...

Wordpress version: 6.1.1

Line that (suddenly) causes this error:

{% filter shortcodes %}
	[eeb_mailto email="{{ options.opt_ts__public_email }}" extra_attrs="class='email'" method="rot13" display="{{ options.opt_ts__public_email }}"]
{% endfilter %}

Even it worked for month like that I tried other shortcodes or just empty space without success.

Btw: A custom filter applied via pipe (|) works:

// in my controller
private function add_twig_filter()
{
	function extract_tel_link( $phone_string )
	{
		$phone_tel = $phone_string;
		$phone_tel = str_replace('(0)', '', $phone_tel);
		$phone_tel = preg_replace('/[^\d+]/', '', $phone_tel);
		return $phone_tel;
	}

	function add_to_twig( $twig )
	{
		/* this is where you can add your own filters to twig */
		$twig->addExtension( new Twig\Extension\StringLoaderExtension() );
		$twig->addFilter( new Twig\TwigFilter( 'extract_tel_link', 'extract_tel_link' ) );
		return $twig;
	}

	add_filter('get_twig', 'add_to_twig');
}
// in my template (same file "footer.twig" from the error log)
{% set phoneNumber = options.opt_ts__public_phone_number %}
<a href="tel:{{ phoneNumber|extract_tel_link }}">{{ phoneNumber }}</a>

I tested this with PHP Version 7.4.21 and PHP 8.0.8 - same problem. Because I didn't change
anything via composer and working with this two PHP versions since a while I very confused
why the filter is not working anymore.

@gchtr
Copy link
Member

gchtr commented Nov 22, 2022

It looks like this is the same issue as #2672. It will be fixed in #2679.

For a very quick fix you could use

composer require twig/twig ^2

@gchtr
Copy link
Member

gchtr commented Nov 24, 2022

We just released a new 1.22.1 version. Could you check whether you still have your issue?

@Luckyfella73
Copy link

@gchtr I can confirm that my Unknown "filter" tag issue is solved with TimberTwig 1.22.1

Thanks for fixing the issue that fast! 🙏

@jarednova
Copy link
Member

Great to hear @Luckyfella73 ! thanks to @rmens for submitting the PR to help us here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants