PluginProbe
Adminimize / 1.11.3
Adminimize v1.11.3
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
adminimize / adminimize.php

adminimize.php in Adminimize 1.11.3, at adminimize.php

1,726 lines 52.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Adminimize
4 * Plugin URI: https://wordpress.org/plugins/adminimize/
5 * Text Domain: adminimize
6 * Domain Path: /languages
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 * Author: Frank Bültge
9 * Author URI: http://bueltge.de/
10 * Version: 1.11.3
11 * License: GPLv3+
12 *
13 * Php Version 5.6
14 *
15 * @package WordPress
16 * @author Frank Bültge <frank@bueltge.de>
17 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 * @version 2017-11-16
19 */
20
21 /**
22 * The stylesheet and the initial idea is from Eric A. Meyer http://meyerweb.com/
23 * I have written a plugin with many options on the basis idea
24 * of differently user-right and a user-friendly range in admin-area via reduce areas.
25 * :( grmpf i have so much wishes and hints form users, there use the plugin and
26 * 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 */
29
30 if ( ! function_exists( 'add_action' ) ) {
31 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
32 exit;
33 }
34
35 // plugin definitions
36 define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
37 define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( __DIR__ ) );
38
39 /**
40 * Return data from the plugin.
41 *
42 * @param string $value
43 *
44 * @return mixed
45 */
46 function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
47
48 if ( ! function_exists( 'get_plugin_data' ) ) {
49 require_once ABSPATH . '/wp-admin/includes/plugin.php';
50 }
51
52 $plugin_data = get_plugin_data( __FILE__ );
53
54 return $plugin_data[ $value ];
55 }
56
57 /**
58 * Load language files.
59 */
60 function _mw_adminimize_textdomain() {
61
62 load_plugin_textdomain(
63 _mw_adminimize_get_plugin_data( 'TextDomain' ),
64 FALSE,
65 dirname( FB_ADMINIMIZE_BASENAME ) . _mw_adminimize_get_plugin_data( 'DomainPath' )
66 );
67 }
68
69 /**
70 * Exclude the Super Admin of Multisite.
71 *
72 * @return bool
73 */
74 function _mw_adminimize_exclude_super_admin() {
75
76 if ( ! function_exists( 'is_super_admin' ) ) {
77 return FALSE;
78 }
79
80 if ( ! is_super_admin() ) {
81 return FALSE;
82 }
83
84 if ( 1 === (int) _mw_adminimize_get_option_value( '_mw_adminimize_exclude_super_admin' ) ) {
85 return TRUE;
86 }
87
88 return FALSE;
89 }
90
91 /**
92 * Get the status, if is on the settings page.
93 *
94 * @return bool
95 */
96 function _mw_adminimize_exclude_settings_page() {
97
98 if ( ! is_admin() ) {
99 return FALSE;
100 }
101
102 if ( defined('DOING_AJAX') && DOING_AJAX ) {
103 return FALSE;
104 }
105
106 $page = '';
107 if ( isset( $_GET[ 'page' ] ) ) {
108 $page = esc_attr( $_GET[ 'page' ] );
109 }
110
111 $screen = $page;
112 if ( function_exists( 'get_current_screen' ) ) {
113 $screen = get_current_screen();
114 }
115
116 if ( isset( $screen->id ) ) {
117 $screen = $screen->id;
118 }
119
120 // Don't filter on settings page
121 return FALSE !== strpos( $screen, 'adminimize' );
122 }
123
124 /**
125 * Get status, if the plugin active network wide.
126 *
127 * @return bool
128 */
129 function _mw_adminimize_is_active_on_multisite() {
130
131 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
132 require_once ABSPATH . '/wp-admin/includes/plugin.php';
133 }
134
135 if ( is_multisite() && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME ) ) {
136 return TRUE;
137 }
138
139 return FALSE;
140 }
141
142 /**
143 * Returns an array with all user roles(names) in it.
144 * Inclusive self defined roles (for example with the 'Role Manager' plugin).
145 *
146 * @uses $wp_roles
147 * @return array $user_roles
148 */
149 function _mw_adminimize_get_all_user_roles() {
150
151 /** @var $wp_roles WP_Roles */
152 global $wp_roles;
153
154 $user_roles = array();
155
156 if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
157 foreach ( $wp_roles->roles as $role => $data ) {
158 $user_roles[] = $role;
159 // The $data var contains caps, maybe for later use.
160 }
161 }
162
163 // Exclude the new bbPress roles.
164 if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
165 $user_roles = array_diff(
166 $user_roles,
167 array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
168 );
169 }
170
171 return $user_roles;
172 }
173
174 /**
175 * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
176 * Inclusive self defined roles (for example with the 'Role Manager' plugin).
177 *
178 * @uses $wp_roles
179 * @return array $user_roles_names
180 */
181 function _mw_adminimize_get_all_user_roles_names() {
182
183 /** @var $wp_roles WP_Roles */
184 global $wp_roles;
185 $user_roles_names = array();
186
187 foreach ( $wp_roles->role_names as $role_name => $data ) {
188
189 $data = translate_user_role( $data );
190 $user_roles_names[] = $data;
191 }
192
193 // exclude the new bbPress roles
194 if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
195 $user_roles_names = array_diff(
196 $user_roles_names,
197 array(
198 esc_attr__( 'Keymaster', 'bbpress' ),
199 esc_attr__( 'Moderator', 'bbpress' ),
200 esc_attr__( 'Participant', 'bbpress' ),
201 esc_attr__( 'Spectator', 'bbpress' ),
202 esc_attr__( 'Blocked', 'bbpress' ),
203 )
204 );
205 }
206
207 return $user_roles_names;
208 }
209
210 /**
211 * Get post type.
212 *
213 * @return null|string String of the post type.
214 */
215 function _mw_adminimize_get_current_post_type() {
216
217 global $post, $typenow, $current_screen;
218
219 // We have a post so we can just get the post type from that.
220 if ( $post && $post->post_type ) {
221 return $post->post_type;
222 } // Check the global $typenow - set in admin.php
223 elseif ( $typenow ) {
224 return $typenow;
225 } // check the global $current_screen object - set in sceen.php
226 elseif ( $current_screen && $current_screen->post_type ) {
227 return $current_screen->post_type;
228 } // lastly check the post_type querystring
229 elseif ( isset( $_REQUEST[ 'post_type' ] ) ) {
230 return sanitize_key( $_REQUEST[ 'post_type' ] );
231 }
232
233 // we do not know the post type!
234 return NULL;
235 }
236
237 /**
238 * Check user-option and add new style.
239 */
240 function _mw_adminimize_admin_init() {
241
242 global $pagenow, $post_type, $menu, $submenu;
243
244 $post_id = 0;
245 if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
246 $post_id = (int) esc_attr( $_GET[ 'post' ] );
247 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
248 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
249 }
250
251 $current_post_type = $post_type;
252 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
253 $current_post_type = get_post_type( $post_id );
254 }
255 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
256 $current_post_type = _mw_adminimize_get_current_post_type();
257 }
258 if ( ! $current_post_type ) { // set hard to post
259 $current_post_type = 'post';
260 }
261
262 // Get all user roles.
263 $user_roles = _mw_adminimize_get_all_user_roles();
264
265 // Get settings.
266 $adminimizeoptions = _mw_adminimize_get_option_value();
267
268 // pages for post type Post
269 $def_post_pages = array( 'edit.php', 'post.php', 'post-new.php' );
270 $def_post_types = array( 'post' );
271 $disabled_metaboxes_post_all = array();
272 // pages for post type Page
273 $def_page_pages = array_merge( $def_post_pages, array( 'page-new.php', 'page.php' ) );
274 $def_page_types = array( 'page' );
275 $disabled_metaboxes_page_all = array();
276 // pages for custom post types
277 $def_custom_pages = $def_post_pages;
278 $args = array( 'public' => TRUE, '_builtin' => FALSE );
279 $def_custom_types = get_post_types( $args );
280 // pages for link pages
281 $link_pages = array( 'link.php', 'link-manager.php', 'link-add.php', 'edit-link-categories.php' );
282 // pages for nav menu
283 $nav_menu_pages = array( 'nav-menus.php' );
284 // widget pages
285 $widget_pages = array( 'widgets.php' );
286
287 foreach ( $user_roles as $role ) {
288 $disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
289 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
290 );
291 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
292 'mw_adminimize_disabled_global_option_' . $role . '_items'
293 );
294 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
295 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
296 );
297 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
298 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
299 );
300 foreach ( $def_custom_types as $post_type ) {
301 $disabled_metaboxes_[ $post_type . '_' . $role ] = _mw_adminimize_get_option_value(
302 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items'
303 );
304 }
305 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
306 'mw_adminimize_disabled_link_option_' . $role . '_items'
307 );
308 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
309 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
310 );
311 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
312 'mw_adminimize_disabled_widget_option_' . $role . '_items'
313 );
314 $disabled_metaboxes_post_all[] = $disabled_metaboxes_post_[ $role ];
315 $disabled_metaboxes_page_all[] = $disabled_metaboxes_page_[ $role ];
316 }
317
318 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
319
320 // Backend options
321 // exclude super admin
322 if ( ! _mw_adminimize_exclude_super_admin() && ! _mw_adminimize_exclude_settings_page() ) {
323
324 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
325 switch ( $_mw_adminimize_header ) {
326 case 1:
327 wp_enqueue_script(
328 '_mw_adminimize_remove_header',
329 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
330 array( 'jquery' )
331 );
332 break;
333 }
334
335 // Post-page options.
336 if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
337
338 $_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
339 switch ( $_mw_adminimize_tb_window ) {
340 case 1:
341 wp_deregister_script( 'media-upload' );
342 wp_enqueue_script(
343 'media-upload',
344 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/tb_window' . $suffix . '.js',
345 array( 'thickbox' )
346 );
347 break;
348 }
349 $_mw_adminimize_timestamp = (int) _mw_adminimize_get_option_value( '_mw_adminimize_timestamp' );
350 switch ( $_mw_adminimize_timestamp ) {
351 case 1:
352 wp_enqueue_script(
353 '_mw_adminimize_timestamp',
354 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/timestamp' . $suffix . '.js',
355 array( 'jquery' )
356 );
357 break;
358 }
359
360 // Category options.
361 $_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
362 switch ( $_mw_adminimize_cat_full ) {
363 case 1:
364 wp_enqueue_style(
365 'adminimize-full-category',
366 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/css/mw_cat_full' . $suffix . '.css'
367 );
368 break;
369 }
370
371 // Set default editor tinymce
372 if ( _mw_adminimize_recursive_in_array(
373 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
374 $disabled_metaboxes_page_all
375 )
376 || _mw_adminimize_recursive_in_array(
377 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
378 $disabled_metaboxes_post_all
379 )
380 ) {
381 add_filter(
382 'wp_default_editor',
383 function() {
384 return 'tinymce';
385 }
386 );
387 }
388
389 // Remove media buttons
390 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
391 || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
392 ) {
393 remove_action( 'media_buttons', 'media_buttons' );
394 }
395 }
396 }
397
398 // set meta-box post option
399 if ( in_array( $pagenow, $def_post_pages, TRUE ) && in_array( $current_post_type, $def_post_types, TRUE ) ) {
400 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
401 }
402 // set meta-box page option
403 if ( in_array( $pagenow, $def_page_pages, TRUE ) && in_array( $current_post_type, $def_page_types, TRUE ) ) {
404 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
405 }
406 // set custom post type options
407 if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
408 && in_array( $current_post_type, $def_custom_types, TRUE )
409 ) {
410 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
411 }
412 // set link option
413 if ( in_array( $pagenow, $link_pages, TRUE ) ) {
414 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
415 }
416 // set wp nav menu options
417 if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
418 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
419 }
420 // set widget options
421 if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
422 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
423 }
424 }
425
426 // Change menu via settings of Adminimize.
427 add_action( 'custom_menu_order', '_mw_adminimize_set_menu_option', 99999 );
428
429 // global_options
430 add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
431 // on admin init
432 if ( is_admin() ) {
433 add_action( 'admin_init', '_mw_adminimize_admin_init' );
434 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
435 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
436 }
437 add_action( 'init', '_mw_adminimize_set_logout_menu', 2 );
438
439 register_activation_hook( __FILE__, '_mw_adminimize_install' );
440 register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
441
442 /**
443 * Remove the dashboard
444 */
445 function _mw_adminimize_remove_dashboard() {
446
447 // exclude super admin
448 if ( _mw_adminimize_exclude_super_admin() ) {
449 return;
450 }
451
452 // Leave the settings screen from Adminimize to see all areas on settings.
453 if ( _mw_adminimize_exclude_settings_page() ) {
454 return;
455 }
456
457 global $menu, $user_ID;
458
459 $disabled_menu_ = array();
460 $disabled_submenu_ = array();
461 $user_roles = _mw_adminimize_get_all_user_roles();
462
463 foreach ( $user_roles as $role ) {
464 $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
465 'mw_adminimize_disabled_menu_' . $role . '_items'
466 );
467 $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
468 'mw_adminimize_disabled_submenu_' . $role . '_items'
469 );
470 }
471
472 $disabled_menu_all = array();
473 $disabled_submenu_all = array();
474
475 foreach ( $user_roles as $role ) {
476 $disabled_menu_all[] = $disabled_menu_[ $role ];
477 $disabled_submenu_all[] = $disabled_submenu_[ $role ];
478 }
479
480 // remove dashboard
481 if ( $disabled_menu_all !== '' || $disabled_submenu_all !== '' ) {
482
483 $redirect = FALSE;
484 foreach ( $user_roles as $role ) {
485 if ( _mw_adminimize_current_user_has_role( $role ) ) {
486 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
487 || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
488 ) {
489 $redirect = TRUE;
490 }
491 }
492 }
493
494 // Redirect option, if Dashboard is inactive
495 if ( $redirect ) {
496 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
497 '_mw_adminimize_db_redirect'
498 );
499 $_mw_adminimize_db_redirect_admin_url = get_option( 'siteurl' ) . '/wp-admin/';
500 switch ( $_mw_adminimize_db_redirect ) {
501 case 0:
502 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'profile.php';
503 break;
504 case 1:
505 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php';
506 break;
507 case 2:
508 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php?post_type=page';
509 break;
510 case 3:
511 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'post-new.php';
512 break;
513 case 4:
514 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'page-new.php';
515 break;
516 case 5:
517 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit-comments.php';
518 break;
519 case 6:
520 $_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect_txt' );
521 break;
522 }
523
524 $the_user = new WP_User( $user_ID );
525 reset( $menu );
526 $page = key( $menu );
527
528 $dashboard_core_string = esc_attr__( 'Dashboard' );
529 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
530 while (
531 ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
532 ) {
533 $page = key( $menu );
534 }
535
536 if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
537 unset( $menu[ $page ] );
538 }
539 reset( $menu );
540 $page = key( $menu );
541
542 while ( ! $the_user->has_cap( $menu[ $page ][ 1 ] ) && next( $menu ) ) {
543 $page = key( $menu );
544 }
545
546 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
547 wp_safe_redirect( $_mw_adminimize_db_redirect );
548 }
549 }
550 }
551 }
552
553 /**
554 * Set menu for settings
555 */
556 function _mw_adminimize_set_menu_option() {
557
558 // exclude super admin
559 if ( _mw_adminimize_exclude_super_admin() ) {
560 return NULL;
561 }
562
563 // Leave the settings screen from Adminimize to see all areas on settings.
564 if ( _mw_adminimize_exclude_settings_page() ) {
565 return;
566 }
567
568 global $menu, $submenu;
569
570 if ( ! isset( $menu ) || empty( $menu ) ) {
571 return;
572 }
573
574 _mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
575 _mw_adminimize_debug( $submenu, 'Adminimize, WordPress Sub-Menu:' );
576
577 $disabled_menu_ = array();
578 $disabled_submenu_ = array();
579 $user = wp_get_current_user();
580 $user_roles = $user->roles;
581 _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
582
583 foreach ( $user_roles as $role ) {
584 $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
585 'mw_adminimize_disabled_menu_' . $role . '_items'
586 );
587 $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
588 'mw_adminimize_disabled_submenu_' . $role . '_items'
589 );
590 }
591
592 $mw_adminimize_menu = array();
593 $mw_adminimize_submenu = array();
594
595 // Set admin-menu.
596 foreach ( $user_roles as $role ) {
597 if ( in_array( $role, $user->roles, TRUE )
598 && _mw_adminimize_current_user_has_role( $role )
599 ) {
600 // Create array about all items with all affected roles.
601 foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
602 $mw_adminimize_menu[] = $menu_item;
603 }
604 foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
605 $mw_adminimize_submenu[] = $submenu_item;
606 }
607 }
608 }
609
610 // Support Multiple Roles for users.
611 // Leave only the items, there are active on each roles of the users.
612 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
613 $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
614 $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
615 } else {
616 // Alternative filter the array to remove duplicates, much faster.
617 $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
618 $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
619 }
620 _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
621 _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
622
623 /**
624 * @ToDo Remove it after feedback from users.
625 *
626 // Fallback on users.php on all user roles smaller admin.
627 if ( in_array( 'users.php', $mw_adminimize_menu, TRUE ) ) {
628 $mw_adminimize_menu[] = 'profile.php';
629 }
630 */
631 foreach ( $menu as $key => $item ) {
632
633 // Menu
634 if ( isset( $item[ 2 ] ) ) {
635 $menu_slug = $item[ 2 ];
636 // Check, if the Menu item in the current user role settings?
637 if ( in_array( $menu_slug, $mw_adminimize_menu, TRUE )
638 ) {
639 remove_menu_page( $menu_slug );
640 // Prevent access to the page with the slug, there was inactive.
641 _mw_adminimize_check_page_access( $menu_slug );
642 }
643
644 // Sub Menu Settings.
645 if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
646 foreach ( (array) $submenu[ $menu_slug ] as $subindex => $subitem ) {
647 // Check, if is Sub Menu item in the user role settings?
648 if (
649 isset( $mw_adminimize_submenu )
650 && _mw_adminimize_in_arrays(
651 array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
652 $mw_adminimize_submenu
653 )
654 ) {
655 remove_submenu_page( $menu_slug, $subitem[ 2 ] );
656 // Prevent access to the page with the slug, there was inactive.
657 _mw_adminimize_check_page_access( $subitem[ 2 ] );
658 }
659 }
660 }
661 }
662 }
663
664 }
665
666 /**
667 * Set global options in backend in all areas.
668 */
669 function _mw_adminimize_set_global_option() {
670
671 // exclude super admin
672 if ( _mw_adminimize_exclude_super_admin() ) {
673 return NULL;
674 }
675
676 // Leave the settings screen from Adminimize to see all areas on settings.
677 if ( _mw_adminimize_exclude_settings_page() ) {
678 return;
679 }
680
681 $user_roles = _mw_adminimize_get_all_user_roles();
682 $_mw_adminimize_admin_head = '';
683 $disabled_global_option = array();
684 $disabled_global_option_ = array();
685 $user = wp_get_current_user();
686
687 // Get settings for each role.
688 foreach ( $user_roles as $role ) {
689 $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
690 'mw_adminimize_disabled_global_option_' . $role . '_items'
691 );
692 }
693
694 // Write global options in an var.
695 foreach ( $user_roles as $role ) {
696 if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
697
698 // Create array about all items with all affected roles, important for multiple roles.
699 foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
700 $disabled_global_option[] = $global_item;
701 }
702 }
703 }
704
705 // Support Multiple Roles for users.
706 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
707 $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
708 }
709 $global_options = implode( ', ', $disabled_global_option );
710
711 if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
712 global $_wp_admin_css_colors;
713 $_wp_admin_css_colors = 0;
714 }
715 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
716 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
717
718 if ( '' !== $global_options ) {
719 echo $_mw_adminimize_admin_head;
720 }
721 }
722
723 /**
724 * Set metabox options from database an area post.
725 */
726 function _mw_adminimize_set_metabox_post_option() {
727
728 // exclude super admin
729 if ( _mw_adminimize_exclude_super_admin() ) {
730 return;
731 }
732
733 // Leave the settings screen from Adminimize to see all areas on settings.
734 if ( _mw_adminimize_exclude_settings_page() ) {
735 return;
736 }
737
738 $user_roles = _mw_adminimize_get_all_user_roles();
739 $_mw_adminimize_admin_head = '';
740 $metaboxes = '';
741
742 foreach ( $user_roles as $role ) {
743 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
744 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
745 );
746
747 if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
748 $disabled_metaboxes_post_[ $role ][ '0' ] = '';
749 }
750
751 // New since version 1.7.8.
752 $user = wp_get_current_user();
753 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
754 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
755 && is_array(
756 $disabled_metaboxes_post_[ $role ]
757 )
758 ) {
759 $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
760 }
761 }
762 }
763
764 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
765 $_mw_adminimize_admin_head .= '<style type="text/css">' .
766 $metaboxes . ' {display:none !important;}</style>' . "\n";
767
768 if ( ! empty( $metaboxes ) ) {
769 echo $_mw_adminimize_admin_head;
770 }
771 }
772
773 /**
774 * Set metabox options from database an area page.
775 */
776 function _mw_adminimize_set_metabox_page_option() {
777
778 // exclude super admin
779 if ( _mw_adminimize_exclude_super_admin() ) {
780 return NULL;
781 }
782
783 // Leave the settings screen from Adminimize to see all areas on settings.
784 if ( _mw_adminimize_exclude_settings_page() ) {
785 return;
786 }
787
788 $user_roles = _mw_adminimize_get_all_user_roles();
789 $_mw_adminimize_admin_head = '';
790 $metaboxes = '';
791
792 foreach ( $user_roles as $role ) {
793 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
794 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
795 );
796
797 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
798 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
799 }
800
801 // New since version 1.7.8.
802 $user = wp_get_current_user();
803 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
804 if ( _mw_adminimize_current_user_has_role( $role )
805 && isset( $disabled_metaboxes_page_[ $role ] )
806 && is_array( $disabled_metaboxes_page_[ $role ] )
807 ) {
808 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
809 }
810 }
811 }
812
813 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
814 $_mw_adminimize_admin_head .= '<style type="text/css">' .
815 $metaboxes . ' {display:none !important;}</style>' . "\n";
816
817 if ( ! empty( $metaboxes ) ) {
818 echo $_mw_adminimize_admin_head;
819 }
820 }
821
822 /**
823 * Set metabox options from database an area post.
824 */
825 function _mw_adminimize_set_metabox_cp_option() {
826
827 // exclude super admin
828 if ( _mw_adminimize_exclude_super_admin() ) {
829 return NULL;
830 }
831
832 // Leave the settings screen from Adminimize to see all areas on settings.
833 if ( _mw_adminimize_exclude_settings_page() ) {
834 return;
835 }
836
837 $post_id = 0;
838 if ( isset( $_GET[ 'post' ] ) ) {
839 $post_id = (int) $_GET[ 'post' ];
840 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
841 $post_id = (int) $_POST[ 'post_ID' ];
842 }
843
844 $current_post_type = $GLOBALS[ 'post_type' ];
845 if ( ! isset( $current_post_type ) ) {
846 $current_post_type = get_post_type( $post_id );
847 }
848
849 if ( ! isset( $current_post_type ) || ! $current_post_type ) {
850 $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
851 }
852
853 // set hard to post
854 if ( ! $current_post_type ) {
855 $current_post_type = 'post';
856 }
857
858 $user_roles = _mw_adminimize_get_all_user_roles();
859 $_mw_adminimize_admin_head = '';
860 $metaboxes = '';
861
862 foreach ( $user_roles as $role ) {
863 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
864 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
865 );
866
867 if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
868 $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
869 }
870
871 $user = wp_get_current_user();
872 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
873 if ( _mw_adminimize_current_user_has_role( $role )
874 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
875 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
876 ) {
877 $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
878 }
879 }
880 }
881
882 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
883 $_mw_adminimize_admin_head .= '<style type="text/css">' .
884 $metaboxes . ' {display:none !important;}</style>' . "\n";
885
886 if ( ! empty( $metaboxes ) ) {
887 echo $_mw_adminimize_admin_head;
888 }
889 }
890
891 /**
892 * Set link options in area links of back end.
893 */
894 function _mw_adminimize_set_link_option() {
895
896 // exclude super admin
897 if ( _mw_adminimize_exclude_super_admin() ) {
898 return NULL;
899 }
900
901 // Leave the settings screen from Adminimize to see all areas on settings.
902 if ( _mw_adminimize_exclude_settings_page() ) {
903 return;
904 }
905
906 $user_roles = _mw_adminimize_get_all_user_roles();
907 $_mw_adminimize_admin_head = '';
908
909 foreach ( $user_roles as $role ) {
910 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
911 'mw_adminimize_disabled_link_option_' . $role . '_items'
912 );
913 }
914
915 foreach ( $user_roles as $role ) {
916 if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
917 $disabled_link_option_[ $role ][ '0' ] = '';
918 }
919 }
920
921 $link_options = '';
922 foreach ( $user_roles as $role ) {
923 $user = wp_get_current_user();
924 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
925 if ( _mw_adminimize_current_user_has_role( $role )
926 && isset( $disabled_link_option_[ $role ] )
927 && is_array( $disabled_link_option_[ $role ] )
928 ) {
929 $link_options = implode( ',', $disabled_link_option_[ $role ] );
930 }
931 }
932 }
933
934 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
935 $_mw_adminimize_admin_head .= '<style type="text/css">' .
936 $link_options . ' {display:none !important;}</style>' . "\n";
937
938 if ( ! empty( $link_options ) ) {
939 echo $_mw_adminimize_admin_head;
940 }
941 }
942
943 /**
944 * Remove objects on wp nav menu.
945 */
946 function _mw_adminimize_set_nav_menu_option() {
947
948 // exclude super admin
949 if ( _mw_adminimize_exclude_super_admin() ) {
950 return NULL;
951 }
952
953 // Leave the settings screen from Adminimize to see all areas on settings.
954 if ( _mw_adminimize_exclude_settings_page() ) {
955 return;
956 }
957
958 $user_roles = _mw_adminimize_get_all_user_roles();
959 $_mw_adminimize_admin_head = '';
960
961 foreach ( $user_roles as $role ) {
962 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
963 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
964 );
965 }
966
967 foreach ( $user_roles as $role ) {
968 if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
969 $disabled_nav_menu_option_[ $role ][ '0' ] = '';
970 }
971 }
972
973 $nav_menu_options = '';
974 foreach ( $user_roles as $role ) {
975 $user = wp_get_current_user();
976 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
977 if ( _mw_adminimize_current_user_has_role( $role )
978 && isset( $disabled_nav_menu_option_[ $role ] )
979 && is_array( $disabled_nav_menu_option_[ $role ] )
980 ) {
981 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
982 }
983 }
984 }
985
986 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
987 $_mw_adminimize_admin_head .= '<style type="text/css">' .
988 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
989
990 if ( $nav_menu_options ) {
991 echo $_mw_adminimize_admin_head;
992 }
993 }
994
995 /**
996 * Remove areas in Widget Settings
997 */
998 function _mw_adminimize_set_widget_option() {
999
1000 // exclude super admin
1001 if ( _mw_adminimize_exclude_super_admin() ) {
1002 return NULL;
1003 }
1004
1005 // Leave the settings screen from Adminimize to see all areas on settings.
1006 if ( _mw_adminimize_exclude_settings_page() ) {
1007 return;
1008 }
1009
1010 $user_roles = _mw_adminimize_get_all_user_roles();
1011 $_mw_adminimize_admin_head = '';
1012
1013 foreach ( $user_roles as $role ) {
1014 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
1015 'mw_adminimize_disabled_widget_option_' . $role . '_items'
1016 );
1017 }
1018
1019 foreach ( $user_roles as $role ) {
1020 if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
1021 $disabled_widget_option_[ $role ][ '0' ] = '';
1022 }
1023 }
1024
1025 $widget_options = '';
1026 foreach ( $user_roles as $role ) {
1027 $user = wp_get_current_user();
1028 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1029 if ( _mw_adminimize_current_user_has_role( $role )
1030 && isset( $disabled_widget_option_[ $role ] )
1031 && is_array( $disabled_widget_option_[ $role ] )
1032 ) {
1033 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1034 }
1035 }
1036 }
1037
1038 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1039 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1040 $widget_options . ' {display: none !important;}</style>' . "\n";
1041
1042 if ( $widget_options ) {
1043 echo $_mw_adminimize_admin_head;
1044 }
1045 }
1046
1047 /**
1048 * Print small user-info.
1049 */
1050 function _mw_adminimize_small_user_info() {
1051
1052 ?>
1053 <div id="small_user_info">
1054 <p>
1055 <a href="<?php echo wp_nonce_url(
1056 site_url( 'wp-login.php?action=logout' ),
1057 'log-out'
1058 ) ?>"
1059 title="<?php esc_attr_e( 'Log Out' ) ?>"><?php esc_attr_e( 'Log Out' ); ?></a>
1060 </p>
1061 </div>
1062 <?php
1063 }
1064
1065 // include helping functions
1066 require_once 'inc-setup/helping_hands.php';
1067
1068 // Include message class.
1069 require_once 'inc-setup/messages.php';
1070
1071 // inc. settings page
1072 require_once 'adminimize_page.php';
1073
1074 // dashboard options
1075 require_once 'inc-setup/dashboard.php';
1076
1077 // widget options
1078 require_once 'inc-setup/widget.php';
1079 require_once 'inc-setup/footer.php';
1080 require_once 'inc-setup/admin-footer.php';
1081
1082 // global settings
1083 // @TODO Testing, not ready for productive
1084 //require_once( 'inc-options/settings_notice.php' );
1085
1086 // remove admin bar
1087 require_once 'inc-setup/remove-admin-bar.php';
1088
1089 // admin bar helper, setup
1090 // work always in frontend
1091 require_once 'inc-setup/admin-bar-items.php';
1092
1093 // meta boxes helper, setup
1094 // @TODO Meta Boxes: not ready for productive systems.
1095 //require_once( 'inc-setup/meta-boxes.php' );
1096
1097 // Remove Admin Notices.
1098 require_once 'inc-setup/remove-admin-notices.php';
1099
1100 // Add Ex-Import functions.
1101 require_once 'inc-setup/export.php';
1102 require_once 'inc-setup/import.php';
1103
1104 /**
1105 * Add action link(s) to plugins page
1106 *
1107 * @param array $links
1108 * @param string $file
1109 *
1110 * @return string $links
1111 */
1112 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1113
1114 /* create link */
1115 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1116 array_unshift(
1117 $links,
1118 sprintf(
1119 '<a href="options-general.php?page=%s">%s</a>',
1120 FB_ADMINIMIZE_BASENAME,
1121 esc_attr__( 'Settings' )
1122 )
1123 );
1124 }
1125
1126 return $links;
1127 }
1128
1129 /**
1130 * Add settings in plugin-admin-page.
1131 */
1132 function _mw_adminimize_add_settings_page() {
1133
1134 $pagehook = add_options_page(
1135 esc_attr__( 'Adminimize Options', 'adminimize' ),
1136 esc_attr__( 'Adminimize', 'adminimize' ),
1137 'manage_options',
1138 'adminimize-options',
1139 '_mw_adminimize_options'
1140 );
1141
1142 if ( ! is_network_admin() ) {
1143 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1144 }
1145 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1146 }
1147
1148 /**
1149 * Enqueue script and styles for the settings page.
1150 */
1151 function _mw_adminimize_on_load_page() {
1152
1153 // Load translation files on options page.
1154 _mw_adminimize_textdomain();
1155
1156 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1157
1158 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1159 wp_enqueue_style( 'adminimize-style' );
1160
1161 wp_register_script(
1162 'adminimize-settings-script',
1163 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1164 array( 'jquery' ),
1165 '',
1166 TRUE
1167 );
1168 wp_enqueue_script( 'adminimize-settings-script' );
1169 }
1170
1171 /**
1172 * Set theme for users
1173 * Kill with version 1.7.18
1174 * @ToDo Remove for the feature releases.
1175 */
1176 function _mw_adminimize_set_theme() {
1177
1178 if ( ! current_user_can( 'edit_users' ) ) {
1179 wp_die( esc_attr__( 'Cheatin&#8217; uh?' ) );
1180 }
1181
1182 $user_ids = (array) $_POST[ 'mw_adminimize_theme_items' ];
1183 $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
1184
1185 if ( ! $user_ids ) {
1186 return FALSE;
1187 }
1188
1189 foreach ( $user_ids as $user_id ) {
1190 update_user_meta( $user_id, 'admin_color', $admin_color );
1191 }
1192
1193 return TRUE;
1194 }
1195
1196 /**
1197 * Get setting value for each options key.
1198 *
1199 * @param string|bool $key
1200 *
1201 * @return string
1202 */
1203 function _mw_adminimize_get_option_value( $key = FALSE ) {
1204
1205 $adminimizeoptions = FALSE;
1206 if ( ! _mw_adminimize_exclude_settings_page() ) {
1207 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1208 }
1209
1210 if ( FALSE === $adminimizeoptions ) {
1211 // check for use on multisite
1212 if ( _mw_adminimize_is_active_on_multisite() ) {
1213 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1214 } else {
1215 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1216 }
1217 wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1218 }
1219
1220 if ( ! $key ) {
1221 return $adminimizeoptions;
1222 }
1223
1224 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1225 }
1226
1227 /**
1228 * Update options.
1229 *
1230 * @param array $options
1231 *
1232 * @return bool
1233 */
1234 function _mw_adminimize_update_option( $options ) {
1235
1236 if ( ! current_user_can( 'manage_options' ) ) {
1237 return FALSE;
1238 }
1239
1240 // Remove slashes always.
1241 foreach ( $options as $key => $value ) {
1242 $options[ $key ] = stripslashes_deep( $value );
1243 }
1244
1245 // Kill the cache for the settings page.
1246 wp_cache_delete( 'mw_adminimize' );
1247 if ( _mw_adminimize_is_active_on_multisite() ) {
1248 update_site_option( 'mw_adminimize', $options );
1249 } else {
1250 update_option( 'mw_adminimize', $options );
1251 }
1252 wp_cache_add( 'mw_adminimize', $options );
1253
1254 return TRUE;
1255 }
1256
1257 /**
1258 * Update options in database
1259 */
1260 function _mw_adminimize_update() {
1261
1262 $user_roles = _mw_adminimize_get_all_user_roles();
1263 $args = array( 'public' => TRUE, '_builtin' => FALSE );
1264 $post_types = get_post_types( $args );
1265
1266 // Admin Bar Back end settings
1267 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
1268 'mw_adminimize_admin_bar_nodes'
1269 );
1270 // admin bar back end options
1271 foreach ( $user_roles as $role ) {
1272 // admin bar back end options
1273 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
1274 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
1275 } else {
1276 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1277 }
1278 }
1279
1280 // Plugin Self Settings.
1281 if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1282 $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1283 } else {
1284 $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1285 }
1286
1287 if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1288 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1289 } else {
1290 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1291 }
1292
1293 if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1294 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1295 } else {
1296 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1297 }
1298
1299 if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1300 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1301 } else {
1302 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1303 }
1304
1305 // Admin Bar Front end settings
1306 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1307 'mw_adminimize_admin_bar_frontend_nodes'
1308 );
1309 // admin bar front end options
1310 foreach ( $user_roles as $role ) {
1311 // admin bar front-end options
1312 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1313 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1314 } else {
1315 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
1316 }
1317 }
1318
1319 if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
1320 $adminimizeoptions[ '_mw_adminimize_user_info' ] = (int) $_POST[ '_mw_adminimize_user_info' ];
1321 } else {
1322 $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
1323 }
1324
1325 if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
1326 $adminimizeoptions[ '_mw_adminimize_footer' ] = (int) $_POST[ '_mw_adminimize_footer' ];
1327 } else {
1328 $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
1329 }
1330
1331 if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
1332 $adminimizeoptions[ '_mw_adminimize_header' ] = (int) $_POST[ '_mw_adminimize_header' ];
1333 } else {
1334 $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
1335 }
1336
1337 if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
1338 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = (int) $_POST[ '_mw_adminimize_exclude_super_admin' ];
1339 } else {
1340 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
1341 }
1342
1343 if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
1344 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = (int) $_POST[ '_mw_adminimize_tb_window' ];
1345 } else {
1346 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
1347 }
1348
1349 if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
1350 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = (int) $_POST[ '_mw_adminimize_cat_full' ];
1351 } else {
1352 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
1353 }
1354
1355 if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
1356 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = (int) $_POST[ '_mw_adminimize_db_redirect' ];
1357 } else {
1358 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
1359 }
1360
1361 if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
1362 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = (int) $_POST[ '_mw_adminimize_ui_redirect' ];
1363 } else {
1364 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
1365 }
1366
1367 if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
1368 $adminimizeoptions[ '_mw_adminimize_advice' ] = (int) $_POST[ '_mw_adminimize_advice' ];
1369 } else {
1370 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1371 }
1372
1373 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1374 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1375 $_POST[ '_mw_adminimize_advice_txt' ],
1376 array(
1377 'a' => array(
1378 'href' => array(),
1379 'title' => array()
1380 ),
1381 'br' => array(),
1382 'em' => array(),
1383 'strong' => array(),
1384 )
1385 );
1386 } else {
1387 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1388 }
1389
1390 if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
1391 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = (int) $_POST[ '_mw_adminimize_timestamp' ];
1392 } else {
1393 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
1394 }
1395
1396 if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
1397 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = esc_url( $_POST[ '_mw_adminimize_db_redirect_txt' ] );
1398 } else {
1399 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = '';
1400 }
1401
1402 // menu update
1403 foreach ( $user_roles as $role ) {
1404 if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
1405 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] =
1406 $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
1407 } else {
1408 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1409 }
1410
1411 if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
1412 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] =
1413 $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
1414 } else {
1415 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1416 }
1417 }
1418
1419 // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1420
1421 // own menu slug
1422 if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1423 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1424 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1425 );
1426 } else {
1427 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1428 }
1429 // own custom menu slug
1430 if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1431 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1432 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1433 );
1434 } else {
1435 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1436 }
1437
1438 // global_options, metaboxes update
1439 foreach ( $user_roles as $role ) {
1440
1441 // global options
1442 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1443 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1444 $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1445 } else {
1446 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1447 }
1448
1449 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
1450 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] =
1451 $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
1452 } else {
1453 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1454 }
1455
1456 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
1457 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] =
1458 $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
1459 } else {
1460 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1461 }
1462
1463 foreach ( $post_types as $post_type ) {
1464 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] ) ) {
1465 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] =
1466 $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ];
1467 } else {
1468 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1469 }
1470 }
1471
1472 if ( isset( $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] ) ) {
1473 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] =
1474 $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ];
1475 } else {
1476 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = array();
1477 }
1478
1479 // wp nav menu options
1480 if ( isset( $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] ) ) {
1481 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] =
1482 $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ];
1483 } else {
1484 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = array();
1485 }
1486
1487 // widget options
1488 if ( isset( $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] ) ) {
1489 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] =
1490 $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ];
1491 } else {
1492 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = array();
1493 }
1494
1495 // wp dashboard option
1496 if ( isset( $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] ) ) {
1497 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] =
1498 $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ];
1499 } else {
1500 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = array();
1501 }
1502 }
1503
1504 // own options
1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1506 $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1507 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1508 );
1509 } else {
1510 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1511 }
1512
1513 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1515 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1516 );
1517 } else {
1518 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1519 }
1520
1521 // own post options
1522 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1524 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1525 );
1526 } else {
1527 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1528 }
1529
1530 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1532 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1533 );
1534 } else {
1535 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1536 }
1537
1538 // own page options
1539 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1541 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1542 );
1543 } else {
1544 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1545 }
1546
1547 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1549 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1550 );
1551 } else {
1552 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1553 }
1554
1555 // own custom post options
1556 foreach ( $post_types as $post_type ) {
1557 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1559 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1560 );
1561 } else {
1562 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1563 }
1564
1565 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1567 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1568 );
1569 } else {
1570 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1571 }
1572 }
1573
1574 // own link options
1575 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1577 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1578 );
1579 } else {
1580 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1581 }
1582
1583 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1585 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1586 );
1587 } else {
1588 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1589 }
1590
1591 // wp nav menu options
1592 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1594 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1595 );
1596 } else {
1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1598 }
1599
1600 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1602 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1603 );
1604 } else {
1605 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1606 }
1607
1608 // widget options
1609 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1611 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1612 );
1613 } else {
1614 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1615 }
1616
1617 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1619 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1620 );
1621 } else {
1622 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1623 }
1624
1625 // own dashboard options
1626 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1628 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1629 );
1630 } else {
1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1632 }
1633
1634 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1636 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1637 );
1638 } else {
1639 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1640 }
1641
1642 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_option_value(
1643 'mw_adminimize_dashboard_widgets'
1644 );
1645
1646 if ( isset( $GLOBALS[ 'menu' ] ) ) {
1647 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $GLOBALS[ 'menu' ];
1648 }
1649 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1650 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1651 }
1652
1653 // update
1654 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1655
1656 $myErrors = new _mw_adminimize_message_class();
1657 if ( $update_status ) {
1658 $message = $myErrors->get_error(
1659 '_mw_adminimize_update'
1660 );
1661 } else {
1662 $message = $myErrors->get_error(
1663 '_mw_adminimize_access_denied'
1664 );
1665 }
1666 echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1667
1668 return TRUE;
1669 }
1670
1671 /**
1672 * Delete options in database
1673 */
1674 function _mw_adminimize_uninstall() {
1675
1676 wp_cache_delete( 'mw_adminimize' );
1677 delete_site_option( 'mw_adminimize' );
1678 delete_option( 'mw_adminimize' );
1679 }
1680
1681 /**
1682 * Install options in database
1683 */
1684 function _mw_adminimize_install() {
1685
1686 if ( ! is_admin() ) {
1687 return;
1688 }
1689
1690 // If is AJAX Call.
1691 if ( defined('DOING_AJAX') && DOING_AJAX ) {
1692 return;
1693 }
1694
1695 global $menu, $submenu;
1696
1697 $user_roles = _mw_adminimize_get_all_user_roles();
1698 $adminimizeoptions = array();
1699
1700 foreach ( $user_roles as $role ) {
1701 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1702 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1703 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1704 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1705 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1706 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1707 $args = array(
1708 'public' => TRUE,
1709 '_builtin' => FALSE,
1710 );
1711 foreach ( get_post_types( $args ) as $post_type ) {
1712 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1713 }
1714 }
1715
1716 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
1717 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
1718
1719 if ( _mw_adminimize_is_active_on_multisite() ) {
1720 add_site_option( 'mw_adminimize', $adminimizeoptions );
1721 } else {
1722 add_option( 'mw_adminimize', $adminimizeoptions );
1723 }
1724 wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1725 }
1726