PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 4.0.0
Responsive Menu – Create Mobile-Friendly Menu v4.0.0
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 4.0.0, at config/twig.php

143 lines 5.1 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 /** Check menu is exist or not */
27 $menu_arial_label = '';
28 foreach( get_terms('nav_menu') as $nav_menu ) {
29 if ( $nav_menu->slug === $menu ) {
30 $menu_arial_label = $menu;
31 break;
32 }
33 }
34
35 return wp_nav_menu(
36 [
37 'container' => '',
38 'menu_id' => 'responsive-menu',
39 'menu_class' => null,
40 'menu' => $menu && !$options['theme_location_menu'] ? $menu : null,
41 'depth' => $options['menu_depth'] ? $options['menu_depth'] : 0,
42 'theme_location' => $options['theme_location_menu'] ? $options['theme_location_menu'] : null,
43 'walker' => $walker,
44 'items_wrap' => '<ul id="%1$s" role="menubar" aria-label="'. $menu_arial_label .'" >%3$s</ul>',
45 'echo' => false
46 ]
47 );
48
49 }, ['needs_environment' => true]));
50
51 $twig->addGlobal('search_url', function_exists('icl_get_home_url') ? icl_get_home_url() : get_home_url());
52
53 else:
54
55 $twig->addFunction(new Twig_SimpleFunction('csrf', function() {
56 return wp_nonce_field('update', 'responsive-menu-nonce', true, false);
57 }));
58
59 $twig->addFunction(new Twig_SimpleFunction('current_page', function() {
60 return get_option('responsive_menu_current_page', 'initial-setup');
61 }));
62
63 $twig->addFunction(new Twig_SimpleFunction('header_bar_items', function($items) {
64 if(isset($items['button']))
65 unset($items['button']);
66 return $items;
67 }));
68
69 $twig->addFunction(new Twig_SimpleFunction('menu_items', function($options) {
70
71 if($options['theme_location_menu'])
72 $menu = get_term(get_nav_menu_locations()[$options['theme_location_menu']], 'nav_menu')->name;
73 elseif($options['menu_to_use'])
74 $menu = $options['menu_to_use'];
75 else
76 $menu = get_terms('nav_menu')[0]->slug;
77
78 return wp_get_nav_menu_items($menu);
79 }));
80
81 $twig->addFunction(new Twig_SimpleFunction('all_pages', function() {
82 return get_pages();
83 }));
84
85 $twig->addFunction(new Twig_SimpleFunction('font_icons', function($array) {
86 $new_array = [];
87 for($i=0; $i < count($array['id']); $i++):
88 $new_array[$i] = [
89 'id' => $array['id'][$i],
90 'icon' => $array['icon'][$i],
91 'type' => $array['type'][$i]
92 ];
93 endfor;
94 return $new_array;
95 }));
96
97 $twig->addGlobal('admin_url', get_admin_url());
98 $twig->addGlobal('shortcode', '[responsive_menu]');
99
100 $twig->addFunction(new Twig_SimpleFunction('get_available_themes', function() {
101 $theme_folder_path = wp_upload_dir()['basedir'] . '/responsive-menu-themes';
102 $theme_folders = glob($theme_folder_path . '/*' , GLOB_ONLYDIR);
103
104 $themes = [];
105 foreach($theme_folders as $theme_folder):
106 $config = json_decode(file_get_contents($theme_folder . '/config.json'), true);
107 $themes[basename($theme_folder)]['version'] = $config['version'];
108 $themes[basename($theme_folder)]['name'] = $config['name'];
109 endforeach;
110
111 return $themes;
112 }));
113
114 $twig->addGlobal('themes_folder_url', wp_upload_dir()['baseurl'] . '/responsive-menu-themes/');
115 $twig->addGlobal('themes_folder_dir', wp_upload_dir()['basedir'] . '/responsive-menu-themes/');
116
117 $twig->addFunction(new Twig_SimpleFunction('hide_pro_options', function() {
118 return get_option('hide_pro_options', 'no');
119 }));
120
121 $twig->addFunction(new Twig_SimpleFunction('nav_menus', function() {
122 $menus_array = [];
123 foreach(get_terms('nav_menu') as $menu)
124 $menus_array[$menu->slug] = $menu->name;
125
126 return $menus_array;
127 }));
128
129 $twig->addFunction(new Twig_SimpleFunction('location_menus', function() {
130 $location_menus = ['' => 'None'];
131 foreach(get_registered_nav_menus() as $location => $menu)
132 $location_menus[$location] = $menu;
133
134 return $location_menus;
135 }));
136
137 endif;
138
139 $twig->addFilter(new Twig_SimpleFilter('json_decode', function($string) {
140 return json_decode($string, true);
141 }));
142
143 return $twig;