PluginProbe
Adminimize / 1.8.5
Adminimize v1.8.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.8.5, at adminimize.php

1,915 lines 61.7 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
8 * seen. The plugin that lets you hide 'unnecessary' items from the WordPress administration menu, for all roles of
9 * your install. You can also hide post meta controls on the edit-area to simplify the interface. It is possible to
10 * simplify the admin in different for all roles.
11 * Author: Frank Bültge
12 * Author URI: http://bueltge.de/
13 * Version: 1.8.5
14 * License: GPLv2+
15 *
16 * Php Version 5.3
17 *
18 * @package WordPress
19 * @author Frank Bültge <[email protected]>
20 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
21 * @version 2015-03-19
22 */
23
24 /**
25 * The stylesheet and the initial idea is from Eric A. Meyer, http://meyerweb.com/
26 * and i have written a plugin with many options on the basis
27 * of differently user-right and a user-friendly range in admin-area.
28 *
29 * :( grmpf i have so much wishes and hints form users, do use the plugin and
30 * it is not possible to development this on my free time
31 */
32
33 if ( ! function_exists( 'add_action' ) ) {
34 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
35 exit;
36 }
37
38 // plugin definitions
39 define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
40 define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
41 define( 'FB_ADMINIMIZE_TEXTDOMAIN', _mw_adminimize_get_plugin_data( 'TextDomain' ) );
42
43 function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
44
45 if ( ! function_exists( 'get_plugin_data' ) ) {
46 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
47 }
48
49 $plugin_data = get_plugin_data( __FILE__ );
50 $plugin_value = $plugin_data[ $value ];
51
52 return $plugin_value;
53 }
54
55 function _mw_adminimize_textdomain() {
56
57 load_plugin_textdomain(
58 _mw_adminimize_get_plugin_data( 'TextDomain' ),
59 FALSE,
60 dirname( FB_ADMINIMIZE_BASENAME ) . _mw_adminimize_get_plugin_data( 'DomainPath' )
61 );
62 }
63
64 function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
65
66 if ( '' != $haystack ) {
67 foreach ( $haystack as $stalk ) {
68 if ( $needle == $stalk
69 || ( is_array( $stalk ) && _mw_adminimize_recursive_in_array( $needle, $stalk )
70 )
71 ) {
72 return TRUE;
73 }
74 }
75
76 return FALSE;
77 }
78
79 return FALSE;
80 }
81
82 /**
83 * some basics for message
84 */
85 class _mw_adminimize_message_class {
86
87 /**
88 * constructor
89 */
90 function _mw_adminimize_message_class() {
91
92 $this->localizion_name = FB_ADMINIMIZE_TEXTDOMAIN;
93 $this->errors = new WP_Error();
94 $this->initialize_errors();
95 }
96
97 /**
98 * get_error - Returns an error message based on the passed code
99 * Parameters - $code (the error code as a string)
100 *
101 * @param string $code
102 *
103 * @return string $errorMessage
104 */
105 function get_error( $code = '' ) {
106
107 $errorMessage = $this->errors->get_error_message( $code );
108
109 if ( NULL == $errorMessage ) {
110 return __( 'Unknown error.', $this->localizion_name );
111 }
112
113 return $errorMessage;
114 }
115
116 /**
117 * Initializes all the error messages
118 */
119 function initialize_errors() {
120
121 $this->errors->add( '_mw_adminimize_update', __( 'The updates were saved.', $this->localizion_name ) );
122 $this->errors->add(
123 '_mw_adminimize_access_denied',
124 __( 'You have not enough rights to edit entries in the database.', $this->localizion_name )
125 );
126 $this->errors->add(
127 '_mw_adminimize_import', __( 'All entries in the database were imported.', $this->localizion_name )
128 );
129 $this->errors->add(
130 '_mw_adminimize_deinstall', __( 'All entries in the database were deleted.', $this->localizion_name )
131 );
132 $this->errors->add(
133 '_mw_adminimize_deinstall_yes', __( 'Set the checkbox on deinstall-button.', $this->localizion_name )
134 );
135 $this->errors->add(
136 '_mw_adminimize_get_option', __( 'Can\'t load menu and submenu.', $this->localizion_name )
137 );
138 $this->errors->add( '_mw_adminimize_set_theme', __( 'Backend-Theme was activated!', $this->localizion_name ) );
139 $this->errors->add(
140 '_mw_adminimize_load_theme', __( 'Load user data to themes was successful.', $this->localizion_name )
141 );
142 }
143
144 } // end class
145
146 function _mw_adminimize_exclude_super_admin() {
147
148 // exclude super admin
149 if ( function_exists( 'is_super_admin' )
150 && is_super_admin()
151 && 1 == _mw_adminimize_get_option_value( '_mw_adminimize_exclude_super_admin' )
152 ) {
153 return TRUE;
154 }
155
156 return FALSE;
157 }
158
159 /**
160 * _mw_adminimize_get_all_user_roles() - Returns an array with all user roles(names) in it.
161 * Inclusive self defined roles (for example with the 'Role Manager' plugin).
162 * code by Vincent Weber, www.webRtistik.nl
163 *
164 * @uses $wp_roles
165 * @return array $user_roles
166 */
167 function _mw_adminimize_get_all_user_roles() {
168
169 global $wp_roles;
170
171 $user_roles = array();
172
173 if ( isset( $wp_roles->roles ) && is_array( $wp_roles->roles ) ) {
174 foreach ( $wp_roles->roles as $role => $data ) {
175 array_push( $user_roles, $role );
176 //$data contains caps, maybe for later use..
177 }
178 }
179
180 // exclude the new bbPress roles
181 $user_roles = array_diff(
182 $user_roles,
183 array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
184 );
185
186 return $user_roles;
187 }
188
189 /**
190 * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
191 * Inclusive self defined roles (for example with the 'Role Manager' plugin).
192 *
193 * @uses $wp_roles
194 * @return array $user_roles_names
195 */
196 function _mw_adminimize_get_all_user_roles_names() {
197
198 global $wp_roles;
199
200 $user_roles_names = array();
201
202 foreach ( $wp_roles->role_names as $role_name => $data ) {
203 if ( function_exists( 'translate_user_role' ) ) {
204 $data = translate_user_role( $data );
205 } else {
206 $data = _x( $data, 'Translate each user role.' );
207 }
208
209 array_push( $user_roles_names, $data );
210 }
211
212 // exclude the new bbPress roles
213 $user_roles_names = array_diff(
214 $user_roles_names,
215 array(
216 __( 'Keymaster', 'bbpress' ),
217 __( 'Moderator', 'bbpress' ),
218 __( 'Participant', 'bbpress' ),
219 __( 'Spectator', 'bbpress' ),
220 __( 'Blocked', 'bbpress' )
221 )
222 );
223
224 return $user_roles_names;
225 }
226
227 /**
228 * Control Flash Uploader
229 *
230 * @return boolean
231 */
232 function _mw_adminimize_control_flashloader() {
233
234 $_mw_adminimize_control_flashloader = _mw_adminimize_get_option_value( '_mw_adminimize_control_flashloader' );
235
236 if ( $_mw_adminimize_control_flashloader == '1' ) {
237 return FALSE;
238 } else {
239 return TRUE;
240 }
241 }
242
243 /**
244 * return post type
245 */
246 function _mw_get_current_post_type() {
247
248 global $post, $typenow, $current_screen;
249
250 //we have a post so we can just get the post type from that
251 if ( $post && $post->post_type ) {
252 return $post->post_type;
253 } //check the global $typenow - set in admin.php
254 else if ( $typenow ) {
255 return $typenow;
256 } // check the global $current_screen object - set in sceen.php
257 else if ( $current_screen && $current_screen->post_type ) {
258 return $current_screen->post_type;
259 } // lastly check the post_type querystring
260 else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
261 return sanitize_key( $_REQUEST[ 'post_type' ] );
262 }
263
264 // we do not know the post type!
265 return NULL;
266 }
267
268 /**
269 * check user-option and add new style
270 *
271 * @uses $pagenow
272 */
273 function _mw_adminimize_admin_init() {
274
275 global $pagenow, $post_type, $menu, $submenu;
276
277 if ( isset( $_GET[ 'post' ] ) ) {
278 $post_id = (int) esc_attr( $_GET[ 'post' ] );
279 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
280 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
281 } else {
282 $post_id = 0;
283 }
284
285 $current_post_type = $post_type;
286 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
287 $current_post_type = get_post_type( $post_id );
288 }
289 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
290 $current_post_type = _mw_get_current_post_type();
291 }
292 if ( ! $current_post_type ) // set hard to post
293 {
294 $current_post_type = 'post';
295 }
296
297 $user_roles = _mw_adminimize_get_all_user_roles();
298
299 // check for use on multisite
300 if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
301 $adminimizeoptions = get_site_option( 'mw_adminimize' );
302 } else {
303 $adminimizeoptions = get_option( 'mw_adminimize' );
304 }
305
306 // pages for post type Post
307 $def_post_pages = array( 'edit.php', 'post.php', 'post-new.php' );
308 $def_post_types = array( 'post' );
309 $disabled_metaboxes_post_all = array();
310 // pages for post type Page
311 $def_page_pages = array_merge( $def_post_pages, array( 'page-new.php', 'page.php' ) );
312 $def_page_types = array( 'page' );
313 $disabled_metaboxes_page_all = array();
314 // pages for custom post types
315 $def_custom_pages = $def_post_pages;
316 $args = array( 'public' => TRUE, '_builtin' => FALSE );
317 $def_custom_types = get_post_types( $args );
318 // pages for link pages
319 $link_pages = array( 'link.php', 'link-manager.php', 'link-add.php', 'edit-link-categories.php' );
320 // pages for nav menu
321 $nav_menu_pages = array( 'nav-menus.php' );
322 // widget pages
323 $widget_pages = array( 'widgets.php' );
324
325 foreach ( $user_roles as $role ) {
326 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
327 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
328 );
329 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
330 'mw_adminimize_disabled_global_option_' . $role . '_items'
331 );
332 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
333 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
334 );
335 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
336 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
337 );
338 foreach ( $def_custom_types as $post_type ) {
339 $disabled_metaboxes_[ $post_type . '_' . $role ] = _mw_adminimize_get_option_value(
340 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items'
341 );
342 }
343 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
344 'mw_adminimize_disabled_link_option_' . $role . '_items'
345 );
346 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
347 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
348 );
349 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
350 'mw_adminimize_disabled_widget_option_' . $role . '_items'
351 );
352 array_push( $disabled_metaboxes_post_all, $disabled_metaboxes_post_[ $role ] );
353 array_push( $disabled_metaboxes_page_all, $disabled_metaboxes_page_[ $role ] );
354 }
355
356 // global options
357 // exclude super admin
358 if ( ! _mw_adminimize_exclude_super_admin() ) {
359 $_mw_adminimize_footer = _mw_adminimize_get_option_value( '_mw_adminimize_footer' );
360 switch ( $_mw_adminimize_footer ) {
361 case 1:
362 wp_enqueue_script(
363 '_mw_adminimize_remove_footer',
364 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_footer.js',
365 array( 'jquery' )
366 );
367 break;
368 }
369
370 $_mw_adminimize_header = _mw_adminimize_get_option_value( '_mw_adminimize_header' );
371 switch ( $_mw_adminimize_header ) {
372 case 1:
373 wp_enqueue_script(
374 '_mw_adminimize_remove_header',
375 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header.js',
376 array( 'jquery' )
377 );
378 break;
379 }
380
381 //post-page options
382 if ( in_array( $pagenow, $def_post_pages ) ) {
383
384 $_mw_adminimize_tb_window = _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
385 switch ( $_mw_adminimize_tb_window ) {
386 case 1:
387 wp_deregister_script( 'media-upload' );
388 wp_enqueue_script(
389 'media-upload',
390 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/tb_window.js',
391 array( 'thickbox' )
392 );
393 break;
394 }
395 $_mw_adminimize_timestamp = _mw_adminimize_get_option_value( '_mw_adminimize_timestamp' );
396 switch ( $_mw_adminimize_timestamp ) {
397 case 1:
398 wp_enqueue_script(
399 '_mw_adminimize_timestamp',
400 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/timestamp.js',
401 array( 'jquery' )
402 );
403 break;
404 }
405
406 //category options
407 $_mw_adminimize_cat_full = _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
408 switch ( $_mw_adminimize_cat_full ) {
409 case 1:
410 wp_enqueue_style(
411 'adminimize-ful-category',
412 WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/css/mw_cat_full.css'
413 );
414 break;
415 }
416
417 // set default editor tinymce
418 if ( _mw_adminimize_recursive_in_array(
419 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
420 $disabled_metaboxes_page_all
421 )
422 || _mw_adminimize_recursive_in_array(
423 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
424 $disabled_metaboxes_post_all
425 )
426 ) {
427 add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
428 }
429
430 // remove media bottons
431 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
432 || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
433 ) {
434 remove_action( 'media_buttons', 'media_buttons' );
435 }
436 }
437
438 $_mw_adminimize_control_flashloader = _mw_adminimize_get_option_value( '_mw_adminimize_control_flashloader' );
439 switch ( $_mw_adminimize_control_flashloader ) {
440 case 1:
441 add_filter( 'flash_uploader', '_mw_adminimize_control_flashloader', 1 );
442 break;
443 }
444 }
445
446 // set menu option
447 add_action( 'admin_head', '_mw_adminimize_set_menu_option', 1 );
448 // global_options
449 add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
450
451 // set metabox post option
452 if ( in_array( $pagenow, $def_post_pages ) && in_array( $current_post_type, $def_post_types ) ) {
453 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
454 }
455 // set metabox page option
456 if ( in_array( $pagenow, $def_page_pages ) && in_array( $current_post_type, $def_page_types ) ) {
457 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
458 }
459 // set custom post type options
460 if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages )
461 && in_array(
462 $current_post_type, $def_custom_types
463 )
464 ) {
465 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
466 }
467 // set link option
468 if ( in_array( $pagenow, $link_pages ) ) {
469 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
470 }
471 // set wp nav menu options
472 if ( in_array( $pagenow, $nav_menu_pages ) ) {
473 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
474 }
475 // set widget options
476 if ( in_array( $pagenow, $widget_pages ) ) {
477 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
478 }
479
480 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
481 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
482
483 }
484
485 /**
486 * Init always with WP
487 */
488 function _mw_adminimize_init() {
489
490 // change Admin Bar and user Info
491 if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3alpha', '>=' ) ) {
492 _mw_adminimize_set_menu_option_33();
493 } else {
494 add_action( 'admin_head', '_mw_adminimize_set_user_info' );
495 add_action( 'wp_head', '_mw_adminimize_set_user_info' );
496 }
497
498 }
499
500 // on admin init
501 define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
502 if ( is_admin() ) {
503 add_action( 'admin_init', '_mw_adminimize_textdomain' );
504 add_action( 'admin_init', '_mw_adminimize_admin_init', 2 );
505 /* maybe later
506 if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) )
507 add_action( 'network_admin_menu', '_mw_adminimize_add_settings_page' );
508 */
509 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
510 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
511 }
512 add_action( 'init', '_mw_adminimize_init', 2 );
513
514 register_activation_hook( __FILE__, '_mw_adminimize_install' );
515 register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
516 //register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
517
518 /**
519 * list category-box in sidebar
520 *
521 * @uses $post_ID
522 */
523 function _mw_adminimize_sidecat_list_category_box() {
524
525 global $post_ID;
526 ?>
527
528 <div class="inside" id="categorydivsb">
529 <p><strong><?php _e( "Categories" ); ?></strong></p>
530 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
531 <?php wp_category_checklist( $post_ID ); ?>
532 </ul>
533 <?php if ( ! defined( 'WP_PLUGIN_DIR' ) ) { // for wp <2.6 ?>
534 <div id="category-adder" class="wp-hidden-children">
535 <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e(
536 '+ Add New Category'
537 ); ?></a></h4>
538
539 <p id="category-add" class="wp-hidden-child">
540 <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e(
541 'New category name'
542 ); ?>" tabindex="3" />
543 <?php wp_dropdown_categories(
544 array(
545 'hide_empty' => 0,
546 'name' => 'newcat_parent',
547 'orderby' => 'name',
548 'hierarchical' => 1,
549 'show_option_none' => __( 'Parent category' ),
550 'tab_index' => 3
551 )
552 ); ?>
553 <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e(
554 'Add'
555 ); ?>" tabindex="3" />
556 <?php wp_nonce_field( 'add-category', '_ajax_nonce', FALSE ); ?>
557 <span id="category-ajax-response"></span>
558 </p>
559 </div>
560 <?php } else { ?>
561 <div id="category-adder" class="wp-hidden-children">
562 <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e(
563 '+ Add New Category'
564 ); ?></a></h4>
565
566 <p id="category-add" class="wp-hidden-child">
567 <label class="hidden" for="newcat"><?php _e(
568 'Add New Category'
569 ); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e(
570 'New category name'
571 ); ?>" tabindex="3" aria-required="TRUE" />
572 <br />
573 <label class="hidden" for="newcat_parent"><?php _e(
574 'Parent category'
575 ); ?>:</label><?php wp_dropdown_categories(
576 array(
577 'hide_empty' => 0,
578 'name' => 'newcat_parent',
579 'orderby' => 'name',
580 'hierarchical' => 1,
581 'show_option_none' => __( 'Parent category' ),
582 'tab_index' => 3
583 )
584 ); ?>
585 <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e(
586 'Add'
587 ); ?>" tabindex="3" />
588 <?php wp_nonce_field( 'add-category', '_ajax_nonce', FALSE ); ?>
589 <span id="category-ajax-response"></span>
590 </p>
591 </div>
592 <?php } ?>
593 </div>
594 <?php
595 }
596
597 /**
598 * Remove the dashboard
599 *
600 * @author Basic Austin Matzko
601 * @see http://www.ilfilosofo.com/blog/2006/05/24/plugin-remove-the-wordpress-dashboard/
602 */
603 function _mw_adminimize_remove_dashboard() {
604
605 global $menu, $user_ID, $wp_version;
606
607 $disabled_menu_ = '';
608 $disabled_submenu_ = '';
609 $user_roles = _mw_adminimize_get_all_user_roles();
610
611 foreach ( $user_roles as $role ) {
612 $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
613 'mw_adminimize_disabled_menu_' . $role . '_items'
614 );
615 $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
616 'mw_adminimize_disabled_submenu_' . $role . '_items'
617 );
618 }
619
620 $disabled_menu_all = array();
621 $disabled_submenu_all = array();
622
623 foreach ( $user_roles as $role ) {
624 array_push( $disabled_menu_all, $disabled_menu_[ $role ] );
625 array_push( $disabled_submenu_all, $disabled_submenu_[ $role ] );
626 }
627
628 // remove dashboard
629 if ( $disabled_menu_all != '' || $disabled_submenu_all != '' ) {
630
631 foreach ( $user_roles as $role ) {
632
633 if ( current_user_can( $role ) ) {
634 if ( _mw_adminimize_recursive_in_array(
635 'index.php', $disabled_menu_[ $role ]
636 )
637 || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
638 ) {
639 $redirect = TRUE;
640 } else {
641 $redirect = FALSE;
642 }
643 }
644 }
645
646 // redirect option, if Dashboard is inactive
647 if ( isset( $redirect ) && $redirect ) {
648 $_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect' );
649 $_mw_adminimize_db_redirect_admin_url = get_option( 'siteurl' ) . '/wp-admin/';
650 switch ( $_mw_adminimize_db_redirect ) {
651 case 0:
652 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'profile.php';
653 break;
654 case 1:
655 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php';
656 break;
657 case 2:
658 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php?post_type=page';
659 break;
660 case 3:
661 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'post-new.php';
662 break;
663 case 4:
664 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'page-new.php';
665 break;
666 case 5:
667 $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit-comments.php';
668 break;
669 case 6:
670 $_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect_txt' );
671 break;
672 }
673
674 // fallback for WP smaller 3.0
675 if ( version_compare(
676 $wp_version, "3.0alpha", "<"
677 )
678 && 'edit.php?post_type=page' == $_mw_adminimize_db_redirect
679 ) {
680 $_mw_adminimize_db_redirect = 'edit-pages.php';
681 }
682
683 $the_user = new WP_User( $user_ID );
684 reset( $menu );
685 $page = key( $menu );
686
687 while ( ( __( 'Dashboard' ) != $menu[ $page ][ 0 ] ) && next( $menu )
688 || ( __(
689 'Dashboard'
690 ) != $menu[ $page ][ 1 ] )
691 && next( $menu ) ) {
692 $page = key( $menu );
693 }
694
695 if ( __( 'Dashboard' ) == $menu[ $page ][ 0 ] || __( 'Dashboard' ) == $menu[ $page ][ 1 ] ) {
696 unset( $menu[ $page ] );
697 }
698 reset( $menu );
699 $page = key( $menu );
700
701 while ( ! $the_user->has_cap( $menu[ $page ][ 1 ] ) && next( $menu ) ) {
702 $page = key( $menu );
703 }
704
705 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
706 wp_redirect( $_mw_adminimize_db_redirect );
707 }
708 }
709
710 }
711 }
712
713 /**
714 * set menu options from database
715 */
716 function _mw_adminimize_set_user_info() {
717
718 global $user_identity, $wp_version;
719
720 // exclude super admin
721 if ( _mw_adminimize_exclude_super_admin() ) {
722 return NULL;
723 }
724
725 $user_roles = _mw_adminimize_get_all_user_roles();
726
727 foreach ( $user_roles as $role ) {
728 $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
729 'mw_adminimize_disabled_menu_' . $role . '_items'
730 );
731 $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
732 'mw_adminimize_disabled_submenu_' . $role . '_items'
733 );
734 }
735
736 $_mw_adminimize_admin_head = "\n";
737 $_mw_adminimize_user_info = _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
738 $_mw_adminimize_ui_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
739
740 // change user-info
741 switch ( $_mw_adminimize_user_info ) {
742 case 1:
743 $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
744 $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove(); });' . "\n";
745 $_mw_adminimize_admin_head .= '</script>' . "\n";
746 break;
747 case 2:
748 if ( version_compare( $wp_version, "3.2alpha", ">=" ) ) {
749 if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
750 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
751 dirname( __FILE__ )
752 ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
753 }
754 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
755 dirname( __FILE__ )
756 ) . '/css/mw_small_user_info32.css" type="text/css" />' . "\n";
757 } elseif ( version_compare( $wp_version, "3.0alpha", ">=" ) ) {
758 if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
759 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
760 dirname( __FILE__ )
761 ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
762 }
763 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
764 dirname( __FILE__ )
765 ) . '/css/mw_small_user_info30.css" type="text/css" />' . "\n";
766 } elseif ( version_compare( substr( $wp_version, 0, 3 ), '2.7', '>=' ) ) {
767 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
768 dirname( __FILE__ )
769 ) . '/css/mw_small_user_info27.css" type="text/css" />' . "\n";
770 } else {
771 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
772 dirname( __FILE__ )
773 ) . '/css/mw_small_user_info.css" type="text/css" />' . "\n";
774 }
775 $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
776 $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
777 if ( $_mw_adminimize_ui_redirect == '1' ) {
778 $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
779 'siteurl'
780 ) . wp_nonce_url(
781 ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
782 ) . '" title="' . __( 'Log Out' ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
783 } else {
784 $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
785 'siteurl'
786 ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . __(
787 'Log Out'
788 ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
789 }
790 $_mw_adminimize_admin_head .= '</script>' . "\n";
791 break;
792 case 3:
793 if ( version_compare( $wp_version, "3.2alpha", ">=" ) ) {
794 if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
795 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
796 dirname( __FILE__ )
797 ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
798 }
799 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
800 dirname( __FILE__ )
801 ) . '/css/mw_small_user_info32.css" type="text/css" />' . "\n";
802 } elseif ( version_compare( $wp_version, "3.0alpha", ">=" ) ) {
803 if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
804 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
805 dirname( __FILE__ )
806 ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
807 }
808 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
809 dirname( __FILE__ )
810 ) . '/css/mw_small_user_info30.css" type="text/css" />' . "\n";
811 } elseif ( version_compare( substr( $wp_version, 0, 3 ), '2.7', '>=' ) ) {
812 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
813 dirname( __FILE__ )
814 ) . '/css/mw_small_user_info27.css" type="text/css" />' . "\n";
815 } else {
816 $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
817 dirname( __FILE__ )
818 ) . '/css/mw_small_user_info.css" type="text/css" />' . "\n";
819 }
820 $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
821 $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
822 if ( $_mw_adminimize_ui_redirect == '1' ) {
823 $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
824 'siteurl'
825 ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
826 'siteurl'
827 ) . wp_nonce_url(
828 ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
829 ) . '" title="' . __( 'Log Out' ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
830 } else {
831 $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
832 'siteurl'
833 ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
834 'siteurl'
835 ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . __(
836 'Log Out'
837 ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
838 }
839 $_mw_adminimize_admin_head .= '</script>' . "\n";
840 break;
841 }
842
843 echo $_mw_adminimize_admin_head;
844 }
845
846 /**
847 * Set menu for settings
848 */
849 function _mw_adminimize_set_menu_option() {
850
851 global $menu, $submenu, $current_screen;
852
853 // exclude super admin
854 if ( _mw_adminimize_exclude_super_admin() ) {
855 return NULL;
856 }
857
858 if ( 'settings_page_adminimize/adminimize' === $current_screen->id ) {
859 return NULL;
860 }
861
862 $user_roles = _mw_adminimize_get_all_user_roles();
863 $disabled_menu_ = '';
864 $disabled_submenu_ = '';
865
866 foreach ( $user_roles as $role ) {
867 $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
868 'mw_adminimize_disabled_menu_' . $role . '_items'
869 );
870 $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
871 'mw_adminimize_disabled_submenu_' . $role . '_items'
872 );
873 }
874
875 $mw_adminimize_menu = '';
876 // set menu
877 if ( isset( $disabled_menu_[ 'editor' ] ) && '' != $disabled_menu_[ 'editor' ] ) {
878
879 // set admin-menu
880 foreach ( $user_roles as $role ) {
881 $user = wp_get_current_user();
882 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
883 if ( current_user_can( $role ) ) {
884 $mw_adminimize_menu = $disabled_menu_[ $role ];
885 $mw_adminimize_submenu = $disabled_submenu_[ $role ];
886 }
887 }
888 }
889
890 // fallback on users.php on all userroles smaller admin
891 if ( is_array( $mw_adminimize_menu ) && in_array( 'users.php', $mw_adminimize_menu ) ) {
892 $mw_adminimize_menu[ ] = 'profile.php';
893 }
894
895 if ( isset( $menu ) && ! empty( $menu ) ) {
896 foreach ( $menu as $index => $item ) {
897 if ( 'index.php' === $item ) {
898 continue;
899 }
900
901 if ( isset( $mw_adminimize_menu ) && in_array( $item[ 2 ], $mw_adminimize_menu ) ) {
902 unset( $menu[ $index ] );
903 }
904
905 if ( isset( $submenu ) && ! empty( $submenu[ $item[ 2 ] ] ) ) {
906 foreach ( $submenu[ $item[ 2 ] ] as $subindex => $subitem ) {
907 if ( isset( $mw_adminimize_submenu ) && in_array( $subitem[ 2 ], $mw_adminimize_submenu ) )
908 //if ( 'profile.php' === $subitem[2] )
909 // unset( $menu[70] );
910 {
911 unset( $submenu[ $item[ 2 ] ][ $subindex ] );
912 }
913 }
914 }
915 }
916 }
917
918 }
919
920 }
921
922 /**
923 * set global options in backend in all areas
924 */
925 function _mw_adminimize_set_global_option() {
926
927 global $_wp_admin_css_colors;
928
929 // exclude super admin
930 if ( _mw_adminimize_exclude_super_admin() ) {
931 return NULL;
932 }
933
934 $user_roles = _mw_adminimize_get_all_user_roles();
935
936 $_mw_adminimize_admin_head = '';
937
938 // remove_action( 'admin_head', 'index_js' );
939
940 foreach ( $user_roles as $role ) {
941 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
942 'mw_adminimize_disabled_global_option_' . $role . '_items'
943 );
944 }
945
946 foreach ( $user_roles as $role ) {
947 if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
948 $disabled_global_option_[ $role ][ '0' ] = '';
949 }
950 }
951
952 $global_options = '';
953 // new 1.7.8
954 foreach ( $user_roles as $role ) {
955 $user = wp_get_current_user();
956 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
957 if ( current_user_can( $role )
958 && isset( $disabled_global_option_[ $role ] )
959 && is_array( $disabled_global_option_[ $role ] )
960 ) {
961 $global_options = implode( ', ', $disabled_global_option_[ $role ] );
962 }
963 }
964 }
965 if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
966 $_wp_admin_css_colors = 0;
967 }
968 $_mw_adminimize_admin_head .= '<!-- global options -->' . "\n";
969 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display: none !important;}</style>' . "\n";
970
971 if ( ! empty( $global_options ) ) {
972 echo $_mw_adminimize_admin_head;
973 }
974 }
975
976 /**
977 * set metabox options from database an area post
978 */
979 function _mw_adminimize_set_metabox_post_option() {
980
981 // exclude super admin
982 if ( _mw_adminimize_exclude_super_admin() ) {
983 return NULL;
984 }
985
986 $user_roles = _mw_adminimize_get_all_user_roles();
987 $_mw_adminimize_admin_head = '';
988 $metaboxes = '';
989
990 foreach ( $user_roles as $role ) {
991 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
992 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
993 );
994
995 if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
996 $disabled_metaboxes_post_[ $role ][ '0' ] = '';
997 }
998
999 // new 1.7.8
1000 $user = wp_get_current_user();
1001 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
1002 if ( current_user_can( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
1003 && is_array(
1004 $disabled_metaboxes_post_[ $role ]
1005 )
1006 ) {
1007 $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
1008 }
1009 }
1010 }
1011
1012 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1013 $metaboxes . ' {display: none !important;}</style>' . "\n";
1014
1015 if ( ! empty( $metaboxes ) ) {
1016 echo $_mw_adminimize_admin_head;
1017 }
1018 }
1019
1020 /**
1021 * set metabox options from database an area page
1022 */
1023 function _mw_adminimize_set_metabox_page_option() {
1024
1025 // exclude super admin
1026 if ( _mw_adminimize_exclude_super_admin() ) {
1027 return NULL;
1028 }
1029
1030 $user_roles = _mw_adminimize_get_all_user_roles();
1031 $_mw_adminimize_admin_head = '';
1032 $metaboxes = '';
1033
1034 foreach ( $user_roles as $role ) {
1035 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
1036 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
1037 );
1038
1039 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
1040 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
1041 }
1042
1043 // new 1.7.8
1044 $user = wp_get_current_user();
1045 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
1046 if ( current_user_can( $role )
1047 && isset( $disabled_metaboxes_page_[ $role ] )
1048 && is_array( $disabled_metaboxes_page_[ $role ] )
1049 ) {
1050 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
1051 }
1052 }
1053 }
1054
1055 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1056 $metaboxes . ' {display: none !important;}</style>' . "\n";
1057
1058 if ( ! empty( $metaboxes ) ) {
1059 echo $_mw_adminimize_admin_head;
1060 }
1061 }
1062
1063 /**
1064 * set metabox options from database an area post
1065 */
1066 function _mw_adminimize_set_metabox_cp_option() {
1067
1068 // exclude super admin
1069 if ( _mw_adminimize_exclude_super_admin() ) {
1070 return NULL;
1071 }
1072
1073 if ( isset( $_GET[ 'post' ] ) ) {
1074 $post_id = (int) $_GET[ 'post' ];
1075 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
1076 $post_id = (int) $_POST[ 'post_ID' ];
1077 } else {
1078 $post_id = 0;
1079 }
1080
1081 $current_post_type = $GLOBALS[ 'post_type' ];
1082 if ( ! isset( $current_post_type ) ) {
1083 $current_post_type = get_post_type( $post_id );
1084 }
1085
1086 if ( ! isset( $current_post_type ) || ! $current_post_type ) {
1087 $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
1088 }
1089
1090 // set hard to post
1091 if ( ! $current_post_type ) {
1092 $current_post_type = 'post';
1093 }
1094
1095 $user_roles = _mw_adminimize_get_all_user_roles();
1096 $_mw_adminimize_admin_head = '';
1097 $metaboxes = '';
1098
1099 foreach ( $user_roles as $role ) {
1100 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
1101 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
1102 );
1103
1104 if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
1105 $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
1106 }
1107
1108 $user = wp_get_current_user();
1109 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
1110 if ( current_user_can( $role )
1111 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
1112 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
1113 ) {
1114 $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
1115 }
1116 }
1117 }
1118
1119 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1120 $metaboxes . ' {display: none !important;}</style>' . "\n";
1121
1122 if ( ! empty( $metaboxes ) ) {
1123 echo $_mw_adminimize_admin_head;
1124 }
1125 }
1126
1127 /**
1128 * set link options in area Links of Backend
1129 */
1130 function _mw_adminimize_set_link_option() {
1131
1132 // exclude super admin
1133 if ( _mw_adminimize_exclude_super_admin() ) {
1134 return NULL;
1135 }
1136
1137 $user_roles = _mw_adminimize_get_all_user_roles();
1138
1139 $_mw_adminimize_admin_head = '';
1140
1141 // remove_action( 'admin_head', 'index_js' );
1142
1143 foreach ( $user_roles as $role ) {
1144 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
1145 'mw_adminimize_disabled_link_option_' . $role . '_items'
1146 );
1147 }
1148
1149 foreach ( $user_roles as $role ) {
1150 if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
1151 $disabled_link_option_[ $role ][ '0' ] = '';
1152 }
1153 }
1154
1155 $link_options = '';
1156 // new 1.7.8
1157 foreach ( $user_roles as $role ) {
1158 $user = wp_get_current_user();
1159 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
1160 if ( current_user_can( $role )
1161 && isset( $disabled_link_option_[ $role ] )
1162 && is_array( $disabled_link_option_[ $role ] )
1163 ) {
1164 $link_options = implode( ',', $disabled_link_option_[ $role ] );
1165 }
1166 }
1167 }
1168 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1169 $link_options . ' {display: none !important;}</style>' . "\n";
1170
1171 if ( ! empty( $link_options ) ) {
1172 echo $_mw_adminimize_admin_head;
1173 }
1174 }
1175
1176 /**
1177 * remove objects on wp nav menu
1178 */
1179 function _mw_adminimize_set_nav_menu_option() {
1180
1181 // exclude super admin
1182 if ( _mw_adminimize_exclude_super_admin() ) {
1183 return NULL;
1184 }
1185
1186 $user_roles = _mw_adminimize_get_all_user_roles();
1187
1188 $_mw_adminimize_admin_head = '';
1189
1190 // remove_action( 'admin_head', 'index_js' );
1191
1192 foreach ( $user_roles as $role ) {
1193 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
1194 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
1195 );
1196 }
1197
1198 foreach ( $user_roles as $role ) {
1199 if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
1200 $disabled_nav_menu_option_[ $role ][ '0' ] = '';
1201 }
1202 }
1203
1204 $nav_menu_options = '';
1205 // new 1.7.8
1206 foreach ( $user_roles as $role ) {
1207 $user = wp_get_current_user();
1208 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
1209 if ( current_user_can( $role )
1210 && isset( $disabled_nav_menu_option_[ $role ] )
1211 && is_array( $disabled_nav_menu_option_[ $role ] )
1212 ) {
1213 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1214 }
1215 }
1216 }
1217 //remove_meta_box( $id, 'nav-menus', 'side' );
1218 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1219 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1220
1221 if ( $nav_menu_options ) {
1222 echo $_mw_adminimize_admin_head;
1223 }
1224 }
1225
1226 /**
1227 * Remove areas in Widget Settings
1228 */
1229 function _mw_adminimize_set_widget_option() {
1230
1231 // exclude super admin
1232 if ( _mw_adminimize_exclude_super_admin() ) {
1233 return NULL;
1234 }
1235
1236 $user_roles = _mw_adminimize_get_all_user_roles();
1237
1238 $_mw_adminimize_admin_head = '';
1239
1240 foreach ( $user_roles as $role ) {
1241 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
1242 'mw_adminimize_disabled_widget_option_' . $role . '_items'
1243 );
1244 }
1245
1246 foreach ( $user_roles as $role ) {
1247 if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
1248 $disabled_widget_option_[ $role ][ '0' ] = '';
1249 }
1250 }
1251
1252 $widget_options = '';
1253 // new 1.7.8
1254 foreach ( $user_roles as $role ) {
1255 $user = wp_get_current_user();
1256 if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
1257 if ( current_user_can( $role )
1258 && isset( $disabled_widget_option_[ $role ] )
1259 && is_array( $disabled_widget_option_[ $role ] )
1260 ) {
1261 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1262 }
1263 }
1264 }
1265 //remove_meta_box( $id, 'nav-menus', 'side' );
1266 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1267 $widget_options . ' {display: none !important;}</style>' . "\n";
1268
1269 if ( $widget_options ) {
1270 echo $_mw_adminimize_admin_head;
1271 }
1272 }
1273
1274 /**
1275 * small user-info
1276 */
1277 function _mw_adminimize_small_user_info() {
1278
1279 ?>
1280 <div id="small_user_info">
1281 <p>
1282 <a href="<?php echo wp_nonce_url(
1283 site_url( 'wp-login.php?action=logout' ),
1284 'log-out'
1285 ) ?>"
1286 title="<?php _e( 'Log Out' ) ?>"><?php _e( 'Log Out' ); ?></a>
1287 </p>
1288 </div>
1289 <?php
1290 }
1291
1292 /**
1293 * include options-page in wp-admin
1294 */
1295 // include helping functions
1296 require_once( 'inc-setup/helping_hands.php' );
1297
1298 // inc. settings page
1299 require_once( 'adminimize_page.php' );
1300 // @ToDO release XML Ex-Import
1301 //require_once( 'inc-options/class-eximport.php' );
1302
1303 // dashboard options
1304 require_once( 'inc-setup/dashboard.php' );
1305
1306 // widget options
1307 require_once( 'inc-setup/widget.php' );
1308 require_once( 'inc-setup/admin-footer.php' );
1309
1310 // global settings
1311 //require_once( 'inc-options/settings_notice.php' );
1312 // remove admin bar
1313 require_once( 'inc-setup/remove-admin-bar.php' );
1314
1315 // admin bar helper, setup
1316 // work always in frontend
1317 require_once( 'inc-setup/admin-bar-items.php' );
1318 // meta boxes helper, setup
1319 //require_once( 'inc-setup/meta-boxes.php' );
1320
1321 /**
1322 * @version WP 2.8
1323 * Add action link(s) to plugins page
1324 *
1325 * @param $links , $file
1326 *
1327 * @param $file
1328 *
1329 * @return $links
1330 */
1331 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1332
1333 /* create link */
1334 if ( FB_ADMINIMIZE_BASENAME == $file ) {
1335 array_unshift(
1336 $links,
1337 sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, __( 'Settings' ) )
1338 );
1339 }
1340
1341 return $links;
1342 }
1343
1344 /**
1345 * settings in plugin-admin-page
1346 */
1347 function _mw_adminimize_add_settings_page() {
1348
1349 /*
1350 * Maybe later
1351 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
1352 $pagehook = add_submenu_page(
1353 'settings.php',
1354 __( 'Adminimize Network Options', FB_ADMINIMIZE_TEXTDOMAIN ),
1355 __( 'Adminimize', FB_ADMINIMIZE_TEXTDOMAIN ),
1356 'manage_options',
1357 plugin_basename( __FILE__ ),
1358 '_mw_adminimize_options'
1359 );
1360 }
1361 */
1362 $pagehook = add_options_page(
1363 __( 'Adminimize Options', FB_ADMINIMIZE_TEXTDOMAIN ),
1364 __( 'Adminimize', FB_ADMINIMIZE_TEXTDOMAIN ),
1365 'manage_options',
1366 __FILE__,
1367 '_mw_adminimize_options'
1368 );
1369 if ( ! is_network_admin() ) {
1370 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1371 }
1372 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1373 }
1374
1375 function _mw_adminimize_on_load_page() {
1376
1377 wp_register_style( 'adminimize-style', plugins_url( 'css/style.css', __FILE__ ) );
1378 wp_enqueue_style( 'adminimize-style' );
1379
1380 wp_register_script(
1381 'adminimize-settings-script',
1382 plugins_url( 'js/adminimize.js', __FILE__ ),
1383 array( 'jquery' ),
1384 '05/02/2013',
1385 TRUE
1386 );
1387 wp_enqueue_script( 'adminimize-settings-script' );
1388 }
1389
1390 /**
1391 * Set theme for users
1392 * Kill with version 1.7.18
1393 */
1394 function _mw_adminimize_set_theme() {
1395
1396 if ( ! current_user_can( 'edit_users' ) ) {
1397 wp_die( __( 'Cheatin&#8217; uh?' ) );
1398 }
1399
1400 $user_ids = $_POST[ 'mw_adminimize_theme_items' ];
1401 $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
1402
1403 if ( ! $user_ids ) {
1404 return FALSE;
1405 }
1406
1407 foreach ( $user_ids as $user_id ) {
1408 update_user_meta( $user_id, 'admin_color', $admin_color );
1409 }
1410
1411 return TRUE;
1412 }
1413
1414 /**
1415 * read options
1416 *
1417 * @param $key
1418 *
1419 * @return null
1420 */
1421 function _mw_adminimize_get_option_value( $key ) {
1422
1423 // check for use on multisite
1424 if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
1425 $adminimizeoptions = get_site_option( 'mw_adminimize' );
1426 } else {
1427 $adminimizeoptions = get_option( 'mw_adminimize' );
1428 }
1429
1430 return ( isset( $adminimizeoptions[ $key ] ) ) ?
1431 ( $adminimizeoptions[ $key ] ) : NULL;
1432 }
1433
1434 /**
1435 * Update options in database
1436 */
1437 function _mw_adminimize_update() {
1438
1439 $user_roles = _mw_adminimize_get_all_user_roles();
1440 $args = array( 'public' => TRUE, '_builtin' => FALSE );
1441 $post_types = get_post_types( $args );
1442
1443 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
1444 'mw_adminimize_admin_bar_nodes'
1445 );
1446 // admin bar options
1447 foreach ( $user_roles as $role ) {
1448 // admin abr options
1449 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
1450 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
1451 } else {
1452 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1453 }
1454 }
1455
1456 if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
1457 $adminimizeoptions[ '_mw_adminimize_user_info' ] = strip_tags(
1458 stripslashes( $_POST[ '_mw_adminimize_user_info' ] )
1459 );
1460 } else {
1461 $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
1462 }
1463
1464 if ( isset( $_POST[ '_mw_adminimize_dashmenu' ] ) ) {
1465 $adminimizeoptions[ '_mw_adminimize_dashmenu' ] = strip_tags(
1466 stripslashes( $_POST[ '_mw_adminimize_dashmenu' ] )
1467 );
1468 } else {
1469 $adminimizeoptions[ '_mw_adminimize_dashmenu' ] = 0;
1470 }
1471
1472 if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
1473 $adminimizeoptions[ '_mw_adminimize_footer' ] = strip_tags( stripslashes( $_POST[ '_mw_adminimize_footer' ] ) );
1474 } else {
1475 $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
1476 }
1477
1478 if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
1479 $adminimizeoptions[ '_mw_adminimize_header' ] = strip_tags( stripslashes( $_POST[ '_mw_adminimize_header' ] ) );
1480 } else {
1481 $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
1482 }
1483
1484 if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
1485 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = strip_tags(
1486 stripslashes( $_POST[ '_mw_adminimize_exclude_super_admin' ] )
1487 );
1488 } else {
1489 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
1490 }
1491
1492 if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
1493 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = strip_tags(
1494 stripslashes( $_POST[ '_mw_adminimize_tb_window' ] )
1495 );
1496 } else {
1497 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
1498 }
1499
1500 if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
1501 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = strip_tags(
1502 stripslashes( $_POST[ '_mw_adminimize_cat_full' ] )
1503 );
1504 } else {
1505 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
1506 }
1507
1508 if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
1509 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = strip_tags(
1510 stripslashes( $_POST[ '_mw_adminimize_db_redirect' ] )
1511 );
1512 } else {
1513 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
1514 }
1515
1516 if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
1517 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = strip_tags(
1518 stripslashes( $_POST[ '_mw_adminimize_ui_redirect' ] )
1519 );
1520 } else {
1521 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
1522 }
1523
1524 if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
1525 $adminimizeoptions[ '_mw_adminimize_advice' ] = strip_tags( stripslashes( $_POST[ '_mw_adminimize_advice' ] ) );
1526 } else {
1527 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1528 }
1529
1530 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1531 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] );
1532 } else {
1533 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = 0;
1534 }
1535
1536 if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
1537 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = strip_tags(
1538 stripslashes( $_POST[ '_mw_adminimize_timestamp' ] )
1539 );
1540 } else {
1541 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
1542 }
1543
1544 if ( isset( $_POST[ '_mw_adminimize_control_flashloader' ] ) ) {
1545 $adminimizeoptions[ '_mw_adminimize_control_flashloader' ] = strip_tags(
1546 stripslashes( $_POST[ '_mw_adminimize_control_flashloader' ] )
1547 );
1548 } else {
1549 $adminimizeoptions[ '_mw_adminimize_control_flashloader' ] = 0;
1550 }
1551
1552 if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
1553 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = stripslashes(
1554 $_POST[ '_mw_adminimize_db_redirect_txt' ]
1555 );
1556 } else {
1557 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = 0;
1558 }
1559
1560 // menu update
1561 foreach ( $user_roles as $role ) {
1562 if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
1563 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
1564 } else {
1565 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1566 }
1567
1568 if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
1569 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
1570 } else {
1571 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1572 }
1573 }
1574
1575 // global_options, metaboxes update
1576 foreach ( $user_roles as $role ) {
1577
1578 // global options
1579 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1580 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1581 } else {
1582 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1583 }
1584
1585 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
1586 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
1587 } else {
1588 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1589 }
1590
1591 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
1592 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
1593 } else {
1594 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1595 }
1596
1597 foreach ( $post_types as $post_type ) {
1598 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] ) ) {
1599 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ];
1600 } else {
1601 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1602 }
1603 }
1604
1605 if ( isset( $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] ) ) {
1606 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ];
1607 } else {
1608 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = array();
1609 }
1610
1611 // wp nav menu options
1612 if ( isset( $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] ) ) {
1613 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ];
1614 } else {
1615 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = array();
1616 }
1617
1618 // widget options
1619 if ( isset( $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] ) ) {
1620 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ];
1621 } else {
1622 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = array();
1623 }
1624
1625 // wp dashboard option
1626 if ( isset( $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] ) ) {
1627 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ];
1628 } else {
1629 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = array();
1630 }
1631 }
1632
1633 // own options
1634 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1635 $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1636 } else {
1637 $adminimizeoptions[ '_mw_adminimize_own_values' ] = 0;
1638 }
1639
1640 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1641 $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1642 } else {
1643 $adminimizeoptions[ '_mw_adminimize_own_options' ] = 0;
1644 }
1645
1646 // own post options
1647 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1648 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1649 $_POST[ '_mw_adminimize_own_post_values' ]
1650 );
1651 } else {
1652 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = 0;
1653 }
1654
1655 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1656 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1657 $_POST[ '_mw_adminimize_own_post_options' ]
1658 );
1659 } else {
1660 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = 0;
1661 }
1662
1663 // own page options
1664 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1665 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1666 $_POST[ '_mw_adminimize_own_page_values' ]
1667 );
1668 } else {
1669 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = 0;
1670 }
1671
1672 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1673 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1674 $_POST[ '_mw_adminimize_own_page_options' ]
1675 );
1676 } else {
1677 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = 0;
1678 }
1679
1680 // own custom post options
1681 foreach ( $post_types as $post_type ) {
1682 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1683 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1684 $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1685 );
1686 } else {
1687 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = 0;
1688 }
1689
1690 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1691 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1692 $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1693 );
1694 } else {
1695 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = 0;
1696 }
1697 }
1698
1699 // own link options
1700 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1701 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1702 $_POST[ '_mw_adminimize_own_link_values' ]
1703 );
1704 } else {
1705 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = 0;
1706 }
1707
1708 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1709 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1710 $_POST[ '_mw_adminimize_own_link_options' ]
1711 );
1712 } else {
1713 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = 0;
1714 }
1715
1716 // wp nav menu options
1717 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1718 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1719 $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1720 );
1721 } else {
1722 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = 0;
1723 }
1724
1725 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1726 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1727 $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1728 );
1729 } else {
1730 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = 0;
1731 }
1732
1733 // widget options
1734 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1735 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1736 $_POST[ '_mw_adminimize_own_widget_values' ]
1737 );
1738 } else {
1739 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = 0;
1740 }
1741
1742 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1743 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1744 $_POST[ '_mw_adminimize_own_widget_options' ]
1745 );
1746 } else {
1747 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = 0;
1748 }
1749
1750 // own dashboard options
1751 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1752 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1753 $_POST[ '_mw_adminimize_own_dashboard_values' ]
1754 );
1755 } else {
1756 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = 0;
1757 }
1758
1759 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1760 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1761 $_POST[ '_mw_adminimize_own_dashboard_options' ]
1762 );
1763 } else {
1764 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = 0;
1765 }
1766
1767 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_option_value(
1768 'mw_adminimize_dashboard_widgets'
1769 );
1770
1771 if ( isset( $GLOBALS[ 'menu' ] ) ) {
1772 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $GLOBALS[ 'menu' ];
1773 }
1774 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1775 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1776 }
1777
1778 //update_option( 'mw_adminimize1', $adminimizeoptions['mw_adminimize_disabled_admin_bar_administrator_items'] );
1779 //update_site_option( 'mw_adminimize1', $adminimizeoptions['mw_adminimize_disabled_admin_bar_administrator_items'] );
1780 // update
1781 if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
1782 update_site_option( 'mw_adminimize', $adminimizeoptions );
1783 } else {
1784 update_option( 'mw_adminimize', $adminimizeoptions );
1785 }
1786
1787 $myErrors = new _mw_adminimize_message_class();
1788 $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1789 '_mw_adminimize_update'
1790 ) . '</p></div>';
1791 echo $myErrors;
1792 }
1793
1794 /**
1795 * Delete options in database
1796 */
1797 function _mw_adminimize_deinstall() {
1798
1799 delete_site_option( 'mw_adminimize' );
1800 delete_option( 'mw_adminimize' );
1801 }
1802
1803 /**
1804 * Install options in database
1805 */
1806 function _mw_adminimize_install() {
1807
1808 if ( ! is_admin() ) {
1809 return NULL;
1810 }
1811
1812 global $menu, $submenu;
1813
1814 $user_roles = _mw_adminimize_get_all_user_roles();
1815 $adminimizeoptions = array();
1816
1817 foreach ( $user_roles as $role ) {
1818 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1819 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1820 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1821 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1822 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1823 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1824 $args = array(
1825 'public' => TRUE,
1826 '_builtin' => FALSE
1827 );
1828 foreach ( get_post_types( $args ) as $post_type ) {
1829 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1830 }
1831 }
1832
1833 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
1834 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
1835
1836 if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
1837 add_site_option( 'mw_adminimize', $adminimizeoptions );
1838 } else {
1839 add_option( 'mw_adminimize', $adminimizeoptions );
1840 }
1841 }
1842
1843 /**
1844 * export options in file
1845 */
1846 function _mw_adminimize_export() {
1847
1848 global $wpdb;
1849
1850 $filename = 'adminimize_export-' . date( 'Y-m-d_G-i-s' ) . '.seq';
1851
1852 header( "Content-Description: File Transfer" );
1853 header( "Content-Disposition: attachment; filename=" . urlencode( $filename ) );
1854 header( "Content-Type: application/force-download" );
1855 header( "Content-Type: application/octet-stream" );
1856 header( "Content-Type: application/download" );
1857 header( 'Content-Type: text/seq; charset=' . get_option( 'blog_charset' ), TRUE );
1858 flush();
1859
1860 $export_data = mysql_query( "SELECT option_value FROM $wpdb->options WHERE option_name = 'mw_adminimize'" );
1861 $export_data = mysql_result( $export_data, 0 );
1862 echo $export_data;
1863 flush();
1864 }
1865
1866 /**
1867 * import options in table _options
1868 */
1869 function _mw_adminimize_import() {
1870
1871 // check file extension
1872 $str_file_name = $_FILES[ 'datei' ][ 'name' ];
1873 $str_file_ext = explode( ".", $str_file_name );
1874
1875 if ( $str_file_ext[ 1 ] != 'seq' ) {
1876 wp_die( 'No exist.' );
1877 } elseif ( file_exists( $_FILES[ 'datei' ][ 'name' ] ) ) {
1878 wp_die( 'Exist.' );
1879 } else {
1880 // path for file
1881 $str_ziel = WP_CONTENT_DIR . '/' . $_FILES[ 'datei' ][ 'name' ];
1882 // transfer
1883 move_uploaded_file( $_FILES[ 'datei' ][ 'tmp_name' ], $str_ziel );
1884 // access authorization
1885 chmod( $str_ziel, 0644 );
1886 // SQL import
1887 ini_set( 'default_socket_timeout', 120 );
1888 $import_file = file_get_contents( $str_ziel );
1889
1890 _mw_adminimize_deinstall();
1891 $import_file = unserialize( $import_file );
1892
1893 if ( file_exists( $str_ziel ) ) {
1894 unlink( $str_ziel );
1895 }
1896
1897 if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
1898 update_site_option( 'mw_adminimize', $import_file );
1899 } else {
1900 update_option( 'mw_adminimize', $import_file );
1901 }
1902
1903 if ( file_exists( $str_ziel ) ) {
1904 unlink( $str_ziel );
1905 }
1906
1907 }
1908
1909 $myErrors = new _mw_adminimize_message_class();
1910 $myErrors = '<div id="message" class="updated fade"><p>' .
1911 $myErrors->get_error( '_mw_adminimize_import' ) . '</p></div>';
1912
1913 echo $myErrors;
1914 }
1915