PluginProbe
QuadMenu – Mega Menu / 2.0.6
QuadMenu – Mega Menu v2.0.6
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / includes / themes.php

themes.php in QuadMenu – Mega Menu 2.0.6, at includes/themes.php

197 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 die('-1');
5 }
6
7 class Quadmenu_Themes {
8
9 public function __construct() {
10
11 $this->themes();
12
13 add_filter('quadmenu_developer_options', array($this, 'options'));
14
15 add_action('wp_ajax_quadmenu_add_theme', array($this, 'ajax_theme_create'));
16
17 add_action('wp_ajax_quadmenu_delete_theme', array($this, 'ajax_theme_delete'));
18
19 add_action('redux/options/' . QUADMENU_DB_OPTIONS . '/import', array($this, 'import'), 10, 2);
20
21 add_action('redux/options/' . QUADMENU_DB_OPTIONS . '/settings/change', array($this, 'title'), 10, 2);
22
23 //add_action('redux/' . QUADMENU_DB_OPTIONS . '/localize/reset', array($this, 'message'));
24 add_action('wp_ajax_' . QUADMENU_DB_OPTIONS . '_ajax_save', array($this, 'themes_delete'));
25 }
26
27 public function themes() {
28
29 global $quadmenu_themes;
30
31 $defaults = array(
32 'default_theme' => esc_html('Default Theme', 'quadmenu')
33 );
34
35 $custom = (array) get_option(QUADMENU_DB_THEMES, array());
36
37 $quadmenu_themes = apply_filters('quadmenu_default_themes', wp_parse_args($custom, $defaults));
38 }
39
40 public function options($options) {
41
42 global $quadmenu_themes;
43
44 if ($saved_themes = get_option(QUADMENU_DB_THEMES, array())) {
45 $options['quadmenu_themes'] = $saved_themes;
46 }
47
48 $options['themes'] = $this->less_themes($quadmenu_themes);
49
50 return $options;
51 }
52
53 static function less_themes($quadmenu_themes) {
54
55 $themes = array();
56
57 if (is_array($quadmenu_themes) && count($quadmenu_themes)) {
58
59 foreach ($quadmenu_themes as $key => $theme) {
60
61 $themes[] = '~"' . $key . '"';
62 }
63
64 return implode(',', array_reverse($themes));
65 }
66
67 return '~"' . $quadmenu_themes . '"';
68 }
69
70 public function import($plugin_options = null, $imported_options = null) {
71
72 if (!empty($imported_options['quadmenu_themes'])) {
73 update_option(QUADMENU_DB_THEMES, $imported_options['quadmenu_themes']);
74 }
75 }
76
77 public function ajax_theme_create() {
78
79 if (!check_ajax_referer('quadmenu', 'nonce', false)) {
80 QuadMenu::send_json_error(esc_html__('Please reload page.', 'quadmenu'));
81 }
82
83 do_action('quadmenu_delete_theme');
84
85 $saved_themes = get_option(QUADMENU_DB_THEMES, array());
86
87 $next_id = count($saved_themes) + 1;
88
89 $next_key = 'custom_theme_' . $next_id;
90
91 $saved_themes[$next_key] = sprintf(esc_html__('Custom Theme %s', 'quadmenu'), $next_id);
92
93 if (update_option(QUADMENU_DB_THEMES, $saved_themes)) {
94
95 Quadmenu_Compiler::do_compiler(true);
96
97 QuadMenu_Redux::add_notification('blue', sprintf(esc_html__('New theme created. Your options panel will be reloaded to include their options. %s.', 'quadmenu'), esc_html__('Please wait', 'quadmenu')));
98
99 QuadMenu::send_json_success(QuadMenu::taburl('quadmenu_theme_' . $next_key));
100 } else {
101 QuadMenu::send_json_error(esc_html__('Can\'t create theme.', 'quadmenu'));
102 }
103
104 wp_die();
105 }
106
107 public function ajax_theme_delete() {
108
109 if (!check_ajax_referer('quadmenu', 'nonce', false)) {
110 QuadMenu::send_json_error(esc_html__('Please reload page.', 'quadmenu'));
111 }
112
113 do_action('quadmenu_delete_theme');
114
115 global $quadmenu_themes;
116
117 if (!empty($_REQUEST['current_theme'])) {
118
119 $key = sanitize_text_field($_REQUEST['current_theme']);
120
121 $saved_themes = get_option(QUADMENU_DB_THEMES, array());
122
123 unset($saved_themes[$key]);
124
125 $prev_key = reset(array_keys($quadmenu_themes));
126
127 if (update_option(QUADMENU_DB_THEMES, $saved_themes)) {
128
129 Quadmenu_Compiler::do_compiler(true);
130
131 QuadMenu_Redux::add_notification('blue', sprintf(esc_html__('Theme deleted. Your options panel will be reloaded to remove their options. %s.', 'quadmenu'), esc_html__('Please wait', 'quadmenu')));
132
133 QuadMenu::send_json_success(QuadMenu::taburl('quadmenu_theme_' . $prev_key));
134 } else {
135 QuadMenu::send_json_error(esc_html__('Can\'t delete theme.', 'quadmenu'));
136 }
137 }
138
139 wp_die();
140 }
141
142 function themes_delete() {
143
144 if (!empty($_REQUEST['data']) && wp_verify_nonce($_REQUEST['nonce'], 'redux_ajax_nonce' . QUADMENU_DB_OPTIONS)) {
145
146 $redux = ReduxFrameworkInstances::get_instance(QUADMENU_DB_OPTIONS);
147
148 $values = array();
149
150 $_REQUEST['data'] = stripslashes($_REQUEST['data']);
151
152 $values = $redux->redux_parse_str($_REQUEST['data']);
153 //$values = Redux_Functions_Ex::parse_str( $_REQUEST['data'] );
154
155 $values = $values[QUADMENU_DB_OPTIONS];
156
157 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
158 $values = array_map('stripslashes_deep', $values);
159 }
160
161 if (!empty($values['defaults'])) {
162
163 delete_option(QUADMENU_DB_THEMES);
164 }
165 }
166 }
167
168 function title($options = false, $changed = false) {
169
170 $update = false;
171
172 if ($saved_themes = get_option(QUADMENU_DB_THEMES, array())) {
173
174 foreach ($saved_themes as $key => $name) {
175
176 if (!empty($options[$key . '_theme_title']) && $options[$key . '_theme_title'] != $name) {
177
178 $update = true;
179
180 $saved_themes[$key] = $options[$key . '_theme_title'];
181 }
182 }
183
184 if ($update && update_option(QUADMENU_DB_THEMES, $saved_themes)) {
185 QuadMenu_Redux::add_notification('blue', esc_html__('Theme name changed.', 'quadmenu'));
186 }
187 }
188 }
189
190 function message() {
191 return esc_html__('Are you sure? Resetting will lose all custom values and themes.', 'quadmenu');
192 }
193
194 }
195
196 new Quadmenu_Themes();
197