Created
September 9, 2015 11:06
-
-
Save EugeneCib/e77506f066b7c4b5c6f3 to your computer and use it in GitHub Desktop.
WordPress escape function extension for Twig. Escape functions as twig filters and functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Twig_Extension_WP_basic_functions extends Twig_Extension | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getFunctions() | |
{ | |
return array( | |
new Twig_SimpleFunction('esc_html', 'esc_html'), | |
new Twig_SimpleFunction('esc_html__', 'esc_html__'), | |
new Twig_SimpleFunction('esc_html_e', 'esc_html_e'), | |
new Twig_SimpleFunction('esc_html_x', 'esc_html_x'), | |
new Twig_SimpleFunction('esc_attr', 'esc_attr'), | |
new Twig_SimpleFunction('esc_url', 'esc_url'), | |
new Twig_SimpleFunction('esc_url_raw', 'esc_url_raw'), | |
new Twig_SimpleFunction('esc_js', 'esc_js'), | |
new Twig_SimpleFunction('esc_textarea', 'esc_textarea'), | |
new Twig_SimpleFunction('sanitize_email', 'sanitize_email'), | |
new Twig_SimpleFunction('antispambot', 'antispambot'), | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getFilters() | |
{ | |
return array( | |
new Twig_SimpleFilter( 'esc_html', 'esc_html' ), | |
new Twig_SimpleFilter( 'esc_attr', 'esc_attr' ), | |
new Twig_SimpleFilter( 'esc_url', 'esc_url' ), | |
new Twig_SimpleFilter('esc_url_raw', 'esc_url_raw'), | |
new Twig_SimpleFilter( 'esc_js', 'esc_js' ), | |
new Twig_SimpleFilter('esc_textarea', 'esc_textarea'), | |
new Twig_SimpleFilter('nl2br', 'nl2br'), | |
new Twig_SimpleFilter('sanitize_email', 'sanitize_email'), | |
new Twig_SimpleFilter('antispambot', 'antispambot'), | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getName() | |
{ | |
return 'wp_escape'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment