general.php
5.44 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
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // disable direct access.
}
if ( ! class_exists( 'Mega_Menu_General' ) ) :
/**
* Handles the Mega Menu > Menu Settings page
*/
class Mega_Menu_General {
/**
* Constructor
*
* @since 1.0
*/
public function __construct() {
add_action( 'admin_post_megamenu_save_settings', array( $this, 'save_settings' ) );
add_filter( 'megamenu_menu_tabs', array( $this, 'add_general_tab' ), 4 );
add_action( 'megamenu_page_general_settings', array( $this, 'general_settings_page' ) );
}
/**
* Add the Menu Locations tab to our available tabs
*
* @param array $tabs
* @since 2.8
*/
public function add_general_tab( $tabs ) {
$tabs['general_settings'] = __( 'General Settings', 'megamenu' );
return $tabs;
}
/**
* Sanitize multidimensional array
*
* @since 2.7.5
*/
public function sanitize_array( &$array ) {
foreach ( $array as &$value ) {
if ( ! is_array( $value ) ) {
$value = sanitize_textarea_field( $value );
} else {
$this->sanitize_array( $value );
}
}
return $array;
}
/**
* Save menu general settings.
*
* @since 1.0
*/
public function save_settings() {
check_admin_referer( 'megamenu_save_settings' );
if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
$settings = $this->sanitize_array( $_POST['settings'] );
$submitted_settings = apply_filters( 'megamenu_submitted_settings', $settings );
$existing_settings = get_option( 'megamenu_settings' );
$new_settings = array_merge( (array) $existing_settings, $submitted_settings );
update_option( 'megamenu_settings', $new_settings );
}
delete_transient( 'megamenu_failed_to_write_css_to_filesystem' );
do_action( 'megamenu_after_save_general_settings' );
do_action( 'megamenu_delete_cache' );
$url = isset( $_POST['_wp_http_referer'] ) ? $_POST['_wp_http_referer'] : admin_url( 'admin.php?page=maxmegamenu&saved=true' );
$this->redirect( $url );
}
/**
* Redirect and exit
*
* @since 1.8
*/
public function redirect( $url ) {
wp_redirect( $url );
exit;
}
/**
* Content for 'Settings' tab
*
* @since 1.4
*/
public function general_settings_page( $saved_settings ) {
$css = isset( $saved_settings['css'] ) ? $saved_settings['css'] : 'fs';
$js = isset( $saved_settings['js'] ) ? $saved_settings['js'] : 'footer';
$locations = get_registered_nav_menus();
?>
<div class='menu_settings menu_settings_general_settings'>
<form action="<?php echo esc_attr( admin_url( 'admin-post.php' ) ); ?>" method="post">
<input type="hidden" name="action" value="megamenu_save_settings" />
<?php wp_nonce_field( 'megamenu_save_settings' ); ?>
<h3 class='first'><?php esc_html_e( 'General Settings', 'megamenu' ); ?></h3>
<table>
<tr>
<td class='mega-name'>
<?php esc_html_e( 'CSS Output', 'megamenu' ); ?>
<div class='mega-description'>
</div>
</td>
<td class='mega-value'>
<select name='settings[css]' id='mega_css'>
<option value='fs' <?php echo selected( 'fs' === $css ); ?>><?php esc_html_e( 'Save to filesystem', 'megamenu' ); ?>
<?php
if ( get_transient( 'megamenu_failed_to_write_css_to_filesystem' ) ) {
echo ' ' . esc_html( '(Action required: Check upload folder permissions)', 'megamenu' );
}
?>
</option>
<option value='head' <?php echo selected( 'head' === $css ); ?>><?php esc_html_e( 'Output in <head>', 'megamenu' ); ?></option>
<option value='disabled' <?php echo selected( 'disabled' === $css ); ?>><?php esc_html_e( "Don't output CSS", 'megamenu' ); ?></option>
<select>
<div class='mega-description'>
<div class='fs' style='display: <?php echo 'fs' === $css ? 'block' : 'none'; ?>'><?php esc_html_e( 'CSS will be saved to wp-content/uploads/maxmegamenu/style.css and enqueued from there.', 'megamenu' ); ?></div>
<div class='head' style='display: <?php echo 'head' === $css ? 'block' : 'none'; ?>'><?php esc_html_e( 'CSS will be loaded from the cache in a <style> tag in the <head> of the page.', 'megamenu' ); ?></div>
<div class='disabled' style='display: <?php echo 'disabled' === $css ? 'block' : 'none'; ?>'>
<?php esc_html_e( 'CSS will not be output, you must enqueue the CSS for the menu manually.', 'megamenu' ); ?>
<div class='fail'><?php esc_html_e( 'Selecting this option will effectively disable the theme editor and many of the features available in Max Mega Menu and Max Mega Menu Pro. Only enable this option if you fully understand the consequences.', 'megamenu' ); ?>
</div>
</div>
</td>
</tr>
<!--tr>
<td class='mega-name'>
<?php esc_html_e( 'JavaScript Output', 'megamenu' ); ?>
<div class='mega-description'>
</div>
</td>
<td class='mega-value'>
<select name='settings[js]' id='mega_css'>
<option value='footer' <?php echo selected( 'footer' === $js ); ?>><?php esc_html_e( 'Footer (default)', 'megamenu' ); ?></option>
<option value='head' <?php echo selected( 'head' === $js ); ?>><?php esc_html_e( 'Output in <head>', 'megamenu' ); ?></option>
<select>
</td>
</tr-->
</table>
<?php do_action( 'megamenu_general_settings', $saved_settings ); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
}
endif;