PluginProbe
Adminimize / 1.11.6
Adminimize v1.11.6
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.6, at adminimize.php

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