Twig\Extension\CoreExtension::setEscaper() is deprecated#2070
Conversation
Codecov Report
@@ Coverage Diff @@
## 2.x #2070 +/- ##
===========================================
- Coverage 95.8% 95.68% -0.12%
Complexity 1517 1517
===========================================
Files 48 48
Lines 3862 3873 +11
===========================================
+ Hits 3700 3706 +6
- Misses 162 167 +5
Continue to review full report at Codecov.
|
|
This looks good to me @romainmenke! I had thought about getting a little more cleaver with assigning the class ( |
gchtr
left a comment
There was a problem hiding this comment.
I agree with @jarednova that here, it’s probably better to not get too clever. The only thing I see that could be optimized is that we could save the anonymous functions in variables and reuse them:
$esc_url = function( \Twig\Environment $env, $string ) {
return esc_url( $string );
}
if ( class_exists( 'Twig\Extension\EscaperExtension' ) ) {
$twig->getExtension( 'Twig\Extension\EscaperExtension' )->setEscaper('esc_url', $esc_url );
} else {
$twig->getExtension( 'Twig\Extension\CoreExtension' )->setEscaper( 'esc_url', $esc_url );
}|
Reusing those makes sense. I also assigned the escaper extensions to a variable as 4 calls to get the same thing wasn't optimal either. |
gchtr
left a comment
There was a problem hiding this comment.
@romainmenke Cool! Thanks for the changes. I think this looks much cleaner now.
However, I was merely using $esc_url as an example. Instead of using $esc_url for all escapers, we need to set variables for all the different anonymous functions. Sorry if that wasn’t clear enough!
$esc_url = function( \Twig\Environment $env, $string ) {
return esc_url( $string );
}
$wp_kses_post = function( \Twig\Environment $env, $string ) {
return wp_kses_post( $string );
}
$esc_html = function( \Twig\Environment $env, $string ) {
return esc_html( $string );
}
$esc_js = function( \Twig\Environment $env, $string ) {
return esc_js( $string );
}And then:
$escaper_extension->setEscaper( 'esc_url', $esc_url );
$escaper_extension->setEscaper( 'wp_kses_post', $wp_kses_post );
$escaper_extension->setEscaper( 'esc_html', $esc_html );
$escaper_extension->setEscaper( 'esc_js', $esc_js );
Yeah still early over here. Realised it just now too :) |
|
@gchtr should be better now. Thanks for the fast feedback! |
gchtr
left a comment
There was a problem hiding this comment.
Great! Thanks for the updates! 👍
|
@romainmenke Congratulations on your first contribution to Timber 🍾 ! |
Bring in fix for #2070 into master
let's try this from the proper base branch 🤦♂
see : #2062
This adds on
class_exists( 'Twig\Extension\EscaperExtension' )As of Twig 2.11, the Twig\Extension\CoreExtension::setEscaper() and Twig\Extension\CoreExtension::getEscapers() are deprecated. Use the same methods on Twig\Extension\EscaperExtension instead.