PluginProbe
Adminimize / 1.11.4
Adminimize v1.11.4
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.4, at adminimize.php

1,694 lines 52.0 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.4
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-12-14
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_tmp = get_current_screen();
114 }
115
116 if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
117 $screen = $screen_tmp->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( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
382 /**
383 * Return string tinymce.
384 * Necessary for php 5.2 usage :(; not possible to use an anonymous function.
385 *
386 * @return string
387 */
388 function _mw_admininimize_return_tinmyce() {
389 return 'tinymce';
390 }
391 }
392
393 // Remove media buttons
394 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
395 || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
396 ) {
397 remove_action( 'media_buttons', 'media_buttons' );
398 }
399 }
400 }
401
402 // set meta-box post option
403 if ( in_array( $pagenow, $def_post_pages, TRUE ) && in_array( $current_post_type, $def_post_types, TRUE ) ) {
404 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
405 }
406 // set meta-box page option
407 if ( in_array( $pagenow, $def_page_pages, TRUE ) && in_array( $current_post_type, $def_page_types, TRUE ) ) {
408 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
409 }
410 // set custom post type options
411 if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
412 && in_array( $current_post_type, $def_custom_types, TRUE )
413 ) {
414 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
415 }
416 // set link option
417 if ( in_array( $pagenow, $link_pages, TRUE ) ) {
418 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
419 }
420 // set wp nav menu options
421 if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
422 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
423 }
424 // set widget options
425 if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
426 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
427 }
428 }
429
430 // Change menu via settings of Adminimize.
431 //add_filter( 'custom_menu_order', '__return_true' );
432 add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
433
434 // global_options
435 add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
436 // on admin init
437 if ( is_admin() ) {
438 add_action( 'admin_init', '_mw_adminimize_admin_init' );
439 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
440 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
441 }
442
443 register_activation_hook( __FILE__, '_mw_adminimize_install' );
444 register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
445
446 /**
447 * Remove the dashboard
448 */
449 function _mw_adminimize_remove_dashboard() {
450
451 // exclude super admin
452 if ( _mw_adminimize_exclude_super_admin() ) {
453 return;
454 }
455
456 // Leave the settings screen from Adminimize to see all areas on settings.
457 if ( _mw_adminimize_exclude_settings_page() ) {
458 return;
459 }
460
461 global $menu, $user_ID;
462
463 $disabled_menu_ = array();
464 $disabled_submenu_ = array();
465 $user_roles = _mw_adminimize_get_all_user_roles();
466
467 foreach ( $user_roles as $role ) {
468 $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
469 'mw_adminimize_disabled_menu_' . $role . '_items'
470 );
471 $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
472 'mw_adminimize_disabled_submenu_' . $role . '_items'
473 );
474 }
475
476 $disabled_menu_all = array();
477 $disabled_submenu_all = array();
478
479 foreach ( $user_roles as $role ) {
480 $disabled_menu_all[] = $disabled_menu_[ $role ];
481 $disabled_submenu_all[] = $disabled_submenu_[ $role ];
482 }
483
484 // remove dashboard
485 if ( $disabled_menu_all !== '' || $disabled_submenu_all !== '' ) {
486
487 $redirect = FALSE;
488 foreach ( $user_roles as $role ) {
489 if ( _mw_adminimize_current_user_has_role( $role ) ) {
490 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
491 || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
492 ) {
493 $redirect = TRUE;
494 }
495 }
496 }
497
498 // Redirect option, if Dashboard is inactive
499 if ( $redirect ) {
500 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
501 '_mw_adminimize_db_redirect'
502 );
503 $_mw_adminimize_db_redirect_admin_url = get_option( 'siteurl' ) . '/wp-admin/';
504 switch ( $_mw_adminimize_db_redirect ) {
505 case 0:
506 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'profile.php';
507 break;
508 case 1:
509 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php';
510 break;
511 case 2:
512 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php?post_type=page';
513 break;
514 case 3:
515 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'post-new.php';
516 break;
517 case 4:
518 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'page-new.php';
519 break;
520 case 5:
521 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit-comments.php';
522 break;
523 case 6:
524 $_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect_txt' );
525 break;
526 }
527
528 $the_user = new WP_User( $user_ID );
529 reset( $menu );
530 $page = key( $menu );
531
532 $dashboard_core_string = esc_attr__( 'Dashboard' );
533 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
534 while (
535 ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
536 ) {
537 $page = key( $menu );
538 }
539
540 if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
541 unset( $menu[ $page ] );
542 }
543 reset( $menu );
544 $page = key( $menu );
545
546 while ( ! $the_user->has_cap( $menu[ $page ][ 1 ] ) && next( $menu ) ) {
547 $page = key( $menu );
548 }
549
550 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
551 wp_safe_redirect( $_mw_adminimize_db_redirect );
552 }
553 }
554 }
555 }
556
557 /**
558 * Set menu for settings
559 */
560 function _mw_adminimize_set_menu_option() {
561
562 // exclude super admin
563 if ( _mw_adminimize_exclude_super_admin() ) {
564 return NULL;
565 }
566
567 // Leave the settings screen from Adminimize to see all areas on settings.
568 if ( _mw_adminimize_exclude_settings_page() ) {
569 return;
570 }
571
572 global $menu, $submenu;
573
574 if ( ! isset( $menu ) || empty( $menu ) ) {
575 return;
576 }
577
578 _mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
579 _mw_adminimize_debug( $submenu, 'Adminimize, WordPress Sub-Menu:' );
580
581 $disabled_menu_ = array();
582 $disabled_submenu_ = array();
583 $user = wp_get_current_user();
584 $user_roles = $user->roles;
585 _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
586
587 foreach ( $user_roles as $role ) {
588 $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
589 'mw_adminimize_disabled_menu_' . $role . '_items'
590 );
591 $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
592 'mw_adminimize_disabled_submenu_' . $role . '_items'
593 );
594 }
595
596 $mw_adminimize_menu = array();
597 $mw_adminimize_submenu = array();
598
599 // Set admin-menu.
600 foreach ( $user_roles as $role ) {
601 if ( in_array( $role, $user->roles, TRUE )
602 && _mw_adminimize_current_user_has_role( $role )
603 ) {
604 // Create array about all items with all affected roles.
605 foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
606 $mw_adminimize_menu[] = $menu_item;
607 }
608 foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
609 $mw_adminimize_submenu[] = $submenu_item;
610 }
611 }
612 }
613
614 // Support Multiple Roles for users.
615 // Leave only the items, there are active on each roles of the users.
616 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
617 $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
618 $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
619 } else {
620 // Alternative filter the array to remove duplicates, much faster.
621 $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
622 $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
623 }
624 _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
625 _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
626
627 foreach ( $menu as $key => $item ) {
628
629 _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
630
631 // Menu
632 if ( isset( $item[ 2 ] ) ) {
633 $menu_slug = $item[ 2 ];
634 // Check, if the Menu item in the current user role settings?
635 if ( in_array( $menu_slug, $mw_adminimize_menu, false )
636 ) {
637 remove_menu_page( $menu_slug );
638 // Prevent access to the page with the slug, there was inactive.
639 _mw_adminimize_check_page_access( $menu_slug );
640 }
641
642 // Sub Menu Settings.
643 if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
644 foreach ( (array) $submenu[ $menu_slug ] as $subindex => $subitem ) {
645 // Check, if is Sub Menu item in the user role settings?
646 if (
647 isset( $mw_adminimize_submenu )
648 && _mw_adminimize_in_arrays(
649 array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
650 $mw_adminimize_submenu
651 )
652 ) {
653 remove_submenu_page( $menu_slug, $subitem[ 2 ] );
654 // Prevent access to the page with the slug, there was inactive.
655 _mw_adminimize_check_page_access( $subitem[ 2 ] );
656 }
657 }
658 }
659 }
660 }
661
662 }
663
664 /**
665 * Set global options in backend in all areas.
666 */
667 function _mw_adminimize_set_global_option() {
668
669 // exclude super admin
670 if ( _mw_adminimize_exclude_super_admin() ) {
671 return NULL;
672 }
673
674 // Leave the settings screen from Adminimize to see all areas on settings.
675 if ( _mw_adminimize_exclude_settings_page() ) {
676 return;
677 }
678
679 $user_roles = _mw_adminimize_get_all_user_roles();
680 $_mw_adminimize_admin_head = '';
681 $disabled_global_option = array();
682 $disabled_global_option_ = array();
683 $user = wp_get_current_user();
684
685 // Get settings for each role.
686 foreach ( $user_roles as $role ) {
687 $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
688 'mw_adminimize_disabled_global_option_' . $role . '_items'
689 );
690 }
691
692 // Write global options in an var.
693 foreach ( $user_roles as $role ) {
694 if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
695
696 // Create array about all items with all affected roles, important for multiple roles.
697 foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
698 $disabled_global_option[] = $global_item;
699 }
700 }
701 }
702
703 // Support Multiple Roles for users.
704 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
705 $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
706 }
707 $global_options = implode( ', ', $disabled_global_option );
708
709 if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
710 global $_wp_admin_css_colors;
711 $_wp_admin_css_colors = 0;
712 }
713 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
714 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
715
716 if ( '' !== $global_options ) {
717 echo $_mw_adminimize_admin_head;
718 }
719 }
720
721 /**
722 * Set metabox options from database an area post.
723 */
724 function _mw_adminimize_set_metabox_post_option() {
725
726 // exclude super admin
727 if ( _mw_adminimize_exclude_super_admin() ) {
728 return;
729 }
730
731 // Leave the settings screen from Adminimize to see all areas on settings.
732 if ( _mw_adminimize_exclude_settings_page() ) {
733 return;
734 }
735
736 $user_roles = _mw_adminimize_get_all_user_roles();
737 $_mw_adminimize_admin_head = '';
738 $metaboxes = '';
739
740 foreach ( $user_roles as $role ) {
741 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
742 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
743 );
744
745 if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
746 $disabled_metaboxes_post_[ $role ][ '0' ] = '';
747 }
748
749 // New since version 1.7.8.
750 $user = wp_get_current_user();
751 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
752 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
753 && is_array(
754 $disabled_metaboxes_post_[ $role ]
755 )
756 ) {
757 $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
758 }
759 }
760 }
761
762 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
763 $_mw_adminimize_admin_head .= '<style type="text/css">' .
764 $metaboxes . ' {display:none !important;}</style>' . "\n";
765
766 if ( ! empty( $metaboxes ) ) {
767 echo $_mw_adminimize_admin_head;
768 }
769 }
770
771 /**
772 * Set metabox options from database an area page.
773 */
774 function _mw_adminimize_set_metabox_page_option() {
775
776 // exclude super admin
777 if ( _mw_adminimize_exclude_super_admin() ) {
778 return NULL;
779 }
780
781 // Leave the settings screen from Adminimize to see all areas on settings.
782 if ( _mw_adminimize_exclude_settings_page() ) {
783 return;
784 }
785
786 $user_roles = _mw_adminimize_get_all_user_roles();
787 $_mw_adminimize_admin_head = '';
788 $metaboxes = '';
789
790 foreach ( $user_roles as $role ) {
791 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
792 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
793 );
794
795 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
796 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
797 }
798
799 // New since version 1.7.8.
800 $user = wp_get_current_user();
801 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
802 if ( _mw_adminimize_current_user_has_role( $role )
803 && isset( $disabled_metaboxes_page_[ $role ] )
804 && is_array( $disabled_metaboxes_page_[ $role ] )
805 ) {
806 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
807 }
808 }
809 }
810
811 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
812 $_mw_adminimize_admin_head .= '<style type="text/css">' .
813 $metaboxes . ' {display:none !important;}</style>' . "\n";
814
815 if ( ! empty( $metaboxes ) ) {
816 echo $_mw_adminimize_admin_head;
817 }
818 }
819
820 /**
821 * Set metabox options from database an area post.
822 */
823 function _mw_adminimize_set_metabox_cp_option() {
824
825 // exclude super admin
826 if ( _mw_adminimize_exclude_super_admin() ) {
827 return NULL;
828 }
829
830 // Leave the settings screen from Adminimize to see all areas on settings.
831 if ( _mw_adminimize_exclude_settings_page() ) {
832 return;
833 }
834
835 $post_id = 0;
836 if ( isset( $_GET[ 'post' ] ) ) {
837 $post_id = (int) $_GET[ 'post' ];
838 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
839 $post_id = (int) $_POST[ 'post_ID' ];
840 }
841
842 $current_post_type = $GLOBALS[ 'post_type' ];
843 if ( ! isset( $current_post_type ) ) {
844 $current_post_type = get_post_type( $post_id );
845 }
846
847 if ( ! isset( $current_post_type ) || ! $current_post_type ) {
848 $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
849 }
850
851 // set hard to post
852 if ( ! $current_post_type ) {
853 $current_post_type = 'post';
854 }
855
856 $user_roles = _mw_adminimize_get_all_user_roles();
857 $_mw_adminimize_admin_head = '';
858 $metaboxes = '';
859
860 foreach ( $user_roles as $role ) {
861 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
862 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
863 );
864
865 if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
866 $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
867 }
868
869 $user = wp_get_current_user();
870 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
871 if ( _mw_adminimize_current_user_has_role( $role )
872 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
873 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
874 ) {
875 $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
876 }
877 }
878 }
879
880 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
881 $_mw_adminimize_admin_head .= '<style type="text/css">' .
882 $metaboxes . ' {display:none !important;}</style>' . "\n";
883
884 if ( ! empty( $metaboxes ) ) {
885 echo $_mw_adminimize_admin_head;
886 }
887 }
888
889 /**
890 * Set link options in area links of back end.
891 */
892 function _mw_adminimize_set_link_option() {
893
894 // exclude super admin
895 if ( _mw_adminimize_exclude_super_admin() ) {
896 return NULL;
897 }
898
899 // Leave the settings screen from Adminimize to see all areas on settings.
900 if ( _mw_adminimize_exclude_settings_page() ) {
901 return;
902 }
903
904 $user_roles = _mw_adminimize_get_all_user_roles();
905 $_mw_adminimize_admin_head = '';
906
907 foreach ( $user_roles as $role ) {
908 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
909 'mw_adminimize_disabled_link_option_' . $role . '_items'
910 );
911 }
912
913 foreach ( $user_roles as $role ) {
914 if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
915 $disabled_link_option_[ $role ][ '0' ] = '';
916 }
917 }
918
919 $link_options = '';
920 foreach ( $user_roles as $role ) {
921 $user = wp_get_current_user();
922 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
923 if ( _mw_adminimize_current_user_has_role( $role )
924 && isset( $disabled_link_option_[ $role ] )
925 && is_array( $disabled_link_option_[ $role ] )
926 ) {
927 $link_options = implode( ',', $disabled_link_option_[ $role ] );
928 }
929 }
930 }
931
932 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
933 $_mw_adminimize_admin_head .= '<style type="text/css">' .
934 $link_options . ' {display:none !important;}</style>' . "\n";
935
936 if ( ! empty( $link_options ) ) {
937 echo $_mw_adminimize_admin_head;
938 }
939 }
940
941 /**
942 * Remove objects on wp nav menu.
943 */
944 function _mw_adminimize_set_nav_menu_option() {
945
946 // exclude super admin
947 if ( _mw_adminimize_exclude_super_admin() ) {
948 return NULL;
949 }
950
951 // Leave the settings screen from Adminimize to see all areas on settings.
952 if ( _mw_adminimize_exclude_settings_page() ) {
953 return;
954 }
955
956 $user_roles = _mw_adminimize_get_all_user_roles();
957 $_mw_adminimize_admin_head = '';
958
959 foreach ( $user_roles as $role ) {
960 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
961 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
962 );
963 }
964
965 foreach ( $user_roles as $role ) {
966 if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
967 $disabled_nav_menu_option_[ $role ][ '0' ] = '';
968 }
969 }
970
971 $nav_menu_options = '';
972 foreach ( $user_roles as $role ) {
973 $user = wp_get_current_user();
974 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
975 if ( _mw_adminimize_current_user_has_role( $role )
976 && isset( $disabled_nav_menu_option_[ $role ] )
977 && is_array( $disabled_nav_menu_option_[ $role ] )
978 ) {
979 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
980 }
981 }
982 }
983
984 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
985 $_mw_adminimize_admin_head .= '<style type="text/css">' .
986 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
987
988 if ( $nav_menu_options ) {
989 echo $_mw_adminimize_admin_head;
990 }
991 }
992
993 /**
994 * Remove areas in Widget Settings
995 */
996 function _mw_adminimize_set_widget_option() {
997
998 // exclude super admin
999 if ( _mw_adminimize_exclude_super_admin() ) {
1000 return NULL;
1001 }
1002
1003 // Leave the settings screen from Adminimize to see all areas on settings.
1004 if ( _mw_adminimize_exclude_settings_page() ) {
1005 return;
1006 }
1007
1008 $user_roles = _mw_adminimize_get_all_user_roles();
1009 $_mw_adminimize_admin_head = '';
1010
1011 foreach ( $user_roles as $role ) {
1012 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
1013 'mw_adminimize_disabled_widget_option_' . $role . '_items'
1014 );
1015 }
1016
1017 foreach ( $user_roles as $role ) {
1018 if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
1019 $disabled_widget_option_[ $role ][ '0' ] = '';
1020 }
1021 }
1022
1023 $widget_options = '';
1024 foreach ( $user_roles as $role ) {
1025 $user = wp_get_current_user();
1026 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1027 if ( _mw_adminimize_current_user_has_role( $role )
1028 && isset( $disabled_widget_option_[ $role ] )
1029 && is_array( $disabled_widget_option_[ $role ] )
1030 ) {
1031 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1032 }
1033 }
1034 }
1035
1036 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1037 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1038 $widget_options . ' {display: none !important;}</style>' . "\n";
1039
1040 if ( $widget_options ) {
1041 echo $_mw_adminimize_admin_head;
1042 }
1043 }
1044
1045 /**
1046 * Print small user-info.
1047 */
1048 function _mw_adminimize_small_user_info() {
1049
1050 ?>
1051 <div id="small_user_info">
1052 <p>
1053 <a href="<?php echo wp_nonce_url(
1054 site_url( 'wp-login.php?action=logout' ),
1055 'log-out'
1056 ) ?>"
1057 title="<?php esc_attr_e( 'Log Out' ) ?>"><?php esc_attr_e( 'Log Out' ); ?></a>
1058 </p>
1059 </div>
1060 <?php
1061 }
1062
1063 // include helping functions
1064 require_once 'inc-setup/helping_hands.php';
1065
1066 // Include message class.
1067 require_once 'inc-setup/messages.php';
1068
1069 // inc. settings page
1070 require_once 'adminimize_page.php';
1071
1072 // dashboard options
1073 require_once 'inc-setup/dashboard.php';
1074
1075 // widget options
1076 require_once 'inc-setup/widget.php';
1077 require_once 'inc-setup/footer.php';
1078 require_once 'inc-setup/admin-footer.php';
1079
1080 // remove admin bar
1081 require_once 'inc-setup/remove-admin-bar.php';
1082
1083 // admin bar helper, setup
1084 // work always in frontend
1085 require_once 'inc-setup/admin-bar-items.php';
1086
1087 // meta boxes helper, setup
1088 // @TODO Meta Boxes: not ready for productive systems.
1089 //require_once( 'inc-setup/meta-boxes.php' );
1090
1091 // Remove Admin Notices.
1092 require_once 'inc-setup/remove-admin-notices.php';
1093
1094 // Add Ex-Import functions.
1095 require_once 'inc-setup/export.php';
1096 require_once 'inc-setup/import.php';
1097
1098 /**
1099 * Add action link(s) to plugins page
1100 *
1101 * @param array $links
1102 * @param string $file
1103 *
1104 * @return string $links
1105 */
1106 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1107
1108 /* create link */
1109 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1110 array_unshift(
1111 $links,
1112 sprintf(
1113 '<a href="options-general.php?page=adminimize-options">%s</a>',
1114 esc_attr__( 'Settings' )
1115 )
1116 );
1117 }
1118
1119 return $links;
1120 }
1121
1122 /**
1123 * Add settings in plugin-admin-page.
1124 */
1125 function _mw_adminimize_add_settings_page() {
1126
1127 $pagehook = add_options_page(
1128 esc_attr__( 'Adminimize Options', 'adminimize' ),
1129 esc_attr__( 'Adminimize', 'adminimize' ),
1130 'manage_options',
1131 'adminimize-options',
1132 '_mw_adminimize_options'
1133 );
1134
1135 if ( ! is_network_admin() ) {
1136 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1137 }
1138 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1139 }
1140
1141 /**
1142 * Enqueue script and styles for the settings page.
1143 */
1144 function _mw_adminimize_on_load_page() {
1145
1146 // Load translation files on options page.
1147 _mw_adminimize_textdomain();
1148
1149 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1150
1151 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1152 wp_enqueue_style( 'adminimize-style' );
1153
1154 wp_register_script(
1155 'adminimize-settings-script',
1156 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1157 array( 'jquery' ),
1158 '',
1159 TRUE
1160 );
1161 wp_enqueue_script( 'adminimize-settings-script' );
1162 }
1163
1164 /**
1165 * Get setting value for each options key.
1166 *
1167 * @param string|bool $key
1168 *
1169 * @return string
1170 */
1171 function _mw_adminimize_get_option_value( $key = FALSE ) {
1172
1173 $adminimizeoptions = FALSE;
1174 if ( ! _mw_adminimize_exclude_settings_page() ) {
1175 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1176 }
1177
1178 if ( FALSE === $adminimizeoptions ) {
1179 // check for use on multisite
1180 if ( _mw_adminimize_is_active_on_multisite() ) {
1181 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1182 } else {
1183 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1184 }
1185 wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1186 }
1187
1188 if ( ! $key ) {
1189 return $adminimizeoptions;
1190 }
1191
1192 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1193 }
1194
1195 /**
1196 * Update options.
1197 *
1198 * @param array $options
1199 *
1200 * @return bool
1201 */
1202 function _mw_adminimize_update_option( $options ) {
1203
1204 if ( ! current_user_can( 'manage_options' ) ) {
1205 return FALSE;
1206 }
1207
1208 // Remove slashes always.
1209 foreach ( $options as $key => $value ) {
1210 $options[ $key ] = stripslashes_deep( $value );
1211 }
1212
1213 // Kill the cache for the settings page.
1214 wp_cache_delete( 'mw_adminimize' );
1215 if ( _mw_adminimize_is_active_on_multisite() ) {
1216 update_site_option( 'mw_adminimize', $options );
1217 } else {
1218 update_option( 'mw_adminimize', $options );
1219 }
1220 wp_cache_add( 'mw_adminimize', $options );
1221
1222 return TRUE;
1223 }
1224
1225 /**
1226 * Update options in database
1227 */
1228 function _mw_adminimize_update() {
1229
1230 $user_roles = _mw_adminimize_get_all_user_roles();
1231 $args = array( 'public' => TRUE, '_builtin' => FALSE );
1232 $post_types = get_post_types( $args );
1233
1234 // Admin Bar Back end settings
1235 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
1236 'mw_adminimize_admin_bar_nodes'
1237 );
1238 // admin bar back end options
1239 foreach ( $user_roles as $role ) {
1240 // admin bar back end options
1241 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
1242 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
1243 } else {
1244 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1245 }
1246 }
1247
1248 // Plugin Self Settings.
1249 if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1250 $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1251 } else {
1252 $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1253 }
1254
1255 if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1256 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1257 } else {
1258 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1259 }
1260
1261 if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1262 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1263 } else {
1264 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1265 }
1266
1267 if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1268 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1269 } else {
1270 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1271 }
1272
1273 // Admin Bar Front end settings
1274 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1275 'mw_adminimize_admin_bar_frontend_nodes'
1276 );
1277 // admin bar front end options
1278 foreach ( $user_roles as $role ) {
1279 // admin bar front-end options
1280 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1281 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1282 } else {
1283 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
1284 }
1285 }
1286
1287 if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
1288 $adminimizeoptions[ '_mw_adminimize_user_info' ] = (int) $_POST[ '_mw_adminimize_user_info' ];
1289 } else {
1290 $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
1291 }
1292
1293 if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
1294 $adminimizeoptions[ '_mw_adminimize_footer' ] = (int) $_POST[ '_mw_adminimize_footer' ];
1295 } else {
1296 $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
1297 }
1298
1299 if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
1300 $adminimizeoptions[ '_mw_adminimize_header' ] = (int) $_POST[ '_mw_adminimize_header' ];
1301 } else {
1302 $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
1303 }
1304
1305 if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
1306 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = (int) $_POST[ '_mw_adminimize_exclude_super_admin' ];
1307 } else {
1308 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
1309 }
1310
1311 if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
1312 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = (int) $_POST[ '_mw_adminimize_tb_window' ];
1313 } else {
1314 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
1315 }
1316
1317 if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
1318 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = (int) $_POST[ '_mw_adminimize_cat_full' ];
1319 } else {
1320 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
1321 }
1322
1323 if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
1324 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = (int) $_POST[ '_mw_adminimize_db_redirect' ];
1325 } else {
1326 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
1327 }
1328
1329 if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
1330 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = (int) $_POST[ '_mw_adminimize_ui_redirect' ];
1331 } else {
1332 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
1333 }
1334
1335 if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
1336 $adminimizeoptions[ '_mw_adminimize_advice' ] = (int) $_POST[ '_mw_adminimize_advice' ];
1337 } else {
1338 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1339 }
1340
1341 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1342 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1343 $_POST[ '_mw_adminimize_advice_txt' ],
1344 array(
1345 'a' => array(
1346 'href' => array(),
1347 'title' => array()
1348 ),
1349 'br' => array(),
1350 'em' => array(),
1351 'strong' => array(),
1352 )
1353 );
1354 } else {
1355 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1356 }
1357
1358 if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
1359 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = (int) $_POST[ '_mw_adminimize_timestamp' ];
1360 } else {
1361 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
1362 }
1363
1364 if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
1365 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = esc_url( $_POST[ '_mw_adminimize_db_redirect_txt' ] );
1366 } else {
1367 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = '';
1368 }
1369
1370 // menu update
1371 foreach ( $user_roles as $role ) {
1372 if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
1373 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] =
1374 $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
1375 } else {
1376 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1377 }
1378
1379 if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
1380 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] =
1381 $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
1382 } else {
1383 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1384 }
1385 }
1386
1387 // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1388
1389 // own menu slug
1390 if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1391 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1392 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1393 );
1394 } else {
1395 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1396 }
1397 // own custom menu slug
1398 if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1399 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1400 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1401 );
1402 } else {
1403 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1404 }
1405
1406 // global_options, metaboxes update
1407 foreach ( $user_roles as $role ) {
1408
1409 // global options
1410 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1411 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1412 $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1413 } else {
1414 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1415 }
1416
1417 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
1418 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] =
1419 $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
1420 } else {
1421 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1422 }
1423
1424 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
1425 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] =
1426 $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
1427 } else {
1428 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1429 }
1430
1431 foreach ( $post_types as $post_type ) {
1432 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] ) ) {
1433 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] =
1434 $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ];
1435 } else {
1436 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1437 }
1438 }
1439
1440 if ( isset( $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] ) ) {
1441 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] =
1442 $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ];
1443 } else {
1444 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = array();
1445 }
1446
1447 // wp nav menu options
1448 if ( isset( $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] ) ) {
1449 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] =
1450 $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ];
1451 } else {
1452 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = array();
1453 }
1454
1455 // widget options
1456 if ( isset( $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] ) ) {
1457 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] =
1458 $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ];
1459 } else {
1460 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = array();
1461 }
1462
1463 // wp dashboard option
1464 if ( isset( $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] ) ) {
1465 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] =
1466 $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ];
1467 } else {
1468 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = array();
1469 }
1470 }
1471
1472 // own options
1473 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1474 $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1475 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1476 );
1477 } else {
1478 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1479 }
1480
1481 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1482 $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1483 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1484 );
1485 } else {
1486 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1487 }
1488
1489 // own post options
1490 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1491 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1492 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1493 );
1494 } else {
1495 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1496 }
1497
1498 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1499 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1500 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1501 );
1502 } else {
1503 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1504 }
1505
1506 // own page options
1507 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1508 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1509 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1510 );
1511 } else {
1512 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1513 }
1514
1515 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1516 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1517 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1518 );
1519 } else {
1520 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1521 }
1522
1523 // own custom post options
1524 foreach ( $post_types as $post_type ) {
1525 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1526 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1527 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1528 );
1529 } else {
1530 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1531 }
1532
1533 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1534 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1535 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1536 );
1537 } else {
1538 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1539 }
1540 }
1541
1542 // own link options
1543 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1544 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1545 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1546 );
1547 } else {
1548 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1549 }
1550
1551 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1552 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1553 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1554 );
1555 } else {
1556 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1557 }
1558
1559 // wp nav menu options
1560 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1561 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1562 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1563 );
1564 } else {
1565 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1566 }
1567
1568 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1569 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1570 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1571 );
1572 } else {
1573 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1574 }
1575
1576 // widget options
1577 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1578 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1579 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1580 );
1581 } else {
1582 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1583 }
1584
1585 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1586 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1587 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1588 );
1589 } else {
1590 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1591 }
1592
1593 // own dashboard options
1594 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1595 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1596 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1597 );
1598 } else {
1599 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1600 }
1601
1602 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1603 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1604 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1605 );
1606 } else {
1607 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1608 }
1609
1610 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_option_value(
1611 'mw_adminimize_dashboard_widgets'
1612 );
1613
1614 if ( isset( $GLOBALS[ 'menu' ] ) ) {
1615 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $GLOBALS[ 'menu' ];
1616 }
1617 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1618 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1619 }
1620
1621 // update
1622 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1623
1624 $myErrors = new _mw_adminimize_message_class();
1625 if ( $update_status ) {
1626 $message = $myErrors->get_error(
1627 '_mw_adminimize_update'
1628 );
1629 } else {
1630 $message = $myErrors->get_error(
1631 '_mw_adminimize_access_denied'
1632 );
1633 }
1634 echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1635
1636 return TRUE;
1637 }
1638
1639 /**
1640 * Delete options in database
1641 */
1642 function _mw_adminimize_uninstall() {
1643
1644 wp_cache_delete( 'mw_adminimize' );
1645 delete_site_option( 'mw_adminimize' );
1646 delete_option( 'mw_adminimize' );
1647 }
1648
1649 /**
1650 * Install options in database
1651 */
1652 function _mw_adminimize_install() {
1653
1654 if ( ! is_admin() ) {
1655 return;
1656 }
1657
1658 // If is AJAX Call.
1659 if ( defined('DOING_AJAX') && DOING_AJAX ) {
1660 return;
1661 }
1662
1663 global $menu, $submenu;
1664
1665 $user_roles = _mw_adminimize_get_all_user_roles();
1666 $adminimizeoptions = array();
1667
1668 foreach ( $user_roles as $role ) {
1669 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1670 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1671 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1672 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1673 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1674 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1675 $args = array(
1676 'public' => TRUE,
1677 '_builtin' => FALSE,
1678 );
1679 foreach ( get_post_types( $args ) as $post_type ) {
1680 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1681 }
1682 }
1683
1684 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
1685 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
1686
1687 if ( _mw_adminimize_is_active_on_multisite() ) {
1688 add_site_option( 'mw_adminimize', $adminimizeoptions );
1689 } else {
1690 add_option( 'mw_adminimize', $adminimizeoptions );
1691 }
1692 wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1693 }
1694