PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.1
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
← All changes | adminimize.php +455 -518 1.11.8 → 1.9.1 View file →
@@ -6,17 +6,15 @@
6 6 * Domain Path: /languages
7 7 * Description: Visually compresses the administrative meta-boxes so that more admin page content can be initially seen. The plugin that lets you hide 'unnecessary' items from the WordPress administration menu, for all roles of your install. You can also hide post meta controls on the edit-area to simplify the interface. It is possible to simplify the admin in different for all roles.
8 8 * Author: Frank Bültge
9 9 * Author URI: http://bueltge.de/
10 - * Version: 1.11.8
10 + * Version: 1.9.1
11 11 * License: GPLv2+
12 12 *
13 - * Php Version 5.6
14 - *
15 13 * @package WordPress
16 14 * @author Frank Bültge <[email protected]>
17 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 - * @version 2022-07-19
16 + * @version 2016-01-25
19 17 */
20 18
21 19 /**
22 20 * The stylesheet and the initial idea is from Eric A. Meyer http://meyerweb.com/
@@ -23,9 +21,8 @@
23 21 * I have written a plugin with many options on the basis idea
24 22 * of differently user-right and a user-friendly range in admin-area via reduce areas.
25 23 * :( grmpf i have so much wishes and hints form users, there use the plugin and
26 24 * it is not easy to development this on my free time.
27 - * Also I hate the source, old and hard to maintain, no OOP.
28 25 */
29 26
30 27 if ( ! function_exists( 'add_action' ) ) {
31 28 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
@@ -33,17 +30,10 @@
33 30 }
34 31
35 32 // plugin definitions
36 33 define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
37 -define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( __DIR__ ) );
34 +define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
38 35
39 -/**
40 - * Return data from the plugin.
41 - *
42 - * @param string $value
43 - *
44 - * @return mixed
45 - */
46 36 function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
47 37
48 38 if ( ! function_exists( 'get_plugin_data' ) ) {
49 39 require_once ABSPATH . '/wp-admin/includes/plugin.php';
@@ -48,11 +38,12 @@
48 38 if ( ! function_exists( 'get_plugin_data' ) ) {
49 39 require_once ABSPATH . '/wp-admin/includes/plugin.php';
50 40 }
51 41
52 - $plugin_data = get_plugin_data( __FILE__ );
42 + $plugin_data = get_plugin_data( __FILE__ );
43 + $plugin_value = $plugin_data[ $value ];
53 44
54 - return $plugin_data[ $value ];
45 + return $plugin_value;
55 46 }
56 47
57 48 /**
58 49 * Load language files.
@@ -94,31 +85,21 @@
94 85 * @return bool
95 86 */
96 87 function _mw_adminimize_exclude_settings_page() {
97 88
98 - if ( ! is_admin() ) {
99 - return false;
89 + if ( ! function_exists( 'get_current_screen' ) ) {
90 + return TRUE;
100 91 }
101 92
102 - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
103 - return false;
104 - }
93 + // Get admin page
94 + $screen = get_current_screen();
105 95
106 - $page = '';
107 - if ( isset( $_GET['page'] ) ) {
108 - $page = esc_attr( $_GET['page'] );
96 + // Don't filter on settings page
97 + if ( isset( $screen->id ) && FALSE !== strpos( $screen->id, 'adminimize' ) ) {
98 + return TRUE;
109 99 }
110 100
111 - if ( function_exists( 'get_current_screen' ) ) {
112 - $screen_tmp = get_current_screen();
113 -
114 - if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
115 - $page = $screen_tmp->id;
116 - }
117 - }
118 -
119 - // Don't filter on settings page
120 - return FALSE !== strpos( $page, 'adminimize' );
101 + return FALSE;
121 102 }
122 103
123 104 /**
124 105 * Get status, if the plugin active network wide.
@@ -127,23 +108,12 @@
127 108 */
128 109 function _mw_adminimize_is_active_on_multisite() {
129 110
130 111 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
131 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
112 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
132 113 }
133 114
134 - /**
135 - * Allow different adminimize options per site on multisite.
136 - *
137 - * @since 1.11.6
138 - *
139 - * @param bool
140 - */
141 - $force_single_site_usage = apply_filters( 'adminimize_mu_force_options_per_site', false );
142 -
143 - if ( is_multisite()
144 - && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME )
145 - && ! $force_single_site_usage ) {
115 + if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
146 116 return TRUE;
147 117 }
148 118
149 119 return FALSE;
@@ -157,36 +127,27 @@
157 127 * @return array $user_roles
158 128 */
159 129 function _mw_adminimize_get_all_user_roles() {
160 130
161 - /** @var $wp_roles WP_Roles */
162 131 global $wp_roles;
163 132
164 133 $user_roles = array();
165 134
166 - if ( null !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
135 + if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
136 + /** @var array $wp_roles */
167 137 foreach ( $wp_roles->roles as $role => $data ) {
168 138 $user_roles[] = $role;
169 - // The $data var contains caps, maybe for later use.
139 + //$data contains caps, maybe for later use..
170 140 }
171 141 }
172 142
173 143 // Exclude the new bbPress roles.
174 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
175 - $user_roles = array_diff(
176 - $user_roles,
177 - array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
178 - );
179 - }
144 + $user_roles = array_diff(
145 + $user_roles,
146 + array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
147 + );
180 148
181 - /**
182 - * Use this filter to add or remove a role in Adminimize options.
183 - *
184 - * @since 1.11.6
185 - *
186 - * @param array
187 - */
188 - return apply_filters( 'adminimize_user_roles_filter', $user_roles );
149 + return $user_roles;
189 150 }
190 151
191 152 /**
192 153 * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
@@ -196,68 +157,56 @@
196 157 * @return array $user_roles_names
197 158 */
198 159 function _mw_adminimize_get_all_user_roles_names() {
199 160
200 - /** @var $wp_roles WP_Roles */
201 161 global $wp_roles;
162 +
202 163 $user_roles_names = array();
203 164
165 + /** @var array $wp_roles */
204 166 foreach ( $wp_roles->role_names as $role_name => $data ) {
167 + if ( function_exists( 'translate_user_role' ) ) {
168 + $data = translate_user_role( $data );
169 + } else {
170 + $data = esc_attr_x( $data, 'Translate each user role.' );
171 + }
205 172
206 - $data = translate_user_role( $data );
207 173 $user_roles_names[] = $data;
208 174 }
209 175
210 176 // exclude the new bbPress roles
211 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
212 - $user_roles_names = array_diff(
213 - $user_roles_names,
214 - array(
215 - esc_attr__( 'Keymaster', 'bbpress' ),
216 - esc_attr__( 'Moderator', 'bbpress' ),
217 - esc_attr__( 'Participant', 'bbpress' ),
218 - esc_attr__( 'Spectator', 'bbpress' ),
219 - esc_attr__( 'Blocked', 'bbpress' ),
220 - )
221 - );
222 - }
177 + $user_roles_names = array_diff(
178 + $user_roles_names,
179 + array(
180 + esc_attr__( 'Keymaster', 'bbpress' ),
181 + esc_attr__( 'Moderator', 'bbpress' ),
182 + esc_attr__( 'Participant', 'bbpress' ),
183 + esc_attr__( 'Spectator', 'bbpress' ),
184 + esc_attr__( 'Blocked', 'bbpress' ),
185 + )
186 + );
223 187
224 - /**
225 - * Use this filter to add or remove a role-name in Adminimize options.
226 - *
227 - * @since 1.11.6
228 - *
229 - * @param array
230 - */
231 - return apply_filters( 'adminimize_user_roles_names_filter', $user_roles_names );
188 + return $user_roles_names;
232 189 }
233 190
234 191 /**
235 - * Get post type.
236 - *
237 - * @return null|string String of the post type.
192 + * return post type
238 193 */
239 -function _mw_adminimize_get_current_post_type() {
194 +function _mw_get_current_post_type() {
240 195
241 196 global $post, $typenow, $current_screen;
242 197
243 - // We have a post so we can just get the post type from that.
198 + //we have a post so we can just get the post type from that
244 199 if ( $post && $post->post_type ) {
245 200 return $post->post_type;
246 - }
247 -
248 - // Check the global $typenow - set in admin.php
249 - if ( $typenow ) {
201 + } //check the global $typenow - set in admin.php
202 + else if ( $typenow ) {
250 203 return $typenow;
251 - }
252 -
253 - // Check the global $current_screen object - set in screen.php
254 - if ( $current_screen && $current_screen->post_type ) {
204 + } // check the global $current_screen object - set in sceen.php
205 + else if ( $current_screen && $current_screen->post_type ) {
255 206 return $current_screen->post_type;
256 - }
257 -
258 - // lastly check the post_type querystring
259 - if ( isset( $_REQUEST['post_type'] ) ) {
207 + } // lastly check the post_type querystring
208 + else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
260 209 return sanitize_key( $_REQUEST[ 'post_type' ] );
261 210 }
262 211
263 212 // we do not know the post type!
@@ -270,13 +219,14 @@
270 219 function _mw_adminimize_admin_init() {
271 220
272 221 global $pagenow, $post_type, $menu, $submenu;
273 222
274 - $post_id = 0;
275 223 if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
276 224 $post_id = (int) esc_attr( $_GET[ 'post' ] );
277 225 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
278 226 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
227 + } else {
228 + $post_id = 0;
279 229 }
280 230
281 231 $current_post_type = $post_type;
282 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
@@ -282,22 +232,16 @@
282 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
283 233 $current_post_type = get_post_type( $post_id );
284 234 }
285 235 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
286 - $current_post_type = _mw_adminimize_get_current_post_type();
236 + $current_post_type = _mw_get_current_post_type();
287 237 }
288 - if ( ! $current_post_type ) { // set hard to post
238 + if ( ! $current_post_type ) // set hard to post
239 + {
289 240 $current_post_type = 'post';
290 241 }
291 242
292 - // Debug helper
293 - if ( class_exists( 'DebugListener' ) ) {
294 - $listener = new DebugListener();
295 - add_action( 'adminimize.log', [$listener, 'listen'], 10, 2 );
296 - add_action( 'wp_footer', array( $listener, 'dump' ), PHP_INT_MAX );
297 - }
298 -
299 - // Get all user roles.
243 + // Get all user rolles.
300 244 $user_roles = _mw_adminimize_get_all_user_roles();
301 245
302 246 // Get settings.
303 247 $adminimizeoptions = _mw_adminimize_get_option_value();
@@ -321,9 +265,9 @@
321 265 // widget pages
322 266 $widget_pages = array( 'widgets.php' );
323 267
324 268 foreach ( $user_roles as $role ) {
325 - $disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
269 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
326 270 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
327 271 );
328 272 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
329 273 'mw_adminimize_disabled_global_option_' . $role . '_items'
@@ -353,22 +297,35 @@
353 297 }
354 298
355 299 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
356 300
357 - // Backend options
301 + // global options
358 302 // exclude super admin
359 - if ( ! _mw_adminimize_exclude_super_admin() && ! _mw_adminimize_exclude_settings_page() ) {
303 + if ( ! _mw_adminimize_exclude_super_admin() ) {
304 + $_mw_adminimize_footer = (int) _mw_adminimize_get_option_value( '_mw_adminimize_footer' );
305 + switch ( $_mw_adminimize_footer ) {
306 + case 1:
307 + wp_enqueue_script(
308 + '_mw_adminimize_remove_footer',
309 + WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_footer' . $suffix . '.js',
310 + array( 'jquery' )
311 + );
312 + break;
313 + }
314 +
360 315 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
361 - if ( 1 === $_mw_adminimize_header ) {
362 - wp_enqueue_script(
363 - '_mw_adminimize_remove_header',
364 - WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
365 - [ 'jquery' ]
366 - );
316 + switch ( $_mw_adminimize_header ) {
317 + case 1:
318 + wp_enqueue_script(
319 + '_mw_adminimize_remove_header',
320 + WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
321 + array( 'jquery' )
322 + );
323 + break;
367 324 }
368 325
369 - // Post-page options.
370 - if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
326 + //post-page options
327 + if ( in_array( $pagenow, $def_post_pages, FALSE ) ) {
371 328
372 329 $_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
373 330 switch ( $_mw_adminimize_tb_window ) {
374 331 case 1:
@@ -390,9 +347,9 @@
390 347 );
391 348 break;
392 349 }
393 350
394 - // Category options.
351 + //category options
395 352 $_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
396 353 switch ( $_mw_adminimize_cat_full ) {
397 354 case 1:
398 355 wp_enqueue_style(
@@ -401,82 +358,97 @@
401 358 );
402 359 break;
403 360 }
404 361
405 - // Set default editor tinymce
362 + // set default editor tinymce
406 363 if ( _mw_adminimize_recursive_in_array(
407 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
408 - $disabled_metaboxes_page_all
409 - )
410 - || _mw_adminimize_recursive_in_array(
411 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
412 - $disabled_metaboxes_post_all
413 - )
364 + '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
365 + $disabled_metaboxes_page_all
366 + )
367 + || _mw_adminimize_recursive_in_array(
368 + '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
369 + $disabled_metaboxes_post_all
370 + )
414 371 ) {
415 - add_filter( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
416 - /**
417 - * Return string tinymce.
418 - * Necessary for php 5.2 usage :(; not possible to use an anonymous function.
419 - *
420 - * @return string
421 - */
422 - function _mw_admininimize_return_tinmyce() {
423 - return 'tinymce';
424 - }
372 + add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
425 373 }
426 374
427 - // Remove media buttons
375 + // remove media bottons
428 376 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
429 - || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
377 + || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
430 378 ) {
431 379 remove_action( 'media_buttons', 'media_buttons' );
432 380 }
433 381 }
382 +
434 383 }
435 384
436 - // set meta-box post option
437 - if ( in_array( $pagenow, $def_post_pages, TRUE ) && in_array( $current_post_type, $def_post_types, TRUE ) ) {
385 + // set menu option
386 + add_action( 'admin_head', '_mw_adminimize_set_menu_option', 1 );
387 + // global_options
388 + add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
389 +
390 + // set metabox post option
391 + if ( in_array( $pagenow, $def_post_pages, FALSE ) && in_array( $current_post_type, $def_post_types, FALSE ) ) {
438 392 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
439 393 }
440 - // set meta-box page option
441 - if ( in_array( $pagenow, $def_page_pages, TRUE ) && in_array( $current_post_type, $def_page_types, TRUE ) ) {
394 + // set metabox page option
395 + if ( in_array( $pagenow, $def_page_pages, FALSE ) && in_array( $current_post_type, $def_page_types, FALSE ) ) {
442 396 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
443 397 }
444 398 // set custom post type options
445 - if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
446 - && in_array( $current_post_type, $def_custom_types, TRUE )
399 + if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, FALSE )
400 + && in_array(
401 + $current_post_type, $def_custom_types, FALSE
402 + )
447 403 ) {
448 404 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
449 405 }
450 406 // set link option
451 - if ( in_array( $pagenow, $link_pages, TRUE ) ) {
407 + if ( in_array( $pagenow, $link_pages, FALSE ) ) {
452 408 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
453 409 }
454 410 // set wp nav menu options
455 - if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
411 + if ( in_array( $pagenow, $nav_menu_pages, FALSE ) ) {
456 412 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
457 413 }
458 414 // set widget options
459 - if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
415 + if ( in_array( $pagenow, $widget_pages, FALSE ) ) {
460 416 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
461 417 }
418 +
419 + $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
420 + $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
462 421 }
463 422
464 -// Change menu via settings of Adminimize.
465 -//add_filter( 'custom_menu_order', '__return_true' );
466 -add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
423 +/**
424 + * Init always with WP
425 + */
426 +function _mw_adminimize_init() {
467 427
468 -// global_options
469 -add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
428 + // change Admin Bar and user Info
429 + if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3alpha', '>=' ) ) {
430 + _mw_adminimize_set_menu_option_33();
431 + } else {
432 + add_action( 'admin_head', '_mw_adminimize_set_user_info' );
433 + add_action( 'wp_head', '_mw_adminimize_set_user_info' );
434 + }
435 +
436 +}
437 +
470 438 // on admin init
439 +define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
471 440 if ( is_admin() ) {
472 - add_action( 'admin_init', '_mw_adminimize_admin_init' );
441 + add_action( 'admin_init', '_mw_adminimize_textdomain' );
442 + add_action( 'admin_init', '_mw_adminimize_admin_init', 2 );
473 443 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
474 444 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
475 445 }
446 +add_action( 'init', '_mw_adminimize_init', 2 );
476 447
477 448 register_activation_hook( __FILE__, '_mw_adminimize_install' );
478 -register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
449 +register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
450 +//register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
479 451
480 452 /**
481 453 * Remove the dashboard
482 454 */
@@ -493,17 +465,17 @@
493 465 }
494 466
495 467 global $menu, $user_ID;
496 468
497 - $disabled_menu_ = array();
498 - $disabled_submenu_ = array();
469 + $disabled_menu_ = '';
470 + $disabled_submenu_ = '';
499 471 $user_roles = _mw_adminimize_get_all_user_roles();
500 472
501 473 foreach ( $user_roles as $role ) {
502 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
474 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
503 475 'mw_adminimize_disabled_menu_' . $role . '_items'
504 476 );
505 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
477 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
506 478 'mw_adminimize_disabled_submenu_' . $role . '_items'
507 479 );
508 480 }
509 481
@@ -521,9 +493,9 @@
521 493 $redirect = FALSE;
522 494 foreach ( $user_roles as $role ) {
523 495 if ( _mw_adminimize_current_user_has_role( $role ) ) {
524 496 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
525 - || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
497 + || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
526 498 ) {
527 499 $redirect = TRUE;
528 500 }
529 501 }
@@ -528,9 +500,9 @@
528 500 }
529 501 }
530 502 }
531 503
532 - // Redirect option, if Dashboard is inactive
504 + // redirect option, if Dashboard is inactive
533 505 if ( $redirect ) {
534 506 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
535 507 '_mw_adminimize_db_redirect'
536 508 );
@@ -565,14 +537,14 @@
565 537
566 538 $dashboard_core_string = esc_attr__( 'Dashboard' );
567 539 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
568 540 while (
569 - ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
541 + ! in_array( $dashboard_core_string, $dashboard, FALSE ) && next( $menu )
570 542 ) {
571 543 $page = key( $menu );
572 544 }
573 545
574 - if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
546 + if ( in_array( $dashboard_core_string, $dashboard, FALSE ) ) {
575 547 unset( $menu[ $page ] );
576 548 }
577 549 reset( $menu );
578 550 $page = key( $menu );
@@ -581,15 +553,112 @@
581 553 $page = key( $menu );
582 554 }
583 555
584 556 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
585 - wp_safe_redirect( $_mw_adminimize_db_redirect );
557 + wp_redirect( $_mw_adminimize_db_redirect );
586 558 }
587 559 }
560 +
588 561 }
589 562 }
590 563
591 564 /**
565 + * Set menu options from database.
566 + */
567 +function _mw_adminimize_set_user_info() {
568 +
569 + if ( _mw_adminimize_exclude_settings_page() ) {
570 + return;
571 + }
572 +
573 + // exclude super admin
574 + if ( _mw_adminimize_exclude_super_admin() ) {
575 + return;
576 + }
577 +
578 + global $user_identity;
579 +
580 + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
581 + $user_roles = _mw_adminimize_get_all_user_roles();
582 +
583 + foreach ( $user_roles as $role ) {
584 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
585 + 'mw_adminimize_disabled_menu_' . $role . '_items'
586 + );
587 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
588 + 'mw_adminimize_disabled_submenu_' . $role . '_items'
589 + );
590 + }
591 +
592 + $_mw_adminimize_admin_head = "\n";
593 + $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
594 + $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
595 +
596 + // change user-info
597 + switch ( $_mw_adminimize_user_info ) {
598 + case 1:
599 + $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
600 + $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove(); });' . "\n";
601 + $_mw_adminimize_admin_head .= '</script>' . "\n";
602 + break;
603 + case 2:
604 + $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
605 + dirname( __FILE__ )
606 + ) . '/css/mw_small_user_info' . $suffix . '.css" type="text/css" />' . "\n";
607 +
608 + $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
609 + $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
610 + if ( 1 === (int) $_mw_adminimize_ui_redirect ) {
611 + $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
612 + 'siteurl'
613 + ) . wp_nonce_url(
614 + ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
615 + ) . '" title="' . esc_attr__( 'Log Out' ) . '">' . esc_attr__(
616 + 'Log Out'
617 + ) . '</a></p></div>\' ) });' . "\n";
618 + } else {
619 + $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
620 + 'siteurl'
621 + ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . esc_attr__(
622 + 'Log Out'
623 + ) . '">' . esc_attr__( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
624 + }
625 + $_mw_adminimize_admin_head .= '</script>' . "\n";
626 + break;
627 + case 3:
628 + $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
629 + dirname( __FILE__ )
630 + ) . '/css/mw_small_user_info' . $suffix . '.css" type="text/css" />' . "\n";
631 +
632 + $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
633 + $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
634 + if ( 1 === (int) $_mw_adminimize_ui_redirect ) {
635 + $_mw_adminimize_admin_head .= 'jQuery( \'div#wpcontent\' ).after( \'<div id="small_user_info"><p><a href="' . get_option(
636 + 'siteurl'
637 + ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
638 + 'siteurl'
639 + ) . wp_nonce_url(
640 + ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
641 + ) . '" title="' . esc_attr__( 'Log Out' ) . '">' . esc_attr__(
642 + 'Log Out'
643 + ) . '</a></p></div>\' ) });' . "\n";
644 + } else {
645 + $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
646 + 'siteurl'
647 + ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
648 + 'siteurl'
649 + ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . esc_attr__(
650 + 'Log Out'
651 + ) . '">' . esc_attr__( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
652 + }
653 + $_mw_adminimize_admin_head .= '</script>' . "\n";
654 + break;
655 + }
656 +
657 + echo $_mw_adminimize_admin_head;
658 +}
659 +
660 +/**
592 661 * Set menu for settings
593 662 */
594 663 function _mw_adminimize_set_menu_option() {
595 664
@@ -594,9 +663,9 @@
594 663 function _mw_adminimize_set_menu_option() {
595 664
596 665 // exclude super admin
597 666 if ( _mw_adminimize_exclude_super_admin() ) {
598 - return;
667 + return NULL;
599 668 }
600 669
601 670 // Leave the settings screen from Adminimize to see all areas on settings.
602 671 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -603,40 +672,22 @@
603 672 return;
604 673 }
605 674
606 675 global $menu, $submenu;
607 - $wp_menu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_menu' );
608 - $wp_submenu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_submenu' );
609 676
610 - // Object to array
611 - if ( is_object( $wp_submenu ) ) {
612 - $wp_submenu = get_object_vars( $wp_submenu );
613 - }
614 -
615 - if ( ! isset( $wp_menu ) || empty( $wp_menu ) ) {
616 - $wp_menu = $menu;
617 - }
618 - if ( ! isset( $wp_submenu ) || empty( $wp_submenu ) ) {
619 - $wp_submenu = $submenu;
620 - }
621 677 if ( ! isset( $menu ) || empty( $menu ) ) {
622 678 return;
623 679 }
624 680
625 - _mw_adminimize_debug( $wp_menu, 'Adminimize, WordPress Menu:' );
626 - _mw_adminimize_debug( $wp_submenu, 'Adminimize, WordPress Sub-Menu:' );
681 + $user_roles = _mw_adminimize_get_all_user_roles();
682 + $disabled_menu_ = '';
683 + $disabled_submenu_ = '';
627 684
628 - $disabled_menu_ = array();
629 - $disabled_submenu_ = array();
630 - $user = wp_get_current_user();
631 - $user_roles = $user->roles;
632 - _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
633 -
634 685 foreach ( $user_roles as $role ) {
635 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
686 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
636 687 'mw_adminimize_disabled_menu_' . $role . '_items'
637 688 );
638 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
689 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
639 690 'mw_adminimize_disabled_submenu_' . $role . '_items'
640 691 );
641 692 }
642 693
@@ -644,69 +695,52 @@
644 695 $mw_adminimize_submenu = array();
645 696
646 697 // Set admin-menu.
647 698 foreach ( $user_roles as $role ) {
648 - if ( in_array( $role, $user->roles, TRUE )
649 - && _mw_adminimize_current_user_has_role( $role )
699 +
700 + $user = wp_get_current_user();
701 +
702 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE )
703 + && _mw_adminimize_current_user_has_role(
704 + $role
705 + )
650 706 ) {
651 - // Create array about all items with all affected roles.
652 - foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
653 - $mw_adminimize_menu[] = $menu_item;
654 - }
655 - foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
656 - $mw_adminimize_submenu[] = $submenu_item;
657 - }
707 + $mw_adminimize_menu = $disabled_menu_[ $role ];
708 + $mw_adminimize_submenu = $disabled_submenu_[ $role ];
658 709 }
659 710 }
660 711
661 - // Support Multiple Roles for users.
662 - // Leave only the items, there are active on each roles of the users.
663 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
664 - $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
665 - $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
666 - } else {
667 - // Alternative filter the array to remove duplicates, much faster.
668 - $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
669 - $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
712 + // Fallback on users.php on all user roles smaller admin.
713 + if ( is_array( $mw_adminimize_menu ) && in_array( 'users.php', $mw_adminimize_menu, FALSE ) ) {
714 + $mw_adminimize_menu[] = 'profile.php';
670 715 }
671 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
672 - _mw_adminimize_debug( $mw_adminimize_submenu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
673 716
674 - foreach ( $wp_menu as $key => $item ) {
717 + foreach ( $menu as $index => $item ) {
675 718
676 - _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
719 + if ( 'index.php' === $item ) {
720 + continue;
721 + }
677 722
678 - // Menu
679 723 if ( isset( $item[ 2 ] ) ) {
680 - $menu_slug = $item[ 2 ];
681 - // Check, if the Menu item in the current user role settings?
682 - if ( in_array( $menu_slug, $mw_adminimize_menu, false )
724 + if ( isset( $mw_adminimize_menu ) && is_array( $mw_adminimize_menu )
725 + && in_array(
726 + $item[ 2 ], $mw_adminimize_menu, FALSE
727 + )
683 728 ) {
684 - remove_menu_page( $menu_slug );
685 - // Prevent access to the page with the slug, there was inactive.
686 - _mw_adminimize_check_page_access( $menu_slug );
729 + unset( $menu[ $index ] );
687 730 }
688 731
689 - // Sub Menu Settings.
690 - if ( isset( $wp_submenu ) && ! empty( $wp_submenu[ $menu_slug ] ) ) {
691 - foreach ( (array) $wp_submenu[ $menu_slug ] as $subindex => $subitem ) {
692 -
693 - // @see https://github.com/bueltge/adminimize/issues/149
694 - if ( is_object( $subitem ) ) {
695 - $subitem = json_decode( json_encode( $subitem ), true );
696 - }
697 -
698 - // Check, if is Sub Menu item in the user role settings?
732 + if ( isset( $submenu ) && ! empty( $submenu[ $item[ 2 ] ] ) ) {
733 + foreach ( $submenu[ $item[ 2 ] ] as $subindex => $subitem ) {
734 + // Check, if is menu item in the user role settings?
699 735 if (
700 736 isset( $mw_adminimize_submenu )
701 737 && _mw_adminimize_in_arrays(
702 - array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
738 + array( $subitem[ 2 ], $item[ 2 ] . '__' . $subindex ),
703 739 $mw_adminimize_submenu
704 740 )
705 741 ) {
706 - remove_submenu_page( $menu_slug, $subitem[ 2 ] );
707 - // Prevent access to the page with the slug, there was inactive.
708 - _mw_adminimize_check_page_access( $subitem[ 2 ] );
742 + unset( $submenu[ $item[ 2 ] ][ $subindex ] );
709 743 }
710 744 }
711 745 }
712 746 }
@@ -714,12 +748,14 @@
714 748
715 749 }
716 750
717 751 /**
718 - * Set global options in backend in all areas.
752 + * set global options in backend in all areas
719 753 */
720 754 function _mw_adminimize_set_global_option() {
721 755
756 + global $_wp_admin_css_colors;
757 +
722 758 // exclude super admin
723 759 if ( _mw_adminimize_exclude_super_admin() ) {
724 760 return NULL;
725 761 }
@@ -730,59 +766,53 @@
730 766 }
731 767
732 768 $user_roles = _mw_adminimize_get_all_user_roles();
733 769 $_mw_adminimize_admin_head = '';
734 - $disabled_global_option = array();
735 - $disabled_global_option_ = array();
736 - $user = wp_get_current_user();
737 770
738 - // Get settings for each role.
739 771 foreach ( $user_roles as $role ) {
740 - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
772 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
741 773 'mw_adminimize_disabled_global_option_' . $role . '_items'
742 774 );
743 775 }
744 776
745 - // Write global options in an var.
746 777 foreach ( $user_roles as $role ) {
747 - if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
778 + if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
779 + $disabled_global_option_[ $role ][ '0' ] = '';
780 + }
781 + }
748 782
749 - // Create array about all items with all affected roles, important for multiple roles.
750 - foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
751 - $disabled_global_option[] = $global_item;
783 + $global_options = '';
784 + // new 1.7.8
785 + foreach ( $user_roles as $role ) {
786 + $user = wp_get_current_user();
787 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
788 + if ( _mw_adminimize_current_user_has_role( $role )
789 + && isset( $disabled_global_option_[ $role ] )
790 + && is_array( $disabled_global_option_[ $role ] )
791 + ) {
792 + $global_options = implode( ', ', $disabled_global_option_[ $role ] );
752 793 }
753 794 }
754 795 }
755 -
756 - // Support Multiple Roles for users.
757 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
758 - $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
759 - }
760 - $global_options = implode( ', ', $disabled_global_option );
761 -
762 - if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
763 - global $_wp_admin_css_colors;
796 + if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
764 797 $_wp_admin_css_colors = 0;
765 798 }
766 799 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
767 800 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
768 801
769 - // List options if the debug option is active.
770 - _mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
771 -
772 - if ( '' !== $global_options ) {
802 + if ( ! empty( $global_options ) ) {
773 803 echo $_mw_adminimize_admin_head;
774 804 }
775 805 }
776 806
777 807 /**
778 - * Set metabox options from database an area post.
808 + * set metabox options from database an area post
779 809 */
780 810 function _mw_adminimize_set_metabox_post_option() {
781 811
782 812 // exclude super admin
783 813 if ( _mw_adminimize_exclude_super_admin() ) {
784 - return;
814 + return NULL;
785 815 }
786 816
787 817 // Leave the settings screen from Adminimize to see all areas on settings.
788 818 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -790,10 +820,9 @@
790 820 }
791 821
792 822 $user_roles = _mw_adminimize_get_all_user_roles();
793 823 $_mw_adminimize_admin_head = '';
794 - // It's better to declare $metaboxes as an array for better manipulation later.
795 - $metaboxes = array();
824 + $metaboxes = '';
796 825
797 826 foreach ( $user_roles as $role ) {
798 827 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
799 828 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
@@ -798,42 +827,28 @@
798 827 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
799 828 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
800 829 );
801 830
802 - if ( ! isset( $disabled_metaboxes_post_[ $role ]['0'] ) ) {
803 - $disabled_metaboxes_post_[ $role ]['0'] = '';
804 -
805 - /**
806 - * @todo Think why keep going if $role does not even have boxes to hide? We may as well jump to the next $role.
807 - */
808 - continue;
831 + if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
832 + $disabled_metaboxes_post_[ $role ][ '0' ] = '';
809 833 }
810 834
811 - /**
812 - * @todo Think why call a function as we can use a global variable already declared by WordPress.
813 - * @var WP_User $user Instance of WP_User.
814 - * @since 1.7.8
815 - * @version 1.11.4
816 - */
817 - $user = $GLOBALS['current_user'];
818 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
835 + // new 1.7.8
836 + $user = wp_get_current_user();
837 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
819 838 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
820 - && is_array(
821 - $disabled_metaboxes_post_[ $role ]
822 - )
839 + && is_array(
840 + $disabled_metaboxes_post_[ $role ]
841 + )
823 842 ) {
824 - // The previous way $metaboxes was being filled it could be at some point non empty and empty afterwards.
825 - // For instance, if a $role has items to be hidden and the user has this $role, $metaboxes will be filled.
826 - // But in next loop $metaboxes may receive '' as the next $role might not have items to hide and the user might has the next $role.
827 - $metaboxes[] = implode( ',', $disabled_metaboxes_post_[ $role ] );
843 + $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
828 844 }
829 845 }
830 846 }
831 847
832 848 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
833 - // And below we implode $metaboxes because it's an array now.
834 849 $_mw_adminimize_admin_head .= '<style type="text/css">' .
835 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
850 + $metaboxes . ' {display:none !important;}</style>' . "\n";
836 851
837 852 if ( ! empty( $metaboxes ) ) {
838 853 echo $_mw_adminimize_admin_head;
839 854 }
@@ -839,9 +854,9 @@
839 854 }
840 855 }
841 856
842 857 /**
843 - * Set metabox options from database an area page.
858 + * set metabox options from database an area page
844 859 */
845 860 function _mw_adminimize_set_metabox_page_option() {
846 861
847 862 // exclude super admin
@@ -866,14 +881,14 @@
866 881 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
867 882 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
868 883 }
869 884
870 - // New since version 1.7.8.
885 + // new 1.7.8
871 886 $user = wp_get_current_user();
872 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
887 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
873 888 if ( _mw_adminimize_current_user_has_role( $role )
874 - && isset( $disabled_metaboxes_page_[ $role ] )
875 - && is_array( $disabled_metaboxes_page_[ $role ] )
889 + && isset( $disabled_metaboxes_page_[ $role ] )
890 + && is_array( $disabled_metaboxes_page_[ $role ] )
876 891 ) {
877 892 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
878 893 }
879 894 }
@@ -880,9 +895,9 @@
880 895 }
881 896
882 897 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
883 898 $_mw_adminimize_admin_head .= '<style type="text/css">' .
884 - $metaboxes . ' {display:none !important;}</style>' . "\n";
899 + $metaboxes . ' {display:none !important;}</style>' . "\n";
885 900
886 901 if ( ! empty( $metaboxes ) ) {
887 902 echo $_mw_adminimize_admin_head;
888 903 }
@@ -888,9 +903,9 @@
888 903 }
889 904 }
890 905
891 906 /**
892 - * Set metabox options from database an area post.
907 + * set metabox options from database an area post
893 908 */
894 909 function _mw_adminimize_set_metabox_cp_option() {
895 910
896 911 // exclude super admin
@@ -902,13 +917,14 @@
902 917 if ( _mw_adminimize_exclude_settings_page() ) {
903 918 return;
904 919 }
905 920
906 - $post_id = 0;
907 921 if ( isset( $_GET[ 'post' ] ) ) {
908 922 $post_id = (int) $_GET[ 'post' ];
909 923 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
910 924 $post_id = (int) $_POST[ 'post_ID' ];
925 + } else {
926 + $post_id = 0;
911 927 }
912 928
913 929 $current_post_type = $GLOBALS[ 'post_type' ];
914 930 if ( ! isset( $current_post_type ) ) {
@@ -925,9 +941,9 @@
925 941 }
926 942
927 943 $user_roles = _mw_adminimize_get_all_user_roles();
928 944 $_mw_adminimize_admin_head = '';
929 - $metaboxes = array();
945 + $metaboxes = '';
930 946
931 947 foreach ( $user_roles as $role ) {
932 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
933 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
@@ -932,21 +948,19 @@
932 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
933 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
934 950 );
935 951
936 - if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
937 - $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
938 -
939 - continue;
952 + if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
953 + $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
940 954 }
941 955
942 - $user = $GLOBALS['current_user'];
943 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
956 + $user = wp_get_current_user();
957 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
944 958 if ( _mw_adminimize_current_user_has_role( $role )
945 - && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
946 - && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
959 + && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
960 + && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
947 961 ) {
948 - $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
962 + $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
949 963 }
950 964 }
951 965 }
952 966
@@ -951,9 +965,9 @@
951 965 }
952 966
953 967 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
954 968 $_mw_adminimize_admin_head .= '<style type="text/css">' .
955 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
969 + $metaboxes . ' {display:none !important;}</style>' . "\n";
956 970
957 971 if ( ! empty( $metaboxes ) ) {
958 972 echo $_mw_adminimize_admin_head;
959 973 }
@@ -959,9 +973,9 @@
959 973 }
960 974 }
961 975
962 976 /**
963 - * Set link options in area links of back end.
977 + * set link options in area Links of Backend
964 978 */
965 979 function _mw_adminimize_set_link_option() {
966 980
967 981 // exclude super admin
@@ -989,11 +1003,12 @@
989 1003 }
990 1004 }
991 1005
992 1006 $link_options = '';
1007 + // new 1.7.8
993 1008 foreach ( $user_roles as $role ) {
994 1009 $user = wp_get_current_user();
995 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1010 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
996 1011 if ( _mw_adminimize_current_user_has_role( $role )
997 1012 && isset( $disabled_link_option_[ $role ] )
998 1013 && is_array( $disabled_link_option_[ $role ] )
999 1014 ) {
@@ -1003,9 +1018,9 @@
1003 1018 }
1004 1019
1005 1020 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
1006 1021 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1007 - $link_options . ' {display:none !important;}</style>' . "\n";
1022 + $link_options . ' {display:none !important;}</style>' . "\n";
1008 1023
1009 1024 if ( ! empty( $link_options ) ) {
1010 1025 echo $_mw_adminimize_admin_head;
1011 1026 }
@@ -1011,9 +1026,9 @@
1011 1026 }
1012 1027 }
1013 1028
1014 1029 /**
1015 - * Remove objects on wp nav menu.
1030 + * remove objects on wp nav menu
1016 1031 */
1017 1032 function _mw_adminimize_set_nav_menu_option() {
1018 1033
1019 1034 // exclude super admin
@@ -1041,11 +1056,12 @@
1041 1056 }
1042 1057 }
1043 1058
1044 1059 $nav_menu_options = '';
1060 + // new 1.7.8
1045 1061 foreach ( $user_roles as $role ) {
1046 1062 $user = wp_get_current_user();
1047 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1063 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1048 1064 if ( _mw_adminimize_current_user_has_role( $role )
1049 1065 && isset( $disabled_nav_menu_option_[ $role ] )
1050 1066 && is_array( $disabled_nav_menu_option_[ $role ] )
1051 1067 ) {
@@ -1052,12 +1068,13 @@
1052 1068 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1053 1069 }
1054 1070 }
1055 1071 }
1072 + //remove_meta_box( $id, 'nav-menus', 'side' );
1056 1073
1057 1074 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1058 1075 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1059 - $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1076 + $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1060 1077
1061 1078 if ( $nav_menu_options ) {
1062 1079 echo $_mw_adminimize_admin_head;
1063 1080 }
@@ -1093,11 +1110,12 @@
1093 1110 }
1094 1111 }
1095 1112
1096 1113 $widget_options = '';
1114 + // new 1.7.8
1097 1115 foreach ( $user_roles as $role ) {
1098 1116 $user = wp_get_current_user();
1099 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1117 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1100 1118 if ( _mw_adminimize_current_user_has_role( $role )
1101 1119 && isset( $disabled_widget_option_[ $role ] )
1102 1120 && is_array( $disabled_widget_option_[ $role ] )
1103 1121 ) {
@@ -1104,12 +1122,13 @@
1104 1122 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1105 1123 }
1106 1124 }
1107 1125 }
1126 + //remove_meta_box( $id, 'nav-menus', 'side' );
1108 1127
1109 1128 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1110 1129 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1111 - $widget_options . ' {display: none !important;}</style>' . "\n";
1130 + $widget_options . ' {display: none !important;}</style>' . "\n";
1112 1131
1113 1132 if ( $widget_options ) {
1114 1133 echo $_mw_adminimize_admin_head;
1115 1134 }
@@ -1115,9 +1134,9 @@
1115 1134 }
1116 1135 }
1117 1136
1118 1137 /**
1119 - * Print small user-info.
1138 + * small user-info
1120 1139 */
1121 1140 function _mw_adminimize_small_user_info() {
1122 1141
1123 1142 ?>
@@ -1132,15 +1151,13 @@
1132 1151 </div>
1133 1152 <?php
1134 1153 }
1135 1154
1155 +// Include message class.
1156 +require_once 'inc-setup/messages.php';
1136 1157 // include helping functions
1137 -require_once 'inc-setup/DebugListener.php';
1138 1158 require_once 'inc-setup/helping_hands.php';
1139 1159
1140 -// Include message class.
1141 -require_once 'inc-setup/messages.php';
1142 -
1143 1160 // inc. settings page
1144 1161 require_once 'adminimize_page.php';
1145 1162
1146 1163 // dashboard options
@@ -1147,11 +1164,14 @@
1147 1164 require_once 'inc-setup/dashboard.php';
1148 1165
1149 1166 // widget options
1150 1167 require_once 'inc-setup/widget.php';
1151 -require_once 'inc-setup/footer.php';
1152 1168 require_once 'inc-setup/admin-footer.php';
1153 1169
1170 +// global settings
1171 +// @TODO Testing, not ready for productive
1172 +//require_once( 'inc-options/settings_notice.php' );
1173 +
1154 1174 // remove admin bar
1155 1175 require_once 'inc-setup/remove-admin-bar.php';
1156 1176
1157 1177 // admin bar helper, setup
@@ -1164,19 +1184,15 @@
1164 1184
1165 1185 // Remove Admin Notices.
1166 1186 require_once 'inc-setup/remove-admin-notices.php';
1167 1187
1168 -// Add Ex-Import functions.
1169 -require_once 'inc-setup/export.php';
1170 -require_once 'inc-setup/import.php';
1171 -
1172 1188 /**
1173 1189 * Add action link(s) to plugins page
1174 1190 *
1175 - * @param array $links
1176 - * @param string $file
1191 + * @param $links , $file
1192 + * @param $file
1177 1193 *
1178 - * @return array $links
1194 + * @return $links
1179 1195 */
1180 1196 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1181 1197
1182 1198 /* create link */
@@ -1182,12 +1198,9 @@
1182 1198 /* create link */
1183 1199 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1184 1200 array_unshift(
1185 1201 $links,
1186 - sprintf(
1187 - '<a href="options-general.php?page=adminimize-options">%s</a>',
1188 - esc_attr__( 'Settings' )
1189 - )
1202 + sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, esc_attr__( 'Settings' ) )
1190 1203 );
1191 1204 }
1192 1205
1193 1206 return $links;
@@ -1193,9 +1206,9 @@
1193 1206 return $links;
1194 1207 }
1195 1208
1196 1209 /**
1197 - * Add settings in plugin-admin-page.
1210 + * settings in plugin-admin-page
1198 1211 */
1199 1212 function _mw_adminimize_add_settings_page() {
1200 1213
1201 1214 $pagehook = add_options_page(
@@ -1201,12 +1214,11 @@
1201 1214 $pagehook = add_options_page(
1202 1215 esc_attr__( 'Adminimize Options', 'adminimize' ),
1203 1216 esc_attr__( 'Adminimize', 'adminimize' ),
1204 1217 'manage_options',
1205 - 'adminimize-options',
1218 + __FILE__,
1206 1219 '_mw_adminimize_options'
1207 1220 );
1208 -
1209 1221 if ( ! is_network_admin() ) {
1210 1222 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1211 1223 }
1212 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
@@ -1211,23 +1223,15 @@
1211 1223 }
1212 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1213 1225 }
1214 1226
1215 -/**
1216 - * Enqueue script and styles for the settings page.
1217 - */
1218 1227 function _mw_adminimize_on_load_page() {
1219 1228
1220 - // Load translation files on options page.
1221 - _mw_adminimize_textdomain();
1222 -
1223 1229 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1224 1230
1225 - wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1226 1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1227 1232 wp_enqueue_style( 'adminimize-style' );
1228 1233
1229 - wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1230 1234 wp_register_script(
1231 1235 'adminimize-settings-script',
1232 1236 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1233 1237 array( 'jquery' ),
@@ -1237,36 +1241,53 @@
1237 1241 wp_enqueue_script( 'adminimize-settings-script' );
1238 1242 }
1239 1243
1240 1244 /**
1245 + * Set theme for users
1246 + * Kill with version 1.7.18
1247 + */
1248 +function _mw_adminimize_set_theme() {
1249 +
1250 + if ( ! current_user_can( 'edit_users' ) ) {
1251 + wp_die( esc_attr__( 'Cheatin&#8217; uh?' ) );
1252 + }
1253 +
1254 + $user_ids = $_POST[ 'mw_adminimize_theme_items' ];
1255 + $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
1256 +
1257 + if ( ! $user_ids ) {
1258 + return FALSE;
1259 + }
1260 +
1261 + foreach ( $user_ids as $user_id ) {
1262 + update_user_meta( $user_id, 'admin_color', $admin_color );
1263 + }
1264 +
1265 + return TRUE;
1266 +}
1267 +
1268 +/**
1241 1269 * Get setting value for each options key.
1242 1270 *
1243 1271 * @param string|bool $key
1244 1272 *
1245 - * @return string
1273 + * @return array
1246 1274 */
1247 -function _mw_adminimize_get_option_value( $key = false ) {
1275 +function _mw_adminimize_get_option_value( $key = FALSE ) {
1248 1276
1249 - $adminimizeoptions = false;
1250 - if ( ! _mw_adminimize_exclude_settings_page() ) {
1251 - $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1277 + // check for use on multisite
1278 + if ( _mw_adminimize_is_active_on_multisite() ) {
1279 + $adminimizeoptions = get_site_option( 'mw_adminimize', array() );
1280 + } else {
1281 + $adminimizeoptions = get_option( 'mw_adminimize', array() );
1252 1282 }
1253 1283
1254 - if ( false === $adminimizeoptions ) {
1255 - // check for use on multisite.
1256 - if ( _mw_adminimize_is_active_on_multisite() ) {
1257 - $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1258 - } else {
1259 - $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1260 - }
1261 - wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1262 - }
1263 -
1264 1284 if ( ! $key ) {
1265 1285 return $adminimizeoptions;
1266 1286 }
1267 1287
1268 - return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : null;
1288 + /** @var array $adminimizeoptions */
1289 + return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1269 1290 }
1270 1291
1271 1292 /**
1272 1293 * Update options.
@@ -1271,36 +1292,20 @@
1271 1292 /**
1272 1293 * Update options.
1273 1294 *
1274 1295 * @param array $options
1275 - *
1276 - * @return bool
1277 1296 */
1278 1297 function _mw_adminimize_update_option( $options ) {
1279 1298
1280 1299 if ( ! current_user_can( 'manage_options' ) ) {
1281 - return FALSE;
1300 + return;
1282 1301 }
1283 1302
1284 - if ( _mw_adminimize_is_roles_options_import( $options ) ){
1285 - $options = _mw_adminimize_roles_complete_options( $options );
1286 - }
1287 -
1288 - // Remove slashes always.
1289 - foreach ( $options as $key => $value ) {
1290 - $options[ $key ] = stripslashes_deep( $value );
1291 - }
1292 -
1293 - // Kill the cache for the settings page.
1294 - wp_cache_delete( 'mw_adminimize' );
1295 1303 if ( _mw_adminimize_is_active_on_multisite() ) {
1296 1304 update_site_option( 'mw_adminimize', $options );
1297 1305 } else {
1298 1306 update_option( 'mw_adminimize', $options );
1299 1307 }
1300 - wp_cache_add( 'mw_adminimize', $options );
1301 -
1302 - return TRUE;
1303 1308 }
1304 1309
1305 1310 /**
1306 1311 * Update options in database
@@ -1324,33 +1329,8 @@
1324 1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1325 1330 }
1326 1331 }
1327 1332
1328 - // Plugin Self Settings.
1329 - if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1330 - $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1331 - } else {
1332 - $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1333 - }
1334 -
1335 - if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1336 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1337 - } else {
1338 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1339 - }
1340 -
1341 - if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1342 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1343 - } else {
1344 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1345 - }
1346 -
1347 - if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1348 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1349 - } else {
1350 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1351 - }
1352 -
1353 1333 // Admin Bar Front end settings
1354 1334 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1355 1335 'mw_adminimize_admin_bar_frontend_nodes'
1356 1336 );
@@ -1355,9 +1335,9 @@
1355 1335 'mw_adminimize_admin_bar_frontend_nodes'
1356 1336 );
1357 1337 // admin bar front end options
1358 1338 foreach ( $user_roles as $role ) {
1359 - // admin bar front-end options
1339 + // admin bar fron tend options
1360 1340 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1361 1341 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1362 1342 } else {
1363 1343 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
@@ -1418,19 +1398,10 @@
1418 1398 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1419 1399 }
1420 1400
1421 1401 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1422 - $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1423 - $_POST[ '_mw_adminimize_advice_txt' ],
1424 - array(
1425 - 'a' => array(
1426 - 'href' => array(),
1427 - 'title' => array()
1428 - ),
1429 - 'br' => array(),
1430 - 'em' => array(),
1431 - 'strong' => array(),
1432 - )
1402 + $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = htmlspecialchars(
1403 + stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] )
1433 1404 );
1434 1405 } else {
1435 1406 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1436 1407 }
@@ -1463,27 +1434,8 @@
1463 1434 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1464 1435 }
1465 1436 }
1466 1437
1467 - // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1468 -
1469 - // own menu slug
1470 - if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1471 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1472 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1473 - );
1474 - } else {
1475 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1476 - }
1477 - // own custom menu slug
1478 - if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1479 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1480 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1481 - );
1482 - } else {
1483 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1484 - }
1485 -
1486 1438 // global_options, metaboxes update
1487 1439 foreach ( $user_roles as $role ) {
1488 1440
1489 1441 // global options
@@ -1550,19 +1502,15 @@
1550 1502 }
1551 1503
1552 1504 // own options
1553 1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1554 - $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1555 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1556 - );
1506 + $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1557 1507 } else {
1558 1508 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1559 1509 }
1560 1510
1561 1511 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1562 - $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1563 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1564 - );
1512 + $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1565 1513 } else {
1566 1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1567 1515 }
1568 1516
@@ -1568,9 +1516,9 @@
1568 1516
1569 1517 // own post options
1570 1518 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1571 1519 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1572 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1520 + $_POST[ '_mw_adminimize_own_post_values' ]
1573 1521 );
1574 1522 } else {
1575 1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1576 1524 }
@@ -1576,9 +1524,9 @@
1576 1524 }
1577 1525
1578 1526 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1579 1527 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1580 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1528 + $_POST[ '_mw_adminimize_own_post_options' ]
1581 1529 );
1582 1530 } else {
1583 1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1584 1532 }
@@ -1585,9 +1533,9 @@
1585 1533
1586 1534 // own page options
1587 1535 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1588 1536 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1589 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1537 + $_POST[ '_mw_adminimize_own_page_values' ]
1590 1538 );
1591 1539 } else {
1592 1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1593 1541 }
@@ -1593,9 +1541,9 @@
1593 1541 }
1594 1542
1595 1543 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1596 1544 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1597 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1545 + $_POST[ '_mw_adminimize_own_page_options' ]
1598 1546 );
1599 1547 } else {
1600 1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1601 1549 }
@@ -1603,9 +1551,9 @@
1603 1551 // own custom post options
1604 1552 foreach ( $post_types as $post_type ) {
1605 1553 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1606 1554 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1607 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1555 + $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1608 1556 );
1609 1557 } else {
1610 1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1611 1559 }
@@ -1611,9 +1559,9 @@
1611 1559 }
1612 1560
1613 1561 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1614 1562 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1615 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1563 + $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1616 1564 );
1617 1565 } else {
1618 1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1619 1567 }
@@ -1621,9 +1569,9 @@
1621 1569
1622 1570 // own link options
1623 1571 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1624 1572 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1625 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1573 + $_POST[ '_mw_adminimize_own_link_values' ]
1626 1574 );
1627 1575 } else {
1628 1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1629 1577 }
@@ -1629,9 +1577,9 @@
1629 1577 }
1630 1578
1631 1579 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1632 1580 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1633 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1581 + $_POST[ '_mw_adminimize_own_link_options' ]
1634 1582 );
1635 1583 } else {
1636 1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1637 1585 }
@@ -1638,9 +1586,9 @@
1638 1586
1639 1587 // wp nav menu options
1640 1588 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1641 1589 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1642 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1590 + $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1643 1591 );
1644 1592 } else {
1645 1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1646 1594 }
@@ -1646,9 +1594,9 @@
1646 1594 }
1647 1595
1648 1596 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1649 1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1650 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1598 + $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1651 1599 );
1652 1600 } else {
1653 1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1654 1602 }
@@ -1655,9 +1603,9 @@
1655 1603
1656 1604 // widget options
1657 1605 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1658 1606 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1659 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1607 + $_POST[ '_mw_adminimize_own_widget_values' ]
1660 1608 );
1661 1609 } else {
1662 1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1663 1611 }
@@ -1663,9 +1611,9 @@
1663 1611 }
1664 1612
1665 1613 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1666 1614 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1667 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1615 + $_POST[ '_mw_adminimize_own_widget_options' ]
1668 1616 );
1669 1617 } else {
1670 1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1671 1619 }
@@ -1672,9 +1620,9 @@
1672 1620
1673 1621 // own dashboard options
1674 1622 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1675 1623 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1676 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1624 + $_POST[ '_mw_adminimize_own_dashboard_values' ]
1677 1625 );
1678 1626 } else {
1679 1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1680 1628 }
@@ -1680,9 +1628,9 @@
1680 1628 }
1681 1629
1682 1630 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1683 1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1684 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1632 + $_POST[ '_mw_adminimize_own_dashboard_options' ]
1685 1633 );
1686 1634 } else {
1687 1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1688 1636 }
@@ -1697,45 +1645,23 @@
1697 1645 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1698 1646 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1699 1647 }
1700 1648
1701 - /**
1702 - * Filter the adminimize options.
1703 - *
1704 - * Make the options filterable, so we can modify what is saved before it's sent to the db
1705 - *
1706 - * @since 1.11.6
1707 - *
1708 - * @param array $adminimizeoptions the original options.
1709 - * @param array $user_roles Array of the user roles.
1710 - * @param array $_POST Post data.
1711 - */
1712 - $adminimizeoptions = apply_filters( 'mw_adminimize_options_before_update', $adminimizeoptions, $user_roles, $_POST );
1713 -
1714 1649 // update
1715 - $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1650 + _mw_adminimize_update_option( $adminimizeoptions );
1716 1651
1717 1652 $myErrors = new _mw_adminimize_message_class();
1718 - if ( $update_status ) {
1719 - $message = $myErrors->get_error(
1653 + $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1720 1654 '_mw_adminimize_update'
1721 - );
1722 - } else {
1723 - $message = $myErrors->get_error(
1724 - '_mw_adminimize_access_denied'
1725 - );
1726 - }
1727 - echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1728 -
1729 - return TRUE;
1655 + ) . '</p></div>';
1656 + echo $myErrors;
1730 1657 }
1731 1658
1732 1659 /**
1733 1660 * Delete options in database
1734 1661 */
1735 -function _mw_adminimize_uninstall() {
1662 +function _mw_adminimize_deinstall() {
1736 1663
1737 - wp_cache_delete( 'mw_adminimize' );
1738 1664 delete_site_option( 'mw_adminimize' );
1739 1665 delete_option( 'mw_adminimize' );
1740 1666 }
1741 1667
@@ -1744,16 +1670,11 @@
1744 1670 */
1745 1671 function _mw_adminimize_install() {
1746 1672
1747 1673 if ( ! is_admin() ) {
1748 - return;
1674 + return NULL;
1749 1675 }
1750 1676
1751 - // If is AJAX Call.
1752 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
1753 - return;
1754 - }
1755 -
1756 1677 global $menu, $submenu;
1757 1678
1758 1679 $user_roles = _mw_adminimize_get_all_user_roles();
1759 1680 $adminimizeoptions = array();
@@ -1781,55 +1702,71 @@
1781 1702 add_site_option( 'mw_adminimize', $adminimizeoptions );
1782 1703 } else {
1783 1704 add_option( 'mw_adminimize', $adminimizeoptions );
1784 1705 }
1785 - wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1786 1706 }
1787 1707
1788 1708 /**
1789 - * Make sure adminimize option is complete when a role json file is imported
1790 - *
1791 - * @param array $roles_options
1792 - *
1793 - * @return array
1709 + * Process a settings export that generates a .json file of the shop settings
1794 1710 */
1795 -function _mw_adminimize_roles_complete_options( $roles_options ){
1711 +function _mw_adminimize_export_json() {
1796 1712
1797 - $adminimizeoption = _mw_adminimize_get_option_value();
1713 + if ( empty( $_GET[ '_mw_adminimize_export' ] ) || 'true' !== $_GET[ '_mw_adminimize_export' ] ) {
1714 + return;
1715 + }
1798 1716
1799 - foreach ( $roles_options as $role_option_name => $role_option_value ){
1800 - $adminimizeoption[$role_option_name] = $role_option_value;
1717 + require_once ABSPATH . 'wp-includes/pluggable.php';
1718 + if ( ! wp_verify_nonce( $_GET[ 'mw_adminimize_export_nonce' ], 'mw_adminimize_export_nonce' ) ) {
1719 + return;
1801 1720 }
1802 1721
1803 - return $adminimizeoption;
1722 + if ( ! current_user_can( 'manage_options' ) ) {
1723 + return;
1724 + }
1725 +
1726 + $settings = _mw_adminimize_get_option_value();
1727 +
1728 + ignore_user_abort( TRUE );
1729 +
1730 + nocache_headers();
1731 + header( 'Content-Type: application/json; charset=utf-8' );
1732 + header( 'Content-Disposition: attachment; filename=mw_adminimize-settings-export-' . date( 'm-d-Y' ) . '.json' );
1733 + header( 'Expires: 0' );
1734 +
1735 + echo json_encode( $settings );
1736 + exit();
1804 1737 }
1805 1738
1806 1739 /**
1807 - * Check if options comes from roles adminimize settings export
1808 - *
1809 - * @param array $options
1810 - *
1811 - * @return bool
1740 + * Process a settings import from a json file
1812 1741 */
1813 -function _mw_adminimize_is_roles_options_import( $options ){
1814 - global $wp_roles;
1742 +function _mw_adminimize_import_json() {
1815 1743
1816 - $roles_options = [];
1817 - foreach ( $wp_roles->role_names as $role_slug => $role_name ){
1744 + if ( empty( $_POST[ '_mw_adminimize_action' ] ) || '_mw_adminimize_import' !== $_POST[ '_mw_adminimize_action' ] ) {
1745 + return;
1746 + }
1818 1747
1819 - $role_options = array_filter(
1820 - $options, function ( $option_key ) use ( $role_slug ) {
1821 - return stripos( $option_key, '_' . $role_slug ) !== false;
1822 - }, ARRAY_FILTER_USE_KEY
1823 - );
1748 + if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_import_nonce' ], 'mw_adminimize_import_nonce' ) ) {
1749 + return;
1750 + }
1824 1751
1825 - if ( empty( $roles_options ) ){
1826 - $roles_options = $role_options;
1827 - } else {
1828 - $roles_options = array_merge( $roles_options, $role_options );
1829 - }
1752 + if ( ! current_user_can( 'manage_options' ) ) {
1753 + return;
1830 1754 }
1831 1755
1832 - if ( count( $options ) === count( $roles_options ) ){
1833 - return true;
1756 + $extension = pathinfo( $_FILES[ 'import_file' ][ 'name' ], PATHINFO_EXTENSION );
1757 + if ( $extension !== 'json' ) {
1758 + wp_die( esc_attr__( 'Please upload a valid .json file' ) );
1834 1759 }
1760 +
1761 + $import_file = $_FILES[ 'import_file' ][ 'tmp_name' ];
1762 +
1763 + if ( empty( $import_file ) ) {
1764 + wp_die( esc_attr__( 'Please upload a file to import' ) );
1765 + }
1766 +
1767 + // Retrieve the settings from the file and convert the json object to an array.
1768 + $settings = (array) json_decode( file_get_contents( $import_file ) );
1769 + unlink( $import_file );
1770 +
1771 + _mw_adminimize_update_option( $settings );
1835 1772 }