PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.22
Responsive Menu – Create Mobile-Friendly Menu v3.1.22
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / config / twig.php

twig.php in Responsive Menu – Create Mobile-Friendly Menu 3.1.22, at config/twig.php

134 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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, 'debug' => false]);
7
8 //$twig->addExtension(new Twig_Extension_Debug());
9 if(!is_admin()):
10
11 $twig->addFilter(new Twig_SimpleFilter('shortcode', function($string) {
12 return do_shortcode($string);
13 }));
14
15 $twig->addFilter(new Twig_SimpleFilter('translate', function($string, $key) {
16 $translated = apply_filters('wpml_translate_single_string', $string, 'Responsive Menu', $key);
17 $translated = function_exists('pll__') ? pll__($translated) : $translated;
18 return $translated;
19 }));
20
21 $twig->addFunction(new Twig_SimpleFunction('build_menu', function($env, $options) {
22
23 $translator = $env->getFilter('translate')->getCallable();
24 $menu = $translator($options['menu_to_use'], 'menu_to_use');
25 $walker = $options['custom_walker'] ? new $options['custom_walker']($options) : new ResponsiveMenu\Walkers\Walker($options);
26
27 return wp_nav_menu(
28 [
29 'container' => '',
30 'menu_id' => 'responsive-menu',
31 'menu_class' => null,
32 'menu' => $menu && !$options['theme_location_menu'] ? $menu : null,
33 'depth' => $options['menu_depth'] ? $options['menu_depth'] : 0,
34 'theme_location' => $options['theme_location_menu'] ? $options['theme_location_menu'] : null,
35 'walker' => $walker,
36 'echo' => false
37 ]
38 );
39
40 }, ['needs_environment' => true]));
41
42 $twig->addGlobal('search_url', function_exists('icl_get_home_url') ? icl_get_home_url() : get_home_url());
43
44 else:
45
46 $twig->addFunction(new Twig_SimpleFunction('csrf', function() {
47 return wp_nonce_field('update', 'responsive-menu-nonce', true, false);
48 }));
49
50 $twig->addFunction(new Twig_SimpleFunction('current_page', function() {
51 return get_option('responsive_menu_current_page', 'initial-setup');
52 }));
53
54 $twig->addFunction(new Twig_SimpleFunction('header_bar_items', function($items) {
55 if(isset($items['button']))
56 unset($items['button']);
57 return $items;
58 }));
59
60 $twig->addFunction(new Twig_SimpleFunction('menu_items', function($options) {
61
62 if($options['theme_location_menu'])
63 $menu = get_term(get_nav_menu_locations()[$options['theme_location_menu']], 'nav_menu')->name;
64 elseif($options['menu_to_use'])
65 $menu = $options['menu_to_use'];
66 else
67 $menu = get_terms('nav_menu')[0]->slug;
68
69 return wp_get_nav_menu_items($menu);
70 }));
71
72 $twig->addFunction(new Twig_SimpleFunction('all_pages', function() {
73 return get_pages();
74 }));
75
76 $twig->addFunction(new Twig_SimpleFunction('font_icons', function($array) {
77 $new_array = [];
78 for($i=0; $i < count($array['id']); $i++):
79 $new_array[$i] = [
80 'id' => $array['id'][$i],
81 'icon' => $array['icon'][$i],
82 'type' => $array['type'][$i]
83 ];
84 endfor;
85 return $new_array;
86 }));
87
88 $twig->addGlobal('admin_url', get_admin_url());
89 $twig->addGlobal('shortcode', '[responsive_menu]');
90
91 $twig->addFunction(new Twig_SimpleFunction('get_available_themes', function() {
92 $theme_folder_path = wp_upload_dir()['basedir'] . '/responsive-menu-themes';
93 $theme_folders = glob($theme_folder_path . '/*' , GLOB_ONLYDIR);
94
95 $themes = [];
96 foreach($theme_folders as $theme_folder):
97 $config = json_decode(file_get_contents($theme_folder . '/config.json'), true);
98 $themes[basename($theme_folder)]['version'] = $config['version'];
99 $themes[basename($theme_folder)]['name'] = $config['name'];
100 endforeach;
101
102 return $themes;
103 }));
104
105 $twig->addGlobal('themes_folder_url', wp_upload_dir()['baseurl'] . '/responsive-menu-themes/');
106 $twig->addGlobal('themes_folder_dir', wp_upload_dir()['basedir'] . '/responsive-menu-themes/');
107
108 $twig->addFunction(new Twig_SimpleFunction('hide_pro_options', function() {
109 return get_option('hide_pro_options', 'no');
110 }));
111
112 $twig->addFunction(new Twig_SimpleFunction('nav_menus', function() {
113 $menus_array = [];
114 foreach(get_terms('nav_menu') as $menu)
115 $menus_array[$menu->slug] = $menu->name;
116
117 return $menus_array;
118 }));
119
120 $twig->addFunction(new Twig_SimpleFunction('location_menus', function() {
121 $location_menus = ['' => 'None'];
122 foreach(get_registered_nav_menus() as $location => $menu)
123 $location_menus[$location] = $menu;
124
125 return $location_menus;
126 }));
127
128 endif;
129
130 $twig->addFilter(new Twig_SimpleFilter('json_decode', function($string) {
131 return json_decode($string, true);
132 }));
133
134 return $twig;