PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.26
Responsive Menu – Create Mobile-Friendly Menu v3.1.26
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.26, at config/twig.php

133 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 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('csrf', function() {
46 return wp_nonce_field('update', 'responsive-menu-nonce', true, false);
47 }));
48
49 $twig->addFunction(new Twig_SimpleFunction('current_page', function() {
50 return get_option('responsive_menu_current_page', 'initial-setup');
51 }));
52
53 $twig->addFunction(new Twig_SimpleFunction('header_bar_items', function($items) {
54 if(isset($items['button']))
55 unset($items['button']);
56 return $items;
57 }));
58
59 $twig->addFunction(new Twig_SimpleFunction('menu_items', function($options) {
60
61 if($options['theme_location_menu'])
62 $menu = get_term(get_nav_menu_locations()[$options['theme_location_menu']], 'nav_menu')->name;
63 elseif($options['menu_to_use'])
64 $menu = $options['menu_to_use'];
65 else
66 $menu = get_terms('nav_menu')[0]->slug;
67
68 return wp_get_nav_menu_items($menu);
69 }));
70
71 $twig->addFunction(new Twig_SimpleFunction('all_pages', function() {
72 return get_pages();
73 }));
74
75 $twig->addFunction(new Twig_SimpleFunction('font_icons', function($array) {
76 $new_array = [];
77 for($i=0; $i < count($array['id']); $i++):
78 $new_array[$i] = [
79 'id' => $array['id'][$i],
80 'icon' => $array['icon'][$i],
81 'type' => $array['type'][$i]
82 ];
83 endfor;
84 return $new_array;
85 }));
86
87 $twig->addGlobal('admin_url', get_admin_url());
88 $twig->addGlobal('shortcode', '[responsive_menu]');
89
90 $twig->addFunction(new Twig_SimpleFunction('get_available_themes', function() {
91 $theme_folder_path = wp_upload_dir()['basedir'] . '/responsive-menu-themes';
92 $theme_folders = glob($theme_folder_path . '/*' , GLOB_ONLYDIR);
93
94 $themes = [];
95 foreach($theme_folders as $theme_folder):
96 $config = json_decode(file_get_contents($theme_folder . '/config.json'), true);
97 $themes[basename($theme_folder)]['version'] = $config['version'];
98 $themes[basename($theme_folder)]['name'] = $config['name'];
99 endforeach;
100
101 return $themes;
102 }));
103
104 $twig->addGlobal('themes_folder_url', wp_upload_dir()['baseurl'] . '/responsive-menu-themes/');
105 $twig->addGlobal('themes_folder_dir', wp_upload_dir()['basedir'] . '/responsive-menu-themes/');
106
107 $twig->addFunction(new Twig_SimpleFunction('hide_pro_options', function() {
108 return get_option('hide_pro_options', 'no');
109 }));
110
111 $twig->addFunction(new Twig_SimpleFunction('nav_menus', function() {
112 $menus_array = [];
113 foreach(get_terms('nav_menu') as $menu)
114 $menus_array[$menu->slug] = $menu->name;
115
116 return $menus_array;
117 }));
118
119 $twig->addFunction(new Twig_SimpleFunction('location_menus', function() {
120 $location_menus = ['' => 'None'];
121 foreach(get_registered_nav_menus() as $location => $menu)
122 $location_menus[$location] = $menu;
123
124 return $location_menus;
125 }));
126
127 endif;
128
129 $twig->addFilter(new Twig_SimpleFilter('json_decode', function($string) {
130 return json_decode($string, true);
131 }));
132
133 return $twig;