| 1 |
<?php |
| 2 |
|
| 3 |
$twig = new Twig_Environment(new Twig_Loader_Filesystem([ |
| 4 |
dirname(dirname(__FILE__)) . '/views', |
| 5 |
dirname(dirname(__FILE__)) . '/public', |
| 6 |
]), ['autoescape' => false]); |
| 7 |
|
| 8 |
$twig->addFilter(new Twig_SimpleFilter('shortcode', function($string) { |
| 9 |
return do_shortcode($string); |
| 10 |
})); |
| 11 |
|
| 12 |
$twig->addFilter(new Twig_SimpleFilter('translate', function($string, $key) { |
| 13 |
$translated = apply_filters('wpml_translate_single_string', $string, 'Responsive Menu', $key); |
| 14 |
$translated = function_exists('pll__') ? pll__($translated) : $translated; |
| 15 |
return $translated; |
| 16 |
})); |
| 17 |
|
| 18 |
$twig->addFilter(new Twig_SimpleFilter('json_decode', function($string) { |
| 19 |
return json_decode($string, true); |
| 20 |
})); |
| 21 |
|
| 22 |
$twig->addFunction(new Twig_SimpleFunction('header_bar_items', function($items) { |
| 23 |
if(isset($items['button'])) |
| 24 |
unset($items['button']); |
| 25 |
return $items; |
| 26 |
})); |
| 27 |
|
| 28 |
$twig->addFunction(new Twig_SimpleFunction('build_menu', function($env, $options) { |
| 29 |
|
| 30 |
$translator = $env->getFilter('translate')->getCallable(); |
| 31 |
$menu = $translator($options['menu_to_use'], 'menu_to_use'); |
| 32 |
$walker = $options['custom_walker'] ? new $options['custom_walker']($options) : new ResponsiveMenu\Walkers\Walker($options); |
| 33 |
|
| 34 |
return wp_nav_menu( |
| 35 |
[ |
| 36 |
'container' => '', |
| 37 |
'menu_id' => 'responsive-menu', |
| 38 |
'menu_class' => null, |
| 39 |
'menu' => $menu && !$options['theme_location_menu'] ? $menu : null, |
| 40 |
'depth' => $options['menu_depth'] ? $options['menu_depth'] : 0, |
| 41 |
'theme_location' => $options['theme_location_menu'] ? $options['theme_location_menu'] : null, |
| 42 |
'walker' => $walker, |
| 43 |
'echo' => false |
| 44 |
] |
| 45 |
); |
| 46 |
|
| 47 |
}, ['needs_environment' => true])); |
| 48 |
|
| 49 |
$twig->addGlobal('search_url', function_exists('icl_get_home_url') ? icl_get_home_url() : get_home_url()); |
| 50 |
$twig->addGlobal('admin_url', get_admin_url()); |
| 51 |
$twig->addFunction(new Twig_SimpleFunction('current_page', function() { |
| 52 |
return get_option('responsive_menu_current_page', 'initial-setup'); |
| 53 |
})); |
| 54 |
return $twig; |