PluginProbe
Adminimize / 1.11.5
Adminimize v1.11.5
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.5, at adminimize.php

1,711 lines 53.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.5
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-07-07
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 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 // It's better to declare $metaboxes as an array for better manipulation later.
739 $metaboxes = array();
740
741 foreach ( $user_roles as $role ) {
742 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
743 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
744 );
745
746 if ( ! isset( $disabled_metaboxes_post_[ $role ]['0'] ) ) {
747 $disabled_metaboxes_post_[ $role ]['0'] = '';
748
749 /**
750 * @todo Think why keep going if $role does not even have boxes to hide? We may as well jump to the next $role.
751 */
752 continue;
753 }
754
755 /**
756 * @todo Think why call a function as we can use a global variable already declared by WordPress.
757 * @var WP_User $user Instance of WP_User.
758 * @since 1.7.8
759 * @version 1.11.4
760 */
761 $user = $GLOBALS['current_user'];
762 if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
763 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
764 && is_array(
765 $disabled_metaboxes_post_[ $role ]
766 )
767 ) {
768 // The previous way $metaboxes was being filled it could be at some point non empty and empty afterwards.
769 // For instance, if a $role has items to be hidden and the user has this $role, $metaboxes will be filled.
770 // 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.
771 $metaboxes[] = implode( ',', $disabled_metaboxes_post_[ $role ] );
772 }
773 }
774 }
775
776 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
777 // And below we implode $metaboxes because it's an array now.
778 $_mw_adminimize_admin_head .= '<style type="text/css">' .
779 implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
780
781 if ( ! empty( $metaboxes ) ) {
782 echo $_mw_adminimize_admin_head;
783 }
784 }
785
786 /**
787 * Set metabox options from database an area page.
788 */
789 function _mw_adminimize_set_metabox_page_option() {
790
791 // exclude super admin
792 if ( _mw_adminimize_exclude_super_admin() ) {
793 return NULL;
794 }
795
796 // Leave the settings screen from Adminimize to see all areas on settings.
797 if ( _mw_adminimize_exclude_settings_page() ) {
798 return;
799 }
800
801 $user_roles = _mw_adminimize_get_all_user_roles();
802 $_mw_adminimize_admin_head = '';
803 $metaboxes = '';
804
805 foreach ( $user_roles as $role ) {
806 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
807 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
808 );
809
810 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
811 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
812 }
813
814 // New since version 1.7.8.
815 $user = wp_get_current_user();
816 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
817 if ( _mw_adminimize_current_user_has_role( $role )
818 && isset( $disabled_metaboxes_page_[ $role ] )
819 && is_array( $disabled_metaboxes_page_[ $role ] )
820 ) {
821 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
822 }
823 }
824 }
825
826 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
827 $_mw_adminimize_admin_head .= '<style type="text/css">' .
828 $metaboxes . ' {display:none !important;}</style>' . "\n";
829
830 if ( ! empty( $metaboxes ) ) {
831 echo $_mw_adminimize_admin_head;
832 }
833 }
834
835 /**
836 * Set metabox options from database an area post.
837 */
838 function _mw_adminimize_set_metabox_cp_option() {
839
840 // exclude super admin
841 if ( _mw_adminimize_exclude_super_admin() ) {
842 return NULL;
843 }
844
845 // Leave the settings screen from Adminimize to see all areas on settings.
846 if ( _mw_adminimize_exclude_settings_page() ) {
847 return;
848 }
849
850 $post_id = 0;
851 if ( isset( $_GET[ 'post' ] ) ) {
852 $post_id = (int) $_GET[ 'post' ];
853 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
854 $post_id = (int) $_POST[ 'post_ID' ];
855 }
856
857 $current_post_type = $GLOBALS[ 'post_type' ];
858 if ( ! isset( $current_post_type ) ) {
859 $current_post_type = get_post_type( $post_id );
860 }
861
862 if ( ! isset( $current_post_type ) || ! $current_post_type ) {
863 $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
864 }
865
866 // set hard to post
867 if ( ! $current_post_type ) {
868 $current_post_type = 'post';
869 }
870
871 $user_roles = _mw_adminimize_get_all_user_roles();
872 $_mw_adminimize_admin_head = '';
873 $metaboxes = array();
874
875 foreach ( $user_roles as $role ) {
876 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
877 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
878 );
879
880 if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
881 $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
882
883 continue;
884 }
885
886 $user = $GLOBALS['current_user'];
887 if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
888 if ( _mw_adminimize_current_user_has_role( $role )
889 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
890 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
891 ) {
892 $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
893 }
894 }
895 }
896
897 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
898 $_mw_adminimize_admin_head .= '<style type="text/css">' .
899 implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
900
901 if ( ! empty( $metaboxes ) ) {
902 echo $_mw_adminimize_admin_head;
903 }
904 }
905
906 /**
907 * Set link options in area links of back end.
908 */
909 function _mw_adminimize_set_link_option() {
910
911 // exclude super admin
912 if ( _mw_adminimize_exclude_super_admin() ) {
913 return NULL;
914 }
915
916 // Leave the settings screen from Adminimize to see all areas on settings.
917 if ( _mw_adminimize_exclude_settings_page() ) {
918 return;
919 }
920
921 $user_roles = _mw_adminimize_get_all_user_roles();
922 $_mw_adminimize_admin_head = '';
923
924 foreach ( $user_roles as $role ) {
925 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
926 'mw_adminimize_disabled_link_option_' . $role . '_items'
927 );
928 }
929
930 foreach ( $user_roles as $role ) {
931 if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
932 $disabled_link_option_[ $role ][ '0' ] = '';
933 }
934 }
935
936 $link_options = '';
937 foreach ( $user_roles as $role ) {
938 $user = wp_get_current_user();
939 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
940 if ( _mw_adminimize_current_user_has_role( $role )
941 && isset( $disabled_link_option_[ $role ] )
942 && is_array( $disabled_link_option_[ $role ] )
943 ) {
944 $link_options = implode( ',', $disabled_link_option_[ $role ] );
945 }
946 }
947 }
948
949 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
950 $_mw_adminimize_admin_head .= '<style type="text/css">' .
951 $link_options . ' {display:none !important;}</style>' . "\n";
952
953 if ( ! empty( $link_options ) ) {
954 echo $_mw_adminimize_admin_head;
955 }
956 }
957
958 /**
959 * Remove objects on wp nav menu.
960 */
961 function _mw_adminimize_set_nav_menu_option() {
962
963 // exclude super admin
964 if ( _mw_adminimize_exclude_super_admin() ) {
965 return NULL;
966 }
967
968 // Leave the settings screen from Adminimize to see all areas on settings.
969 if ( _mw_adminimize_exclude_settings_page() ) {
970 return;
971 }
972
973 $user_roles = _mw_adminimize_get_all_user_roles();
974 $_mw_adminimize_admin_head = '';
975
976 foreach ( $user_roles as $role ) {
977 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
978 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
979 );
980 }
981
982 foreach ( $user_roles as $role ) {
983 if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
984 $disabled_nav_menu_option_[ $role ][ '0' ] = '';
985 }
986 }
987
988 $nav_menu_options = '';
989 foreach ( $user_roles as $role ) {
990 $user = wp_get_current_user();
991 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
992 if ( _mw_adminimize_current_user_has_role( $role )
993 && isset( $disabled_nav_menu_option_[ $role ] )
994 && is_array( $disabled_nav_menu_option_[ $role ] )
995 ) {
996 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
997 }
998 }
999 }
1000
1001 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1002 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1003 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1004
1005 if ( $nav_menu_options ) {
1006 echo $_mw_adminimize_admin_head;
1007 }
1008 }
1009
1010 /**
1011 * Remove areas in Widget Settings
1012 */
1013 function _mw_adminimize_set_widget_option() {
1014
1015 // exclude super admin
1016 if ( _mw_adminimize_exclude_super_admin() ) {
1017 return NULL;
1018 }
1019
1020 // Leave the settings screen from Adminimize to see all areas on settings.
1021 if ( _mw_adminimize_exclude_settings_page() ) {
1022 return;
1023 }
1024
1025 $user_roles = _mw_adminimize_get_all_user_roles();
1026 $_mw_adminimize_admin_head = '';
1027
1028 foreach ( $user_roles as $role ) {
1029 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
1030 'mw_adminimize_disabled_widget_option_' . $role . '_items'
1031 );
1032 }
1033
1034 foreach ( $user_roles as $role ) {
1035 if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
1036 $disabled_widget_option_[ $role ][ '0' ] = '';
1037 }
1038 }
1039
1040 $widget_options = '';
1041 foreach ( $user_roles as $role ) {
1042 $user = wp_get_current_user();
1043 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1044 if ( _mw_adminimize_current_user_has_role( $role )
1045 && isset( $disabled_widget_option_[ $role ] )
1046 && is_array( $disabled_widget_option_[ $role ] )
1047 ) {
1048 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1049 }
1050 }
1051 }
1052
1053 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1054 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1055 $widget_options . ' {display: none !important;}</style>' . "\n";
1056
1057 if ( $widget_options ) {
1058 echo $_mw_adminimize_admin_head;
1059 }
1060 }
1061
1062 /**
1063 * Print small user-info.
1064 */
1065 function _mw_adminimize_small_user_info() {
1066
1067 ?>
1068 <div id="small_user_info">
1069 <p>
1070 <a href="<?php echo wp_nonce_url(
1071 site_url( 'wp-login.php?action=logout' ),
1072 'log-out'
1073 ) ?>"
1074 title="<?php esc_attr_e( 'Log Out' ) ?>"><?php esc_attr_e( 'Log Out' ); ?></a>
1075 </p>
1076 </div>
1077 <?php
1078 }
1079
1080 // include helping functions
1081 require_once 'inc-setup/helping_hands.php';
1082
1083 // Include message class.
1084 require_once 'inc-setup/messages.php';
1085
1086 // inc. settings page
1087 require_once 'adminimize_page.php';
1088
1089 // dashboard options
1090 require_once 'inc-setup/dashboard.php';
1091
1092 // widget options
1093 require_once 'inc-setup/widget.php';
1094 require_once 'inc-setup/footer.php';
1095 require_once 'inc-setup/admin-footer.php';
1096
1097 // remove admin bar
1098 require_once 'inc-setup/remove-admin-bar.php';
1099
1100 // admin bar helper, setup
1101 // work always in frontend
1102 require_once 'inc-setup/admin-bar-items.php';
1103
1104 // meta boxes helper, setup
1105 // @TODO Meta Boxes: not ready for productive systems.
1106 //require_once( 'inc-setup/meta-boxes.php' );
1107
1108 // Remove Admin Notices.
1109 require_once 'inc-setup/remove-admin-notices.php';
1110
1111 // Add Ex-Import functions.
1112 require_once 'inc-setup/export.php';
1113 require_once 'inc-setup/import.php';
1114
1115 /**
1116 * Add action link(s) to plugins page
1117 *
1118 * @param array $links
1119 * @param string $file
1120 *
1121 * @return array $links
1122 */
1123 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1124
1125 /* create link */
1126 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1127 array_unshift(
1128 $links,
1129 sprintf(
1130 '<a href="options-general.php?page=adminimize-options">%s</a>',
1131 esc_attr__( 'Settings' )
1132 )
1133 );
1134 }
1135
1136 return $links;
1137 }
1138
1139 /**
1140 * Add settings in plugin-admin-page.
1141 */
1142 function _mw_adminimize_add_settings_page() {
1143
1144 $pagehook = add_options_page(
1145 esc_attr__( 'Adminimize Options', 'adminimize' ),
1146 esc_attr__( 'Adminimize', 'adminimize' ),
1147 'manage_options',
1148 'adminimize-options',
1149 '_mw_adminimize_options'
1150 );
1151
1152 if ( ! is_network_admin() ) {
1153 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1154 }
1155 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1156 }
1157
1158 /**
1159 * Enqueue script and styles for the settings page.
1160 */
1161 function _mw_adminimize_on_load_page() {
1162
1163 // Load translation files on options page.
1164 _mw_adminimize_textdomain();
1165
1166 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1167
1168 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1169 wp_enqueue_style( 'adminimize-style' );
1170
1171 wp_register_script(
1172 'adminimize-settings-script',
1173 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1174 array( 'jquery' ),
1175 '',
1176 TRUE
1177 );
1178 wp_enqueue_script( 'adminimize-settings-script' );
1179 }
1180
1181 /**
1182 * Get setting value for each options key.
1183 *
1184 * @param string|bool $key
1185 *
1186 * @return string
1187 */
1188 function _mw_adminimize_get_option_value( $key = FALSE ) {
1189
1190 $adminimizeoptions = FALSE;
1191 if ( ! _mw_adminimize_exclude_settings_page() ) {
1192 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1193 }
1194
1195 if ( FALSE === $adminimizeoptions ) {
1196 // check for use on multisite
1197 if ( _mw_adminimize_is_active_on_multisite() ) {
1198 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1199 } else {
1200 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1201 }
1202 wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1203 }
1204
1205 if ( ! $key ) {
1206 return $adminimizeoptions;
1207 }
1208
1209 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1210 }
1211
1212 /**
1213 * Update options.
1214 *
1215 * @param array $options
1216 *
1217 * @return bool
1218 */
1219 function _mw_adminimize_update_option( $options ) {
1220
1221 if ( ! current_user_can( 'manage_options' ) ) {
1222 return FALSE;
1223 }
1224
1225 // Remove slashes always.
1226 foreach ( $options as $key => $value ) {
1227 $options[ $key ] = stripslashes_deep( $value );
1228 }
1229
1230 // Kill the cache for the settings page.
1231 wp_cache_delete( 'mw_adminimize' );
1232 if ( _mw_adminimize_is_active_on_multisite() ) {
1233 update_site_option( 'mw_adminimize', $options );
1234 } else {
1235 update_option( 'mw_adminimize', $options );
1236 }
1237 wp_cache_add( 'mw_adminimize', $options );
1238
1239 return TRUE;
1240 }
1241
1242 /**
1243 * Update options in database
1244 */
1245 function _mw_adminimize_update() {
1246
1247 $user_roles = _mw_adminimize_get_all_user_roles();
1248 $args = array( 'public' => TRUE, '_builtin' => FALSE );
1249 $post_types = get_post_types( $args );
1250
1251 // Admin Bar Back end settings
1252 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
1253 'mw_adminimize_admin_bar_nodes'
1254 );
1255 // admin bar back end options
1256 foreach ( $user_roles as $role ) {
1257 // admin bar back end options
1258 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
1259 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
1260 } else {
1261 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1262 }
1263 }
1264
1265 // Plugin Self Settings.
1266 if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1267 $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1268 } else {
1269 $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1270 }
1271
1272 if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1273 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1274 } else {
1275 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1276 }
1277
1278 if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1279 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1280 } else {
1281 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1282 }
1283
1284 if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1285 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1286 } else {
1287 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1288 }
1289
1290 // Admin Bar Front end settings
1291 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1292 'mw_adminimize_admin_bar_frontend_nodes'
1293 );
1294 // admin bar front end options
1295 foreach ( $user_roles as $role ) {
1296 // admin bar front-end options
1297 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1298 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1299 } else {
1300 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
1301 }
1302 }
1303
1304 if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
1305 $adminimizeoptions[ '_mw_adminimize_user_info' ] = (int) $_POST[ '_mw_adminimize_user_info' ];
1306 } else {
1307 $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
1308 }
1309
1310 if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
1311 $adminimizeoptions[ '_mw_adminimize_footer' ] = (int) $_POST[ '_mw_adminimize_footer' ];
1312 } else {
1313 $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
1314 }
1315
1316 if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
1317 $adminimizeoptions[ '_mw_adminimize_header' ] = (int) $_POST[ '_mw_adminimize_header' ];
1318 } else {
1319 $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
1320 }
1321
1322 if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
1323 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = (int) $_POST[ '_mw_adminimize_exclude_super_admin' ];
1324 } else {
1325 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
1326 }
1327
1328 if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
1329 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = (int) $_POST[ '_mw_adminimize_tb_window' ];
1330 } else {
1331 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
1332 }
1333
1334 if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
1335 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = (int) $_POST[ '_mw_adminimize_cat_full' ];
1336 } else {
1337 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
1338 }
1339
1340 if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
1341 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = (int) $_POST[ '_mw_adminimize_db_redirect' ];
1342 } else {
1343 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
1344 }
1345
1346 if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
1347 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = (int) $_POST[ '_mw_adminimize_ui_redirect' ];
1348 } else {
1349 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
1350 }
1351
1352 if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
1353 $adminimizeoptions[ '_mw_adminimize_advice' ] = (int) $_POST[ '_mw_adminimize_advice' ];
1354 } else {
1355 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1356 }
1357
1358 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1359 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1360 $_POST[ '_mw_adminimize_advice_txt' ],
1361 array(
1362 'a' => array(
1363 'href' => array(),
1364 'title' => array()
1365 ),
1366 'br' => array(),
1367 'em' => array(),
1368 'strong' => array(),
1369 )
1370 );
1371 } else {
1372 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1373 }
1374
1375 if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
1376 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = (int) $_POST[ '_mw_adminimize_timestamp' ];
1377 } else {
1378 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
1379 }
1380
1381 if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
1382 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = esc_url( $_POST[ '_mw_adminimize_db_redirect_txt' ] );
1383 } else {
1384 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = '';
1385 }
1386
1387 // menu update
1388 foreach ( $user_roles as $role ) {
1389 if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
1390 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] =
1391 $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
1392 } else {
1393 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1394 }
1395
1396 if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
1397 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] =
1398 $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
1399 } else {
1400 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1401 }
1402 }
1403
1404 // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1405
1406 // own menu slug
1407 if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1408 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1409 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1410 );
1411 } else {
1412 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1413 }
1414 // own custom menu slug
1415 if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1416 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1417 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1418 );
1419 } else {
1420 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1421 }
1422
1423 // global_options, metaboxes update
1424 foreach ( $user_roles as $role ) {
1425
1426 // global options
1427 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1428 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1429 $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1430 } else {
1431 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1432 }
1433
1434 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
1435 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] =
1436 $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
1437 } else {
1438 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1439 }
1440
1441 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
1442 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] =
1443 $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
1444 } else {
1445 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1446 }
1447
1448 foreach ( $post_types as $post_type ) {
1449 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] ) ) {
1450 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] =
1451 $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ];
1452 } else {
1453 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1454 }
1455 }
1456
1457 if ( isset( $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] ) ) {
1458 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] =
1459 $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ];
1460 } else {
1461 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = array();
1462 }
1463
1464 // wp nav menu options
1465 if ( isset( $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] ) ) {
1466 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] =
1467 $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ];
1468 } else {
1469 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = array();
1470 }
1471
1472 // widget options
1473 if ( isset( $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] ) ) {
1474 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] =
1475 $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ];
1476 } else {
1477 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = array();
1478 }
1479
1480 // wp dashboard option
1481 if ( isset( $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] ) ) {
1482 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] =
1483 $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ];
1484 } else {
1485 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = array();
1486 }
1487 }
1488
1489 // own options
1490 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1491 $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1492 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1493 );
1494 } else {
1495 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1496 }
1497
1498 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1499 $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1500 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1501 );
1502 } else {
1503 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1504 }
1505
1506 // own post options
1507 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1508 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1509 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1510 );
1511 } else {
1512 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1513 }
1514
1515 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1516 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1517 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1518 );
1519 } else {
1520 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1521 }
1522
1523 // own page options
1524 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1525 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1526 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1527 );
1528 } else {
1529 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1530 }
1531
1532 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1533 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1534 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1535 );
1536 } else {
1537 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1538 }
1539
1540 // own custom post options
1541 foreach ( $post_types as $post_type ) {
1542 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1543 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1544 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1545 );
1546 } else {
1547 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1548 }
1549
1550 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1551 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1552 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1553 );
1554 } else {
1555 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1556 }
1557 }
1558
1559 // own link options
1560 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1561 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1562 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1563 );
1564 } else {
1565 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1566 }
1567
1568 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1569 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1570 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1571 );
1572 } else {
1573 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1574 }
1575
1576 // wp nav menu options
1577 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1578 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1579 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1580 );
1581 } else {
1582 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1583 }
1584
1585 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1586 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1587 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1588 );
1589 } else {
1590 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1591 }
1592
1593 // widget options
1594 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1595 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1596 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1597 );
1598 } else {
1599 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1600 }
1601
1602 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1603 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1604 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1605 );
1606 } else {
1607 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1608 }
1609
1610 // own dashboard options
1611 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1612 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1613 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1614 );
1615 } else {
1616 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1617 }
1618
1619 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1620 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1621 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1622 );
1623 } else {
1624 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1625 }
1626
1627 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_option_value(
1628 'mw_adminimize_dashboard_widgets'
1629 );
1630
1631 if ( isset( $GLOBALS[ 'menu' ] ) ) {
1632 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $GLOBALS[ 'menu' ];
1633 }
1634 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1635 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1636 }
1637
1638 // update
1639 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1640
1641 $myErrors = new _mw_adminimize_message_class();
1642 if ( $update_status ) {
1643 $message = $myErrors->get_error(
1644 '_mw_adminimize_update'
1645 );
1646 } else {
1647 $message = $myErrors->get_error(
1648 '_mw_adminimize_access_denied'
1649 );
1650 }
1651 echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1652
1653 return TRUE;
1654 }
1655
1656 /**
1657 * Delete options in database
1658 */
1659 function _mw_adminimize_uninstall() {
1660
1661 wp_cache_delete( 'mw_adminimize' );
1662 delete_site_option( 'mw_adminimize' );
1663 delete_option( 'mw_adminimize' );
1664 }
1665
1666 /**
1667 * Install options in database
1668 */
1669 function _mw_adminimize_install() {
1670
1671 if ( ! is_admin() ) {
1672 return;
1673 }
1674
1675 // If is AJAX Call.
1676 if ( defined('DOING_AJAX') && DOING_AJAX ) {
1677 return;
1678 }
1679
1680 global $menu, $submenu;
1681
1682 $user_roles = _mw_adminimize_get_all_user_roles();
1683 $adminimizeoptions = array();
1684
1685 foreach ( $user_roles as $role ) {
1686 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1687 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1688 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1689 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1690 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1691 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1692 $args = array(
1693 'public' => TRUE,
1694 '_builtin' => FALSE,
1695 );
1696 foreach ( get_post_types( $args ) as $post_type ) {
1697 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1698 }
1699 }
1700
1701 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
1702 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
1703
1704 if ( _mw_adminimize_is_active_on_multisite() ) {
1705 add_site_option( 'mw_adminimize', $adminimizeoptions );
1706 } else {
1707 add_option( 'mw_adminimize', $adminimizeoptions );
1708 }
1709 wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1710 }
1711