| 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 |
if(!is_admin()): |
| 9 |
|
| 10 |
$twig->addFilter(new Twig_SimpleFilter('shortcode', function($string) { |
| 11 |
return do_shortcode($string); |
| 12 |
})); |
| 13 |
|
| 14 |
$twig->addFilter(new Twig_SimpleFilter('translate', function($string, $key) { |
| 15 |
$translated = apply_filters('wpml_translate_single_string', $string, 'Responsive Menu', $key); |
| 16 |
$translated = function_exists('pll__') ? pll__($translated) : $translated; |
| 17 |
return $translated; |
| 18 |
})); |
| 19 |
|
| 20 |
$twig->addFunction(new Twig_SimpleFunction('build_menu', function($env, $options) { |
| 21 |
|
| 22 |
$translator = $env->getFilter('translate')->getCallable(); |
| 23 |
$menu = $translator($options['menu_to_use'], 'menu_to_use'); |
| 24 |
$walker = $options['custom_walker'] ? new $options['custom_walker']($options) : new ResponsiveMenu\Walkers\Walker($options); |
| 25 |
|
| 26 |
return wp_nav_menu( |
| 27 |
[ |
| 28 |
'container' => '', |
| 29 |
'menu_id' => 'responsive-menu', |
| 30 |
'menu_class' => null, |
| 31 |
'menu' => $menu && !$options['theme_location_menu'] ? $menu : null, |
| 32 |
'depth' => $options['menu_depth'] ? $options['menu_depth'] : 0, |
| 33 |
'theme_location' => $options['theme_location_menu'] ? $options['theme_location_menu'] : null, |
| 34 |
'walker' => $walker, |
| 35 |
'echo' => false |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
}, ['needs_environment' => true])); |
| 40 |
|
| 41 |
$twig->addGlobal('search_url', function_exists('icl_get_home_url') ? icl_get_home_url() : get_home_url()); |
| 42 |
|
| 43 |
else: |
| 44 |
|
| 45 |
$twig->addFunction(new Twig_SimpleFunction('header_bar_items', function($items) { |
| 46 |
if(isset($items['button'])) |
| 47 |
unset($items['button']); |
| 48 |
return $items; |
| 49 |
})); |
| 50 |
|
| 51 |
$twig->addGlobal('admin_url', get_admin_url()); |
| 52 |
|
| 53 |
$twig->addFunction(new Twig_SimpleFunction('csrf', function() { |
| 54 |
return wp_nonce_field('update', 'responsive-menu-nonce', true, false); |
| 55 |
})); |
| 56 |
|
| 57 |
$twig->addFunction(new Twig_SimpleFunction('current_page', function() { |
| 58 |
return get_option('responsive_menu_current_page', 'initial-setup'); |
| 59 |
})); |
| 60 |
|
| 61 |
endif; |
| 62 |
|
| 63 |
$twig->addFilter(new Twig_SimpleFilter('json_decode', function($string) { |
| 64 |
return json_decode($string, true); |
| 65 |
})); |
| 66 |
|
| 67 |
return $twig; |