PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.1
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.9.1, at adminimize.php

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