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

145 lines 5.2 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 $menu = '';
72 if( $options['theme_location_menu'] ) {
73 $menu = get_term(get_nav_menu_locations()[$options['theme_location_menu']], 'nav_menu')->name;
74 } elseif( $options['menu_to_use'] ) {
75 $menu = $options['menu_to_use'];
76 } elseif( ! empty( get_terms('nav_menu')[0]->slug ) ) {
77 $menu = get_terms('nav_menu')[0]->slug;
78 }
79
80 return wp_get_nav_menu_items($menu);
81 }));
82
83 $twig->addFunction(new Twig_SimpleFunction('all_pages', function() {
84 return get_pages();
85 }));
86
87 $twig->addFunction(new Twig_SimpleFunction('font_icons', function($array) {
88 $new_array = [];
89 for($i=0; $i < count($array['id']); $i++):
90 $new_array[$i] = [
91 'id' => $array['id'][$i],
92 'icon' => $array['icon'][$i],
93 'type' => $array['type'][$i]
94 ];
95 endfor;
96 return $new_array;
97 }));
98
99 $twig->addGlobal('admin_url', get_admin_url());
100 $twig->addGlobal('shortcode', '[responsive_menu]');
101
102 $twig->addFunction(new Twig_SimpleFunction('get_available_themes', function() {
103 $theme_folder_path = wp_upload_dir()['basedir'] . '/responsive-menu-themes';
104 $theme_folders = glob($theme_folder_path . '/*' , GLOB_ONLYDIR);
105
106 $themes = [];
107 foreach($theme_folders as $theme_folder):
108 $config = json_decode(file_get_contents($theme_folder . '/config.json'), true);
109 $themes[basename($theme_folder)]['version'] = $config['version'];
110 $themes[basename($theme_folder)]['name'] = $config['name'];
111 endforeach;
112
113 return $themes;
114 }));
115
116 $twig->addGlobal('themes_folder_url', wp_upload_dir()['baseurl'] . '/responsive-menu-themes/');
117 $twig->addGlobal('themes_folder_dir', wp_upload_dir()['basedir'] . '/responsive-menu-themes/');
118
119 $twig->addFunction(new Twig_SimpleFunction('hide_pro_options', function() {
120 return get_option('hide_pro_options', 'no');
121 }));
122
123 $twig->addFunction(new Twig_SimpleFunction('nav_menus', function() {
124 $menus_array = [];
125 foreach(get_terms('nav_menu') as $menu)
126 $menus_array[$menu->slug] = $menu->name;
127
128 return $menus_array;
129 }));
130
131 $twig->addFunction(new Twig_SimpleFunction('location_menus', function() {
132 $location_menus = ['' => 'None'];
133 foreach(get_registered_nav_menus() as $location => $menu)
134 $location_menus[$location] = $menu;
135
136 return $location_menus;
137 }));
138
139 endif;
140
141 $twig->addFilter(new Twig_SimpleFilter('json_decode', function($string) {
142 return json_decode($string, true);
143 }));
144
145 return $twig;