private function maybe_init_twig()
{
if (!isset($this->twig)) {
$loader = new Twig_Loader_Filesystem($this->template_paths);
$environment_args = array();
if (WP_DEBUG) {
$environment_args['debug'] = true;
}
$wpml_cache_directory = new WPML_Cache_Directory(new WPML_WP_API());
$cache_directory = $wpml_cache_directory->get('twig');
if ($cache_directory) {
$environment_args['cache'] = $cache_directory;
$environment_args['auto_reload'] = true;
}
$this->twig = new Twig_Environment($loader, $environment_args);
if (isset($this->custom_functions) && count($this->custom_functions) > 0) {
foreach ($this->custom_functions as $custom_function) {
$this->twig->addFunction($custom_function);
}
}
if (isset($this->custom_filters) && count($this->custom_filters) > 0) {
foreach ($this->custom_filters as $custom_filter) {
$this->twig->addFilter($custom_filter);
}
}
}
}