page.php
10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // disable direct access
}
if ( ! class_exists( 'Mega_Menu_Page' ) ) :
/**
* Handles all admin related functionality.
*/
class Mega_Menu_Page {
/**
* Constructor
*
* @since 1.0
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'megamenu_settings_page' ) );
add_action( 'megamenu_admin_scripts', array( $this, 'enqueue_scripts' ) );
}
/**
* Adds the "Menu Themes" menu item and page.
*
* @since 1.0
*/
public function megamenu_settings_page() {
$svg = 'PHN2ZyB2ZXJzaW9uPSIxLjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEyNy4wMDAwMDBwdCIgaGVpZ2h0PSIxMjcuMDAwMDAwcHQiIHZpZXdCb3g9IjAgMCAxMjcuMDAwMD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cyIDE0MSAxMiAwIDE0IC0zOCAxNCAtMjI4CiAgICAgICAgICAgICAgICAgICAgICAgIGwwIC0yMjggLTc3IC00NyAtNzggLTQ3IC03IDE0NiBjLTMgODAgLTggMTQ3IC0xMCAxNDkgLTIgMiAtNTMgLTI1IC0xMTMgLTYwCiAgICAgICAgICAgICAgICAgICAgICAgIC02MSAtMzUgLTExOSAtNjQgLTEyOSAtNjUgLTExIDAgLTcwIDI3IC0xMzIgNjAgLTYyIDMzIC0xMTUgNjAgLTExNyA2MCAtMyAwCiAgICAgICAgICAgICAgICAgICAgICAgIC04IC02MyAtMTIgLTE0MCAtNCAtNzcgLTExIC0xNDAgLTE2IC0xNDAgLTQgMCAtMzkgMTkgLTc4IDQyIGwtNzAgNDIgLTMgMTI2CiAgICAgICAgICAgICAgICAgICAgICAgIGMtNCAxODIgMSAzNDAgMTIgMzQwIDUgMCA4MSAtNDAgMTY5IC04OXogbTE5NSAtNDU4IGw1NSAtMjcgNDEgMjggYzIzIDE1IDQ4CiAgICAgICAgICAgICAgICAgICAgICAgIDI1IDU2IDIyIDE1IC02IDIwIC03OSA4IC0xMTEgLTcgLTE4IC05NCAtNjUgLTEyMSAtNjUgLTIyIDAgLTgzIDM1IC0xMDAgNTgKICAgICAgICAgICAgICAgICAgICAgICAgLTE4IDIyIC0xNSAxMjIgMyAxMjIgMiAwIDI4IC0xMiA1OCAtMjd6Ii8+CiAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgPC9zdmc+';
$icon = 'data:image/svg+xml;base64,' . $svg;
$capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' );
$page = add_menu_page( __( 'Max Mega Menu', 'megamenu' ), __( 'Mega Menu', 'megamenu' ), $capability, 'maxmegamenu', array( $this, 'page' ), $icon );
$tabs = apply_filters( 'megamenu_menu_tabs', array() );
foreach ( $tabs as $key => $title ) {
if ( $key == 'menu_locations' ) {
add_submenu_page( 'maxmegamenu', __( 'Max Mega Menu', 'megamenu' ) . ' - ' . $title, $title, $capability, 'maxmegamenu', array( $this, 'page' ) );
} else {
add_submenu_page( 'maxmegamenu', __( 'Max Mega Menu', 'megamenu' ) . ' - ' . $title, $title, $capability, 'maxmegamenu_' . $key, array( $this, 'page' ) );
}
}
}
/**
* Main settings page wrapper.
*
* @since 1.4
*/
public function page() {
$tab = isset( $_GET['page'] ) ? substr( $_GET['page'], 12 ) : false;
// backwards compatibility
if ( isset( $_GET['tab'] ) ) {
$tab = $_GET['tab'];
}
if ( ! $tab ) {
$tab = 'menu_locations';
}
$header_links = apply_filters(
'megamenu_header_links',
array(
'homepage' => array(
'url' => 'https://www.megamenu.com/?utm_source=free&utm_medium=settings&utm_campaign=pro',
'target' => '_mmmpro',
'text' => __( 'Homepage', 'megamenu' ),
'class' => '',
),
'documentation' => array(
'url' => 'https://www.megamenu.com/documentation/installation/?utm_source=free&utm_medium=settings&utm_campaign=pro',
'text' => __( 'Documentation', 'megamenu' ),
'target' => '_mmmpro',
'class' => '',
),
'troubleshooting' => array(
'url' => 'https://www.megamenu.com/articles/troubleshooting/?utm_source=free&utm_medium=settings&utm_campaign=pro',
'text' => __( 'Troubleshooting', 'megamenu' ),
'target' => '_mmmpro',
'class' => '',
),
)
);
if ( ! is_plugin_active( 'megamenu-pro/megamenu-pro.php' ) ) {
$header_links['pro'] = array(
'url' => 'https://www.megamenu.com/upgrade/?utm_source=free&utm_medium=settings&utm_campaign=pro',
'target' => '_mmmpro',
'text' => __( 'Upgrade to Pro', 'megamenu' ),
'class' => 'mega-highlight',
);
}
$versions = apply_filters(
'megamenu_versions',
array(
'core' => array(
'version' => MEGAMENU_VERSION,
'text' => __( 'Core version', 'megamenu' ),
),
'pro' => array(
'version' => "<a href='https://www.megamenu.com/upgrade/?utm_source=free&utm_medium=settings&utm_campaign=pro' target='_mmmpro'>not installed</a>",
'text' => __( 'Pro extension', 'megamenu' ),
),
)
);
?>
<div class='megamenu_outer_wrap'>
<div class='megamenu_header_top'>
<ul>
<?php
foreach ( $header_links as $id => $data ) {
echo "<li class='{$data['class']}'><a href='{$data['url']}' target='{$data['target']}'>{$data['text']}";
echo '</a>';
echo '</li>';
}
?>
</ul>
</div>
<div class='megamenu_header'>
<div class='megamenu_header_left'>
<h2><?php _e( 'Max Mega Menu', 'megamenu' ); ?></h2>
<div class='version'>
<?php
$total = count( $versions );
$count = 0;
$separator = ' - ';
foreach ( $versions as $id => $data ) {
echo $data['text'] . ': <b>' . $data['version'] . '</b>';
$count = $count + 1;
if ( $total > 0 && $count != $total ) {
echo $separator;
}
}
?>
</div>
</div>
<?php
if ( isset( $_GET['debug'] ) ) {
echo "<textarea style='width: 100%; height: 400px;'>";
var_dump( get_option("megamenu_settings") );
echo "</textarea>";
}
?>
</div>
<div class='megamenu_wrap'>
<div class='megamenu_left'>
<ul class='mega-page-navigation'>
<?php
$tabs = apply_filters( 'megamenu_menu_tabs', array() );
foreach ( $tabs as $key => $title ) {
$class = $tab == $key ? 'active' : '';
if ( $key == 'menu_locations' ) {
$args = array( 'page' => 'maxmegamenu' );
} else {
$args = array( 'page' => 'maxmegamenu_' . $key );
}
$url = esc_url( add_query_arg( $args, admin_url( 'admin.php' ) ) );
echo "<li class='{$key}'><a class='{$class}' href='{$url}'>{$title}</a></li>";
}
?>
</ul>
</div>
<div class='megamenu_right'>
<?php $this->print_messages(); ?>
<?php
$saved_settings = get_option( 'megamenu_settings' );
if ( has_action( "megamenu_page_{$tab}" ) ) {
do_action( "megamenu_page_{$tab}", $saved_settings );
} else {
do_action( 'megamenu_page_menu_locations', $saved_settings );
}
?>
</div>
</div>
</div>
<?php
}
/**
* Redirect and exit
*
* @since 1.8
*/
public function redirect( $url ) {
wp_redirect( $url );
exit;
}
/**
* Display messages to the user
*
* @since 1.0
*/
public function print_messages() {
if ( is_plugin_active( 'clearfy/clearfy.php' ) ) {
if ( $clearfy_options = get_option( 'wbcr_clearfy_cache_options' ) ) {
if ( $clearfy_options['disable_dashicons'] == true ) {
echo "<p class='fail'>" . __( 'Please enable Dashicons in the Clearfy plugin options. Max Mega Menu requires Dashicons.', 'megamenu' ) . '</p>';
}
}
}
do_action( 'megamenu_print_messages' );
}
/**
* Enqueue admin scripts
*
* @since 1.8.3
*/
public function enqueue_scripts( $hook ) {
wp_deregister_style( 'select2' );
wp_deregister_script( 'select2' );
wp_enqueue_style( 'select2', MEGAMENU_BASE_URL . 'js/select2/select2.css', false, MEGAMENU_VERSION );
wp_enqueue_script( 'mega-menu-select2', MEGAMENU_BASE_URL . 'js/select2/select2.min.js', array(), MEGAMENU_VERSION );
wp_enqueue_style( 'mega-menu-settings', MEGAMENU_BASE_URL . 'css/admin/admin.css', false, MEGAMENU_VERSION );
wp_enqueue_style( 'spectrum', MEGAMENU_BASE_URL . 'js/spectrum/spectrum.css', false, "1.8.1" );
wp_enqueue_script( 'spectrum', MEGAMENU_BASE_URL . 'js/spectrum/spectrum.js', array( 'jquery' ), "1.8.1" );
wp_localize_script(
'spectrum',
'megamenu_spectrum_settings',
apply_filters( 'megamenu_spectrum_localisation', array() )
);
wp_enqueue_script( 'mega-menu-theme-editor', MEGAMENU_BASE_URL . 'js/settings.js', array( 'jquery', 'spectrum', 'code-editor' ), MEGAMENU_VERSION );
wp_localize_script(
'mega-menu-theme-editor',
'megamenu_settings',
array(
'saving' => __( 'Saving', 'megamenu' ),
'confirm' => __( 'Are you sure?', 'megamenu' ),
'theme_save_error' => __( 'Error saving theme.', 'megamenu' ),
'theme_save_error_refresh' => __( 'Please try refreshing the page.', 'megamenu' ),
'theme_save_error_exhausted' => __( 'The server ran out of memory whilst trying to regenerate the menu CSS.', 'megamenu' ),
'theme_save_error_memory_limit' => __( 'Try disabling unusued plugins to increase the available memory. Alternatively, for details on how to increase your server memory limit see:', 'megamenu' ),
'theme_save_error_500' => __( 'The server returned a 500 error. The server did not provide an error message (you should find details of the error in your server error log), but this is usually due to your server memory limit being reached.', 'megamenu' ),
'increase_memory_limit_url' => 'http://www.wpbeginner.com/wp-tutorials/fix-wordpress-memory-exhausted-error-increase-php-memory/',
'increase_memory_limit_anchor_text' => 'How to increase the WordPress memory limit',
)
);
if ( function_exists( 'wp_enqueue_code_editor' ) ) {
wp_deregister_style( 'codemirror' );
wp_deregister_script( 'codemirror' );
$cm_settings['codeEditor'] = wp_enqueue_code_editor( array( 'type' => 'text/x-scss' ) );
wp_localize_script( 'mega-menu-theme-editor', 'cm_settings', $cm_settings );
wp_enqueue_style( 'wp-codemirror' );
}
}
}
endif;