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
← All changes | adminimize.php +426 -347 1.11.4 → 1.9.1 View file →
@@ -6,17 +6,15 @@
6 6 * Domain Path: /languages
7 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 8 * Author: Frank Bültge
9 9 * Author URI: http://bueltge.de/
10 - * Version: 1.11.4
11 - * License: GPLv3+
10 + * Version: 1.9.1
11 + * License: GPLv2+
12 12 *
13 - * Php Version 5.6
14 - *
15 13 * @package WordPress
16 14 * @author Frank Bültge <[email protected]>
17 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 - * @version 2017-12-14
16 + * @version 2016-01-25
19 17 */
20 18
21 19 /**
22 20 * The stylesheet and the initial idea is from Eric A. Meyer http://meyerweb.com/
@@ -23,9 +21,8 @@
23 21 * I have written a plugin with many options on the basis idea
24 22 * of differently user-right and a user-friendly range in admin-area via reduce areas.
25 23 * :( grmpf i have so much wishes and hints form users, there use the plugin and
26 24 * it is not easy to development this on my free time.
27 - * Also I hate the source, old and hard to maintain, no OOP.
28 25 */
29 26
30 27 if ( ! function_exists( 'add_action' ) ) {
31 28 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
@@ -33,17 +30,10 @@
33 30 }
34 31
35 32 // plugin definitions
36 33 define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
37 -define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( __DIR__ ) );
34 +define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
38 35
39 -/**
40 - * Return data from the plugin.
41 - *
42 - * @param string $value
43 - *
44 - * @return mixed
45 - */
46 36 function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
47 37
48 38 if ( ! function_exists( 'get_plugin_data' ) ) {
49 39 require_once ABSPATH . '/wp-admin/includes/plugin.php';
@@ -48,11 +38,12 @@
48 38 if ( ! function_exists( 'get_plugin_data' ) ) {
49 39 require_once ABSPATH . '/wp-admin/includes/plugin.php';
50 40 }
51 41
52 - $plugin_data = get_plugin_data( __FILE__ );
42 + $plugin_data = get_plugin_data( __FILE__ );
43 + $plugin_value = $plugin_data[ $value ];
53 44
54 - return $plugin_data[ $value ];
45 + return $plugin_value;
55 46 }
56 47
57 48 /**
58 49 * Load language files.
@@ -94,32 +85,21 @@
94 85 * @return bool
95 86 */
96 87 function _mw_adminimize_exclude_settings_page() {
97 88
98 - if ( ! is_admin() ) {
99 - return FALSE;
89 + if ( ! function_exists( 'get_current_screen' ) ) {
90 + return TRUE;
100 91 }
101 92
102 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
103 - return FALSE;
104 - }
93 + // Get admin page
94 + $screen = get_current_screen();
105 95
106 - $page = '';
107 - if ( isset( $_GET[ 'page' ] ) ) {
108 - $page = esc_attr( $_GET[ 'page' ] );
96 + // Don't filter on settings page
97 + if ( isset( $screen->id ) && FALSE !== strpos( $screen->id, 'adminimize' ) ) {
98 + return TRUE;
109 99 }
110 100
111 - $screen = $page;
112 - if ( function_exists( 'get_current_screen' ) ) {
113 - $screen_tmp = get_current_screen();
114 - }
115 -
116 - if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
117 - $screen = $screen_tmp->id;
118 - }
119 -
120 - // Don't filter on settings page
121 - return FALSE !== strpos( $screen, 'adminimize' );
101 + return FALSE;
122 102 }
123 103
124 104 /**
125 105 * Get status, if the plugin active network wide.
@@ -128,12 +108,12 @@
128 108 */
129 109 function _mw_adminimize_is_active_on_multisite() {
130 110
131 111 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
132 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
112 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
133 113 }
134 114
135 - if ( is_multisite() && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME ) ) {
115 + if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
136 116 return TRUE;
137 117 }
138 118
139 119 return FALSE;
@@ -147,27 +127,25 @@
147 127 * @return array $user_roles
148 128 */
149 129 function _mw_adminimize_get_all_user_roles() {
150 130
151 - /** @var $wp_roles WP_Roles */
152 131 global $wp_roles;
153 132
154 133 $user_roles = array();
155 134
156 135 if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
136 + /** @var array $wp_roles */
157 137 foreach ( $wp_roles->roles as $role => $data ) {
158 138 $user_roles[] = $role;
159 - // The $data var contains caps, maybe for later use.
139 + //$data contains caps, maybe for later use..
160 140 }
161 141 }
162 142
163 143 // Exclude the new bbPress roles.
164 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
165 - $user_roles = array_diff(
166 - $user_roles,
167 - array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
168 - );
169 - }
144 + $user_roles = array_diff(
145 + $user_roles,
146 + array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
147 + );
170 148
171 149 return $user_roles;
172 150 }
173 151
@@ -179,55 +157,56 @@
179 157 * @return array $user_roles_names
180 158 */
181 159 function _mw_adminimize_get_all_user_roles_names() {
182 160
183 - /** @var $wp_roles WP_Roles */
184 161 global $wp_roles;
162 +
185 163 $user_roles_names = array();
186 164
165 + /** @var array $wp_roles */
187 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 + }
188 172
189 - $data = translate_user_role( $data );
190 173 $user_roles_names[] = $data;
191 174 }
192 175
193 176 // exclude the new bbPress roles
194 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
195 - $user_roles_names = array_diff(
196 - $user_roles_names,
197 - array(
198 - esc_attr__( 'Keymaster', 'bbpress' ),
199 - esc_attr__( 'Moderator', 'bbpress' ),
200 - esc_attr__( 'Participant', 'bbpress' ),
201 - esc_attr__( 'Spectator', 'bbpress' ),
202 - esc_attr__( 'Blocked', 'bbpress' ),
203 - )
204 - );
205 - }
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 + );
206 187
207 188 return $user_roles_names;
208 189 }
209 190
210 191 /**
211 - * Get post type.
212 - *
213 - * @return null|string String of the post type.
192 + * return post type
214 193 */
215 -function _mw_adminimize_get_current_post_type() {
194 +function _mw_get_current_post_type() {
216 195
217 196 global $post, $typenow, $current_screen;
218 197
219 - // We have a post so we can just get the post type from that.
198 + //we have a post so we can just get the post type from that
220 199 if ( $post && $post->post_type ) {
221 200 return $post->post_type;
222 - } // Check the global $typenow - set in admin.php
223 - elseif ( $typenow ) {
201 + } //check the global $typenow - set in admin.php
202 + else if ( $typenow ) {
224 203 return $typenow;
225 204 } // check the global $current_screen object - set in sceen.php
226 - elseif ( $current_screen && $current_screen->post_type ) {
205 + else if ( $current_screen && $current_screen->post_type ) {
227 206 return $current_screen->post_type;
228 207 } // lastly check the post_type querystring
229 - elseif ( isset( $_REQUEST[ 'post_type' ] ) ) {
208 + else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
230 209 return sanitize_key( $_REQUEST[ 'post_type' ] );
231 210 }
232 211
233 212 // we do not know the post type!
@@ -240,13 +219,14 @@
240 219 function _mw_adminimize_admin_init() {
241 220
242 221 global $pagenow, $post_type, $menu, $submenu;
243 222
244 - $post_id = 0;
245 223 if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
246 224 $post_id = (int) esc_attr( $_GET[ 'post' ] );
247 225 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
248 226 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
227 + } else {
228 + $post_id = 0;
249 229 }
250 230
251 231 $current_post_type = $post_type;
252 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
@@ -252,15 +232,16 @@
252 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
253 233 $current_post_type = get_post_type( $post_id );
254 234 }
255 235 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
256 - $current_post_type = _mw_adminimize_get_current_post_type();
236 + $current_post_type = _mw_get_current_post_type();
257 237 }
258 - if ( ! $current_post_type ) { // set hard to post
238 + if ( ! $current_post_type ) // set hard to post
239 + {
259 240 $current_post_type = 'post';
260 241 }
261 242
262 - // Get all user roles.
243 + // Get all user rolles.
263 244 $user_roles = _mw_adminimize_get_all_user_roles();
264 245
265 246 // Get settings.
266 247 $adminimizeoptions = _mw_adminimize_get_option_value();
@@ -284,9 +265,9 @@
284 265 // widget pages
285 266 $widget_pages = array( 'widgets.php' );
286 267
287 268 foreach ( $user_roles as $role ) {
288 - $disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
269 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
289 270 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
290 271 );
291 272 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
292 273 'mw_adminimize_disabled_global_option_' . $role . '_items'
@@ -316,11 +297,21 @@
316 297 }
317 298
318 299 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
319 300
320 - // Backend options
301 + // global options
321 302 // exclude super admin
322 - if ( ! _mw_adminimize_exclude_super_admin() && ! _mw_adminimize_exclude_settings_page() ) {
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 + }
323 314
324 315 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
325 316 switch ( $_mw_adminimize_header ) {
326 317 case 1:
@@ -331,10 +322,10 @@
331 322 );
332 323 break;
333 324 }
334 325
335 - // Post-page options.
336 - if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
326 + //post-page options
327 + if ( in_array( $pagenow, $def_post_pages, FALSE ) ) {
337 328
338 329 $_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
339 330 switch ( $_mw_adminimize_tb_window ) {
340 331 case 1:
@@ -356,9 +347,9 @@
356 347 );
357 348 break;
358 349 }
359 350
360 - // Category options.
351 + //category options
361 352 $_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
362 353 switch ( $_mw_adminimize_cat_full ) {
363 354 case 1:
364 355 wp_enqueue_style(
@@ -367,9 +358,9 @@
367 358 );
368 359 break;
369 360 }
370 361
371 - // Set default editor tinymce
362 + // set default editor tinymce
372 363 if ( _mw_adminimize_recursive_in_array(
373 364 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
374 365 $disabled_metaboxes_page_all
375 366 )
@@ -377,21 +368,12 @@
377 368 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
378 369 $disabled_metaboxes_post_all
379 370 )
380 371 ) {
381 - add_filter( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
382 - /**
383 - * Return string tinymce.
384 - * Necessary for php 5.2 usage :(; not possible to use an anonymous function.
385 - *
386 - * @return string
387 - */
388 - function _mw_admininimize_return_tinmyce() {
389 - return 'tinymce';
390 - }
372 + add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
391 373 }
392 374
393 - // Remove media buttons
375 + // remove media bottons
394 376 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
395 377 || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
396 378 ) {
397 379 remove_action( 'media_buttons', 'media_buttons' );
@@ -396,53 +378,77 @@
396 378 ) {
397 379 remove_action( 'media_buttons', 'media_buttons' );
398 380 }
399 381 }
382 +
400 383 }
401 384
402 - // set meta-box post option
403 - if ( in_array( $pagenow, $def_post_pages, TRUE ) && in_array( $current_post_type, $def_post_types, TRUE ) ) {
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 ) ) {
404 392 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
405 393 }
406 - // set meta-box page option
407 - if ( in_array( $pagenow, $def_page_pages, TRUE ) && in_array( $current_post_type, $def_page_types, TRUE ) ) {
394 + // set metabox page option
395 + if ( in_array( $pagenow, $def_page_pages, FALSE ) && in_array( $current_post_type, $def_page_types, FALSE ) ) {
408 396 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
409 397 }
410 398 // set custom post type options
411 - if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
412 - && in_array( $current_post_type, $def_custom_types, TRUE )
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 + )
413 403 ) {
414 404 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
415 405 }
416 406 // set link option
417 - if ( in_array( $pagenow, $link_pages, TRUE ) ) {
407 + if ( in_array( $pagenow, $link_pages, FALSE ) ) {
418 408 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
419 409 }
420 410 // set wp nav menu options
421 - if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
411 + if ( in_array( $pagenow, $nav_menu_pages, FALSE ) ) {
422 412 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
423 413 }
424 414 // set widget options
425 - if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
415 + if ( in_array( $pagenow, $widget_pages, FALSE ) ) {
426 416 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
427 417 }
418 +
419 + $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
420 + $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
428 421 }
429 422
430 -// Change menu via settings of Adminimize.
431 -//add_filter( 'custom_menu_order', '__return_true' );
432 -add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
423 +/**
424 + * Init always with WP
425 + */
426 +function _mw_adminimize_init() {
433 427
434 -// global_options
435 -add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
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 +
436 438 // on admin init
439 +define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
437 440 if ( is_admin() ) {
438 - add_action( 'admin_init', '_mw_adminimize_admin_init' );
441 + add_action( 'admin_init', '_mw_adminimize_textdomain' );
442 + add_action( 'admin_init', '_mw_adminimize_admin_init', 2 );
439 443 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
440 444 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
441 445 }
446 +add_action( 'init', '_mw_adminimize_init', 2 );
442 447
443 448 register_activation_hook( __FILE__, '_mw_adminimize_install' );
444 -register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
449 +register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
450 +//register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
445 451
446 452 /**
447 453 * Remove the dashboard
448 454 */
@@ -459,17 +465,17 @@
459 465 }
460 466
461 467 global $menu, $user_ID;
462 468
463 - $disabled_menu_ = array();
464 - $disabled_submenu_ = array();
469 + $disabled_menu_ = '';
470 + $disabled_submenu_ = '';
465 471 $user_roles = _mw_adminimize_get_all_user_roles();
466 472
467 473 foreach ( $user_roles as $role ) {
468 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
474 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
469 475 'mw_adminimize_disabled_menu_' . $role . '_items'
470 476 );
471 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
477 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
472 478 'mw_adminimize_disabled_submenu_' . $role . '_items'
473 479 );
474 480 }
475 481
@@ -494,9 +500,9 @@
494 500 }
495 501 }
496 502 }
497 503
498 - // Redirect option, if Dashboard is inactive
504 + // redirect option, if Dashboard is inactive
499 505 if ( $redirect ) {
500 506 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
501 507 '_mw_adminimize_db_redirect'
502 508 );
@@ -531,14 +537,14 @@
531 537
532 538 $dashboard_core_string = esc_attr__( 'Dashboard' );
533 539 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
534 540 while (
535 - ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
541 + ! in_array( $dashboard_core_string, $dashboard, FALSE ) && next( $menu )
536 542 ) {
537 543 $page = key( $menu );
538 544 }
539 545
540 - if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
546 + if ( in_array( $dashboard_core_string, $dashboard, FALSE ) ) {
541 547 unset( $menu[ $page ] );
542 548 }
543 549 reset( $menu );
544 550 $page = key( $menu );
@@ -547,15 +553,112 @@
547 553 $page = key( $menu );
548 554 }
549 555
550 556 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
551 - wp_safe_redirect( $_mw_adminimize_db_redirect );
557 + wp_redirect( $_mw_adminimize_db_redirect );
552 558 }
553 559 }
560 +
554 561 }
555 562 }
556 563
557 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 +/**
558 661 * Set menu for settings
559 662 */
560 663 function _mw_adminimize_set_menu_option() {
561 664
@@ -574,22 +677,17 @@
574 677 if ( ! isset( $menu ) || empty( $menu ) ) {
575 678 return;
576 679 }
577 680
578 - _mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
579 - _mw_adminimize_debug( $submenu, 'Adminimize, WordPress Sub-Menu:' );
681 + $user_roles = _mw_adminimize_get_all_user_roles();
682 + $disabled_menu_ = '';
683 + $disabled_submenu_ = '';
580 684
581 - $disabled_menu_ = array();
582 - $disabled_submenu_ = array();
583 - $user = wp_get_current_user();
584 - $user_roles = $user->roles;
585 - _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
586 -
587 685 foreach ( $user_roles as $role ) {
588 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
686 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
589 687 'mw_adminimize_disabled_menu_' . $role . '_items'
590 688 );
591 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
689 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
592 690 'mw_adminimize_disabled_submenu_' . $role . '_items'
593 691 );
594 692 }
595 693
@@ -597,63 +695,52 @@
597 695 $mw_adminimize_submenu = array();
598 696
599 697 // Set admin-menu.
600 698 foreach ( $user_roles as $role ) {
601 - if ( in_array( $role, $user->roles, TRUE )
602 - && _mw_adminimize_current_user_has_role( $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 + )
603 706 ) {
604 - // Create array about all items with all affected roles.
605 - foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
606 - $mw_adminimize_menu[] = $menu_item;
607 - }
608 - foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
609 - $mw_adminimize_submenu[] = $submenu_item;
610 - }
707 + $mw_adminimize_menu = $disabled_menu_[ $role ];
708 + $mw_adminimize_submenu = $disabled_submenu_[ $role ];
611 709 }
612 710 }
613 711
614 - // Support Multiple Roles for users.
615 - // Leave only the items, there are active on each roles of the users.
616 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
617 - $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
618 - $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
619 - } else {
620 - // Alternative filter the array to remove duplicates, much faster.
621 - $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
622 - $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
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';
623 715 }
624 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
625 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
626 716
627 - foreach ( $menu as $key => $item ) {
717 + foreach ( $menu as $index => $item ) {
628 718
629 - _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
719 + if ( 'index.php' === $item ) {
720 + continue;
721 + }
630 722
631 - // Menu
632 723 if ( isset( $item[ 2 ] ) ) {
633 - $menu_slug = $item[ 2 ];
634 - // Check, if the Menu item in the current user role settings?
635 - if ( in_array( $menu_slug, $mw_adminimize_menu, false )
724 + if ( isset( $mw_adminimize_menu ) && is_array( $mw_adminimize_menu )
725 + && in_array(
726 + $item[ 2 ], $mw_adminimize_menu, FALSE
727 + )
636 728 ) {
637 - remove_menu_page( $menu_slug );
638 - // Prevent access to the page with the slug, there was inactive.
639 - _mw_adminimize_check_page_access( $menu_slug );
729 + unset( $menu[ $index ] );
640 730 }
641 731
642 - // Sub Menu Settings.
643 - if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
644 - foreach ( (array) $submenu[ $menu_slug ] as $subindex => $subitem ) {
645 - // Check, if is Sub Menu item in the user role settings?
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?
646 735 if (
647 736 isset( $mw_adminimize_submenu )
648 737 && _mw_adminimize_in_arrays(
649 - array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
738 + array( $subitem[ 2 ], $item[ 2 ] . '__' . $subindex ),
650 739 $mw_adminimize_submenu
651 740 )
652 741 ) {
653 - remove_submenu_page( $menu_slug, $subitem[ 2 ] );
654 - // Prevent access to the page with the slug, there was inactive.
655 - _mw_adminimize_check_page_access( $subitem[ 2 ] );
742 + unset( $submenu[ $item[ 2 ] ][ $subindex ] );
656 743 }
657 744 }
658 745 }
659 746 }
@@ -661,12 +748,14 @@
661 748
662 749 }
663 750
664 751 /**
665 - * Set global options in backend in all areas.
752 + * set global options in backend in all areas
666 753 */
667 754 function _mw_adminimize_set_global_option() {
668 755
756 + global $_wp_admin_css_colors;
757 +
669 758 // exclude super admin
670 759 if ( _mw_adminimize_exclude_super_admin() ) {
671 760 return NULL;
672 761 }
@@ -677,56 +766,53 @@
677 766 }
678 767
679 768 $user_roles = _mw_adminimize_get_all_user_roles();
680 769 $_mw_adminimize_admin_head = '';
681 - $disabled_global_option = array();
682 - $disabled_global_option_ = array();
683 - $user = wp_get_current_user();
684 770
685 - // Get settings for each role.
686 771 foreach ( $user_roles as $role ) {
687 - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
772 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
688 773 'mw_adminimize_disabled_global_option_' . $role . '_items'
689 774 );
690 775 }
691 776
692 - // Write global options in an var.
693 777 foreach ( $user_roles as $role ) {
694 - if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
778 + if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
779 + $disabled_global_option_[ $role ][ '0' ] = '';
780 + }
781 + }
695 782
696 - // Create array about all items with all affected roles, important for multiple roles.
697 - foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
698 - $disabled_global_option[] = $global_item;
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 ] );
699 793 }
700 794 }
701 795 }
702 -
703 - // Support Multiple Roles for users.
704 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
705 - $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
706 - }
707 - $global_options = implode( ', ', $disabled_global_option );
708 -
709 - if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
710 - global $_wp_admin_css_colors;
796 + if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
711 797 $_wp_admin_css_colors = 0;
712 798 }
713 799 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
714 800 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
715 801
716 - if ( '' !== $global_options ) {
802 + if ( ! empty( $global_options ) ) {
717 803 echo $_mw_adminimize_admin_head;
718 804 }
719 805 }
720 806
721 807 /**
722 - * Set metabox options from database an area post.
808 + * set metabox options from database an area post
723 809 */
724 810 function _mw_adminimize_set_metabox_post_option() {
725 811
726 812 // exclude super admin
727 813 if ( _mw_adminimize_exclude_super_admin() ) {
728 - return;
814 + return NULL;
729 815 }
730 816
731 817 // Leave the settings screen from Adminimize to see all areas on settings.
732 818 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -745,11 +831,11 @@
745 831 if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
746 832 $disabled_metaboxes_post_[ $role ][ '0' ] = '';
747 833 }
748 834
749 - // New since version 1.7.8.
835 + // new 1.7.8
750 836 $user = wp_get_current_user();
751 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
837 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
752 838 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
753 839 && is_array(
754 840 $disabled_metaboxes_post_[ $role ]
755 841 )
@@ -768,9 +854,9 @@
768 854 }
769 855 }
770 856
771 857 /**
772 - * Set metabox options from database an area page.
858 + * set metabox options from database an area page
773 859 */
774 860 function _mw_adminimize_set_metabox_page_option() {
775 861
776 862 // exclude super admin
@@ -795,11 +881,11 @@
795 881 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
796 882 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
797 883 }
798 884
799 - // New since version 1.7.8.
885 + // new 1.7.8
800 886 $user = wp_get_current_user();
801 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
887 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
802 888 if ( _mw_adminimize_current_user_has_role( $role )
803 889 && isset( $disabled_metaboxes_page_[ $role ] )
804 890 && is_array( $disabled_metaboxes_page_[ $role ] )
805 891 ) {
@@ -817,9 +903,9 @@
817 903 }
818 904 }
819 905
820 906 /**
821 - * Set metabox options from database an area post.
907 + * set metabox options from database an area post
822 908 */
823 909 function _mw_adminimize_set_metabox_cp_option() {
824 910
825 911 // exclude super admin
@@ -831,13 +917,14 @@
831 917 if ( _mw_adminimize_exclude_settings_page() ) {
832 918 return;
833 919 }
834 920
835 - $post_id = 0;
836 921 if ( isset( $_GET[ 'post' ] ) ) {
837 922 $post_id = (int) $_GET[ 'post' ];
838 923 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
839 924 $post_id = (int) $_POST[ 'post_ID' ];
925 + } else {
926 + $post_id = 0;
840 927 }
841 928
842 929 $current_post_type = $GLOBALS[ 'post_type' ];
843 930 if ( ! isset( $current_post_type ) ) {
@@ -866,9 +953,9 @@
866 953 $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
867 954 }
868 955
869 956 $user = wp_get_current_user();
870 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
957 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
871 958 if ( _mw_adminimize_current_user_has_role( $role )
872 959 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
873 960 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
874 961 ) {
@@ -886,9 +973,9 @@
886 973 }
887 974 }
888 975
889 976 /**
890 - * Set link options in area links of back end.
977 + * set link options in area Links of Backend
891 978 */
892 979 function _mw_adminimize_set_link_option() {
893 980
894 981 // exclude super admin
@@ -916,11 +1003,12 @@
916 1003 }
917 1004 }
918 1005
919 1006 $link_options = '';
1007 + // new 1.7.8
920 1008 foreach ( $user_roles as $role ) {
921 1009 $user = wp_get_current_user();
922 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1010 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
923 1011 if ( _mw_adminimize_current_user_has_role( $role )
924 1012 && isset( $disabled_link_option_[ $role ] )
925 1013 && is_array( $disabled_link_option_[ $role ] )
926 1014 ) {
@@ -938,9 +1026,9 @@
938 1026 }
939 1027 }
940 1028
941 1029 /**
942 - * Remove objects on wp nav menu.
1030 + * remove objects on wp nav menu
943 1031 */
944 1032 function _mw_adminimize_set_nav_menu_option() {
945 1033
946 1034 // exclude super admin
@@ -968,11 +1056,12 @@
968 1056 }
969 1057 }
970 1058
971 1059 $nav_menu_options = '';
1060 + // new 1.7.8
972 1061 foreach ( $user_roles as $role ) {
973 1062 $user = wp_get_current_user();
974 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1063 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
975 1064 if ( _mw_adminimize_current_user_has_role( $role )
976 1065 && isset( $disabled_nav_menu_option_[ $role ] )
977 1066 && is_array( $disabled_nav_menu_option_[ $role ] )
978 1067 ) {
@@ -979,8 +1068,9 @@
979 1068 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
980 1069 }
981 1070 }
982 1071 }
1072 + //remove_meta_box( $id, 'nav-menus', 'side' );
983 1073
984 1074 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
985 1075 $_mw_adminimize_admin_head .= '<style type="text/css">' .
986 1076 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
@@ -1020,11 +1110,12 @@
1020 1110 }
1021 1111 }
1022 1112
1023 1113 $widget_options = '';
1114 + // new 1.7.8
1024 1115 foreach ( $user_roles as $role ) {
1025 1116 $user = wp_get_current_user();
1026 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1117 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1027 1118 if ( _mw_adminimize_current_user_has_role( $role )
1028 1119 && isset( $disabled_widget_option_[ $role ] )
1029 1120 && is_array( $disabled_widget_option_[ $role ] )
1030 1121 ) {
@@ -1031,8 +1122,9 @@
1031 1122 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1032 1123 }
1033 1124 }
1034 1125 }
1126 + //remove_meta_box( $id, 'nav-menus', 'side' );
1035 1127
1036 1128 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1037 1129 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1038 1130 $widget_options . ' {display: none !important;}</style>' . "\n";
@@ -1042,9 +1134,9 @@
1042 1134 }
1043 1135 }
1044 1136
1045 1137 /**
1046 - * Print small user-info.
1138 + * small user-info
1047 1139 */
1048 1140 function _mw_adminimize_small_user_info() {
1049 1141
1050 1142 ?>
@@ -1059,14 +1151,13 @@
1059 1151 </div>
1060 1152 <?php
1061 1153 }
1062 1154
1155 +// Include message class.
1156 +require_once 'inc-setup/messages.php';
1063 1157 // include helping functions
1064 1158 require_once 'inc-setup/helping_hands.php';
1065 1159
1066 -// Include message class.
1067 -require_once 'inc-setup/messages.php';
1068 -
1069 1160 // inc. settings page
1070 1161 require_once 'adminimize_page.php';
1071 1162
1072 1163 // dashboard options
@@ -1073,11 +1164,14 @@
1073 1164 require_once 'inc-setup/dashboard.php';
1074 1165
1075 1166 // widget options
1076 1167 require_once 'inc-setup/widget.php';
1077 -require_once 'inc-setup/footer.php';
1078 1168 require_once 'inc-setup/admin-footer.php';
1079 1169
1170 +// global settings
1171 +// @TODO Testing, not ready for productive
1172 +//require_once( 'inc-options/settings_notice.php' );
1173 +
1080 1174 // remove admin bar
1081 1175 require_once 'inc-setup/remove-admin-bar.php';
1082 1176
1083 1177 // admin bar helper, setup
@@ -1090,19 +1184,15 @@
1090 1184
1091 1185 // Remove Admin Notices.
1092 1186 require_once 'inc-setup/remove-admin-notices.php';
1093 1187
1094 -// Add Ex-Import functions.
1095 -require_once 'inc-setup/export.php';
1096 -require_once 'inc-setup/import.php';
1097 -
1098 1188 /**
1099 1189 * Add action link(s) to plugins page
1100 1190 *
1101 - * @param array $links
1102 - * @param string $file
1191 + * @param $links , $file
1192 + * @param $file
1103 1193 *
1104 - * @return string $links
1194 + * @return $links
1105 1195 */
1106 1196 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1107 1197
1108 1198 /* create link */
@@ -1108,12 +1198,9 @@
1108 1198 /* create link */
1109 1199 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1110 1200 array_unshift(
1111 1201 $links,
1112 - sprintf(
1113 - '<a href="options-general.php?page=adminimize-options">%s</a>',
1114 - esc_attr__( 'Settings' )
1115 - )
1202 + sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, esc_attr__( 'Settings' ) )
1116 1203 );
1117 1204 }
1118 1205
1119 1206 return $links;
@@ -1119,9 +1206,9 @@
1119 1206 return $links;
1120 1207 }
1121 1208
1122 1209 /**
1123 - * Add settings in plugin-admin-page.
1210 + * settings in plugin-admin-page
1124 1211 */
1125 1212 function _mw_adminimize_add_settings_page() {
1126 1213
1127 1214 $pagehook = add_options_page(
@@ -1127,12 +1214,11 @@
1127 1214 $pagehook = add_options_page(
1128 1215 esc_attr__( 'Adminimize Options', 'adminimize' ),
1129 1216 esc_attr__( 'Adminimize', 'adminimize' ),
1130 1217 'manage_options',
1131 - 'adminimize-options',
1218 + __FILE__,
1132 1219 '_mw_adminimize_options'
1133 1220 );
1134 -
1135 1221 if ( ! is_network_admin() ) {
1136 1222 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1137 1223 }
1138 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
@@ -1137,16 +1223,10 @@
1137 1223 }
1138 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1139 1225 }
1140 1226
1141 -/**
1142 - * Enqueue script and styles for the settings page.
1143 - */
1144 1227 function _mw_adminimize_on_load_page() {
1145 1228
1146 - // Load translation files on options page.
1147 - _mw_adminimize_textdomain();
1148 -
1149 1229 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1150 1230
1151 1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1152 1232 wp_enqueue_style( 'adminimize-style' );
@@ -1161,35 +1241,52 @@
1161 1241 wp_enqueue_script( 'adminimize-settings-script' );
1162 1242 }
1163 1243
1164 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 +/**
1165 1269 * Get setting value for each options key.
1166 1270 *
1167 1271 * @param string|bool $key
1168 1272 *
1169 - * @return string
1273 + * @return array
1170 1274 */
1171 1275 function _mw_adminimize_get_option_value( $key = FALSE ) {
1172 1276
1173 - $adminimizeoptions = FALSE;
1174 - if ( ! _mw_adminimize_exclude_settings_page() ) {
1175 - $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
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() );
1176 1282 }
1177 1283
1178 - if ( FALSE === $adminimizeoptions ) {
1179 - // check for use on multisite
1180 - if ( _mw_adminimize_is_active_on_multisite() ) {
1181 - $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1182 - } else {
1183 - $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1184 - }
1185 - wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1186 - }
1187 -
1188 1284 if ( ! $key ) {
1189 1285 return $adminimizeoptions;
1190 1286 }
1191 1287
1288 + /** @var array $adminimizeoptions */
1192 1289 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1193 1290 }
1194 1291
1195 1292 /**
@@ -1195,32 +1292,20 @@
1195 1292 /**
1196 1293 * Update options.
1197 1294 *
1198 1295 * @param array $options
1199 - *
1200 - * @return bool
1201 1296 */
1202 1297 function _mw_adminimize_update_option( $options ) {
1203 1298
1204 1299 if ( ! current_user_can( 'manage_options' ) ) {
1205 - return FALSE;
1300 + return;
1206 1301 }
1207 1302
1208 - // Remove slashes always.
1209 - foreach ( $options as $key => $value ) {
1210 - $options[ $key ] = stripslashes_deep( $value );
1211 - }
1212 -
1213 - // Kill the cache for the settings page.
1214 - wp_cache_delete( 'mw_adminimize' );
1215 1303 if ( _mw_adminimize_is_active_on_multisite() ) {
1216 1304 update_site_option( 'mw_adminimize', $options );
1217 1305 } else {
1218 1306 update_option( 'mw_adminimize', $options );
1219 1307 }
1220 - wp_cache_add( 'mw_adminimize', $options );
1221 -
1222 - return TRUE;
1223 1308 }
1224 1309
1225 1310 /**
1226 1311 * Update options in database
@@ -1244,33 +1329,8 @@
1244 1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1245 1330 }
1246 1331 }
1247 1332
1248 - // Plugin Self Settings.
1249 - if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1250 - $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1251 - } else {
1252 - $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1253 - }
1254 -
1255 - if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1256 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1257 - } else {
1258 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1259 - }
1260 -
1261 - if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1262 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1263 - } else {
1264 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1265 - }
1266 -
1267 - if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1268 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1269 - } else {
1270 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1271 - }
1272 -
1273 1333 // Admin Bar Front end settings
1274 1334 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1275 1335 'mw_adminimize_admin_bar_frontend_nodes'
1276 1336 );
@@ -1275,9 +1335,9 @@
1275 1335 'mw_adminimize_admin_bar_frontend_nodes'
1276 1336 );
1277 1337 // admin bar front end options
1278 1338 foreach ( $user_roles as $role ) {
1279 - // admin bar front-end options
1339 + // admin bar fron tend options
1280 1340 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1281 1341 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1282 1342 } else {
1283 1343 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
@@ -1338,19 +1398,10 @@
1338 1398 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1339 1399 }
1340 1400
1341 1401 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1342 - $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1343 - $_POST[ '_mw_adminimize_advice_txt' ],
1344 - array(
1345 - 'a' => array(
1346 - 'href' => array(),
1347 - 'title' => array()
1348 - ),
1349 - 'br' => array(),
1350 - 'em' => array(),
1351 - 'strong' => array(),
1352 - )
1402 + $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = htmlspecialchars(
1403 + stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] )
1353 1404 );
1354 1405 } else {
1355 1406 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1356 1407 }
@@ -1383,27 +1434,8 @@
1383 1434 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1384 1435 }
1385 1436 }
1386 1437
1387 - // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1388 -
1389 - // own menu slug
1390 - if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1391 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1392 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1393 - );
1394 - } else {
1395 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1396 - }
1397 - // own custom menu slug
1398 - if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1399 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1400 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1401 - );
1402 - } else {
1403 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1404 - }
1405 -
1406 1438 // global_options, metaboxes update
1407 1439 foreach ( $user_roles as $role ) {
1408 1440
1409 1441 // global options
@@ -1408,9 +1440,9 @@
1408 1440
1409 1441 // global options
1410 1442 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1411 1443 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1412 - $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1444 + $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1413 1445 } else {
1414 1446 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1415 1447 }
1416 1448
@@ -1470,19 +1502,15 @@
1470 1502 }
1471 1503
1472 1504 // own options
1473 1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1474 - $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1475 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1476 - );
1506 + $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1477 1507 } else {
1478 1508 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1479 1509 }
1480 1510
1481 1511 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1482 - $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1483 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1484 - );
1512 + $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1485 1513 } else {
1486 1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1487 1515 }
1488 1516
@@ -1488,9 +1516,9 @@
1488 1516
1489 1517 // own post options
1490 1518 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1491 1519 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1492 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1520 + $_POST[ '_mw_adminimize_own_post_values' ]
1493 1521 );
1494 1522 } else {
1495 1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1496 1524 }
@@ -1496,9 +1524,9 @@
1496 1524 }
1497 1525
1498 1526 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1499 1527 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1500 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1528 + $_POST[ '_mw_adminimize_own_post_options' ]
1501 1529 );
1502 1530 } else {
1503 1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1504 1532 }
@@ -1505,9 +1533,9 @@
1505 1533
1506 1534 // own page options
1507 1535 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1508 1536 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1509 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1537 + $_POST[ '_mw_adminimize_own_page_values' ]
1510 1538 );
1511 1539 } else {
1512 1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1513 1541 }
@@ -1513,9 +1541,9 @@
1513 1541 }
1514 1542
1515 1543 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1516 1544 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1517 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1545 + $_POST[ '_mw_adminimize_own_page_options' ]
1518 1546 );
1519 1547 } else {
1520 1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1521 1549 }
@@ -1523,9 +1551,9 @@
1523 1551 // own custom post options
1524 1552 foreach ( $post_types as $post_type ) {
1525 1553 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1526 1554 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1527 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1555 + $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1528 1556 );
1529 1557 } else {
1530 1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1531 1559 }
@@ -1531,9 +1559,9 @@
1531 1559 }
1532 1560
1533 1561 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1534 1562 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1535 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1563 + $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1536 1564 );
1537 1565 } else {
1538 1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1539 1567 }
@@ -1541,9 +1569,9 @@
1541 1569
1542 1570 // own link options
1543 1571 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1544 1572 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1545 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1573 + $_POST[ '_mw_adminimize_own_link_values' ]
1546 1574 );
1547 1575 } else {
1548 1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1549 1577 }
@@ -1549,9 +1577,9 @@
1549 1577 }
1550 1578
1551 1579 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1552 1580 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1553 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1581 + $_POST[ '_mw_adminimize_own_link_options' ]
1554 1582 );
1555 1583 } else {
1556 1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1557 1585 }
@@ -1558,9 +1586,9 @@
1558 1586
1559 1587 // wp nav menu options
1560 1588 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1561 1589 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1562 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1590 + $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1563 1591 );
1564 1592 } else {
1565 1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1566 1594 }
@@ -1566,9 +1594,9 @@
1566 1594 }
1567 1595
1568 1596 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1569 1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1570 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1598 + $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1571 1599 );
1572 1600 } else {
1573 1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1574 1602 }
@@ -1575,9 +1603,9 @@
1575 1603
1576 1604 // widget options
1577 1605 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1578 1606 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1579 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1607 + $_POST[ '_mw_adminimize_own_widget_values' ]
1580 1608 );
1581 1609 } else {
1582 1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1583 1611 }
@@ -1583,9 +1611,9 @@
1583 1611 }
1584 1612
1585 1613 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1586 1614 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1587 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1615 + $_POST[ '_mw_adminimize_own_widget_options' ]
1588 1616 );
1589 1617 } else {
1590 1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1591 1619 }
@@ -1592,9 +1620,9 @@
1592 1620
1593 1621 // own dashboard options
1594 1622 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1595 1623 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1596 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1624 + $_POST[ '_mw_adminimize_own_dashboard_values' ]
1597 1625 );
1598 1626 } else {
1599 1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1600 1628 }
@@ -1600,9 +1628,9 @@
1600 1628 }
1601 1629
1602 1630 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1603 1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1604 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1632 + $_POST[ '_mw_adminimize_own_dashboard_options' ]
1605 1633 );
1606 1634 } else {
1607 1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1608 1636 }
@@ -1618,31 +1646,22 @@
1618 1646 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1619 1647 }
1620 1648
1621 1649 // update
1622 - $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1650 + _mw_adminimize_update_option( $adminimizeoptions );
1623 1651
1624 1652 $myErrors = new _mw_adminimize_message_class();
1625 - if ( $update_status ) {
1626 - $message = $myErrors->get_error(
1653 + $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1627 1654 '_mw_adminimize_update'
1628 - );
1629 - } else {
1630 - $message = $myErrors->get_error(
1631 - '_mw_adminimize_access_denied'
1632 - );
1633 - }
1634 - echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1635 -
1636 - return TRUE;
1655 + ) . '</p></div>';
1656 + echo $myErrors;
1637 1657 }
1638 1658
1639 1659 /**
1640 1660 * Delete options in database
1641 1661 */
1642 -function _mw_adminimize_uninstall() {
1662 +function _mw_adminimize_deinstall() {
1643 1663
1644 - wp_cache_delete( 'mw_adminimize' );
1645 1664 delete_site_option( 'mw_adminimize' );
1646 1665 delete_option( 'mw_adminimize' );
1647 1666 }
1648 1667
@@ -1651,16 +1670,11 @@
1651 1670 */
1652 1671 function _mw_adminimize_install() {
1653 1672
1654 1673 if ( ! is_admin() ) {
1655 - return;
1674 + return NULL;
1656 1675 }
1657 1676
1658 - // If is AJAX Call.
1659 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
1660 - return;
1661 - }
1662 -
1663 1677 global $menu, $submenu;
1664 1678
1665 1679 $user_roles = _mw_adminimize_get_all_user_roles();
1666 1680 $adminimizeoptions = array();
@@ -1688,6 +1702,71 @@
1688 1702 add_site_option( 'mw_adminimize', $adminimizeoptions );
1689 1703 } else {
1690 1704 add_option( 'mw_adminimize', $adminimizeoptions );
1691 1705 }
1692 - wp_cache_add( 'mw_adminimize', $adminimizeoptions );
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 );
1693 1772 }