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 +462 -535 1.11.13 → 1.9.1 View file →
@@ -4,19 +4,17 @@
4 4 * Plugin URI: https://wordpress.org/plugins/adminimize/
5 5 * Text Domain: adminimize
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 - * Author: WP Media
9 - * Author URI: https://wp-media.me
10 - * Version: 1.11.13
8 + * Author: Frank Bültge
9 + * Author URI: http://bueltge.de/
10 + * Version: 1.9.1
11 11 * License: GPLv2+
12 12 *
13 - * Php Version 5.6
14 - *
15 13 * @package WordPress
16 - * @author WP Media <[email protected]>
14 + * @author Frank Bültge <[email protected]>
17 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 - * @version 2024-05-03
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,31 +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 - if ( function_exists( 'get_current_screen' ) ) {
112 - $screen_tmp = get_current_screen();
113 -
114 - if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
115 - $page = $screen_tmp->id;
116 - }
117 - }
118 -
119 - // Don't filter on settings page
120 - return FALSE !== strpos( $page, 'adminimize' );
101 + return FALSE;
121 102 }
122 103
123 104 /**
124 105 * Get status, if the plugin active network wide.
@@ -127,23 +108,12 @@
127 108 */
128 109 function _mw_adminimize_is_active_on_multisite() {
129 110
130 111 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
131 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
112 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
132 113 }
133 114
134 - /**
135 - * Allow different adminimize options per site on multisite.
136 - *
137 - * @since 1.11.6
138 - *
139 - * @param bool
140 - */
141 - $force_single_site_usage = apply_filters( 'adminimize_mu_force_options_per_site', false );
142 -
143 - if ( is_multisite()
144 - && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME )
145 - && ! $force_single_site_usage ) {
115 + if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
146 116 return TRUE;
147 117 }
148 118
149 119 return FALSE;
@@ -157,36 +127,27 @@
157 127 * @return array $user_roles
158 128 */
159 129 function _mw_adminimize_get_all_user_roles() {
160 130
161 - /** @var $wp_roles WP_Roles */
162 131 global $wp_roles;
163 132
164 133 $user_roles = array();
165 134
166 - if ( null !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
135 + if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
136 + /** @var array $wp_roles */
167 137 foreach ( $wp_roles->roles as $role => $data ) {
168 138 $user_roles[] = $role;
169 - // The $data var contains caps, maybe for later use.
139 + //$data contains caps, maybe for later use..
170 140 }
171 141 }
172 142
173 143 // Exclude the new bbPress roles.
174 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
175 - $user_roles = array_diff(
176 - $user_roles,
177 - array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
178 - );
179 - }
144 + $user_roles = array_diff(
145 + $user_roles,
146 + array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
147 + );
180 148
181 - /**
182 - * Use this filter to add or remove a role in Adminimize options.
183 - *
184 - * @since 1.11.6
185 - *
186 - * @param array
187 - */
188 - return apply_filters( 'adminimize_user_roles_filter', $user_roles );
149 + return $user_roles;
189 150 }
190 151
191 152 /**
192 153 * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
@@ -196,68 +157,56 @@
196 157 * @return array $user_roles_names
197 158 */
198 159 function _mw_adminimize_get_all_user_roles_names() {
199 160
200 - /** @var $wp_roles WP_Roles */
201 161 global $wp_roles;
162 +
202 163 $user_roles_names = array();
203 164
165 + /** @var array $wp_roles */
204 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 + }
205 172
206 - $data = translate_user_role( $data );
207 173 $user_roles_names[] = $data;
208 174 }
209 175
210 176 // exclude the new bbPress roles
211 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
212 - $user_roles_names = array_diff(
213 - $user_roles_names,
214 - array(
215 - esc_attr__( 'Keymaster', 'bbpress' ),
216 - esc_attr__( 'Moderator', 'bbpress' ),
217 - esc_attr__( 'Participant', 'bbpress' ),
218 - esc_attr__( 'Spectator', 'bbpress' ),
219 - esc_attr__( 'Blocked', 'bbpress' ),
220 - )
221 - );
222 - }
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 + );
223 187
224 - /**
225 - * Use this filter to add or remove a role-name in Adminimize options.
226 - *
227 - * @since 1.11.6
228 - *
229 - * @param array
230 - */
231 - return apply_filters( 'adminimize_user_roles_names_filter', $user_roles_names );
188 + return $user_roles_names;
232 189 }
233 190
234 191 /**
235 - * Get post type.
236 - *
237 - * @return null|string String of the post type.
192 + * return post type
238 193 */
239 -function _mw_adminimize_get_current_post_type() {
194 +function _mw_get_current_post_type() {
240 195
241 196 global $post, $typenow, $current_screen;
242 197
243 - // 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
244 199 if ( $post && $post->post_type ) {
245 200 return $post->post_type;
246 - }
247 -
248 - // Check the global $typenow - set in admin.php
249 - if ( $typenow ) {
201 + } //check the global $typenow - set in admin.php
202 + else if ( $typenow ) {
250 203 return $typenow;
251 - }
252 -
253 - // Check the global $current_screen object - set in screen.php
254 - if ( $current_screen && $current_screen->post_type ) {
204 + } // check the global $current_screen object - set in sceen.php
205 + else if ( $current_screen && $current_screen->post_type ) {
255 206 return $current_screen->post_type;
256 - }
257 -
258 - // lastly check the post_type querystring
259 - if ( isset( $_REQUEST['post_type'] ) ) {
207 + } // lastly check the post_type querystring
208 + else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
260 209 return sanitize_key( $_REQUEST[ 'post_type' ] );
261 210 }
262 211
263 212 // we do not know the post type!
@@ -268,41 +217,31 @@
268 217 * Check user-option and add new style.
269 218 */
270 219 function _mw_adminimize_admin_init() {
271 220
272 - global $pagenow, $menu, $submenu;
221 + global $pagenow, $post_type, $menu, $submenu;
273 222
274 - $post_id = 0;
275 223 if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
276 224 $post_id = (int) esc_attr( $_GET[ 'post' ] );
277 225 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
278 226 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
227 + } else {
228 + $post_id = 0;
279 229 }
280 - // Fallback to get always the post type.
281 - if ( isset( $_GET[ 'post_type' ] ) && ! is_array( $_GET[ 'post_type' ] ) ) {
282 - $current_post_type = esc_attr( $_GET['post_type'] );
283 - }
230 +
231 + $current_post_type = $post_type;
284 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
285 - $current_post_type = get_post_type( get_queried_object_id() );
286 - }
287 - if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
288 233 $current_post_type = get_post_type( $post_id );
289 234 }
290 235 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
291 - $current_post_type = _mw_adminimize_get_current_post_type();
236 + $current_post_type = _mw_get_current_post_type();
292 237 }
293 - if ( ! $current_post_type ) { // set hard to post
238 + if ( ! $current_post_type ) // set hard to post
239 + {
294 240 $current_post_type = 'post';
295 241 }
296 242
297 - // Debug helper
298 - if ( class_exists( 'DebugListener' ) ) {
299 - $listener = new DebugListener();
300 - add_action( 'adminimize.log', [$listener, 'listen'], 10, 2 );
301 - add_action( 'wp_footer', array( $listener, 'dump' ), PHP_INT_MAX );
302 - }
303 -
304 - // Get all user roles.
243 + // Get all user rolles.
305 244 $user_roles = _mw_adminimize_get_all_user_roles();
306 245
307 246 // Get settings.
308 247 $adminimizeoptions = _mw_adminimize_get_option_value();
@@ -326,9 +265,9 @@
326 265 // widget pages
327 266 $widget_pages = array( 'widgets.php' );
328 267
329 268 foreach ( $user_roles as $role ) {
330 - $disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
269 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
331 270 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
332 271 );
333 272 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
334 273 'mw_adminimize_disabled_global_option_' . $role . '_items'
@@ -358,22 +297,35 @@
358 297 }
359 298
360 299 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
361 300
362 - // Backend options
301 + // global options
363 302 // exclude super admin
364 - 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 + }
314 +
365 315 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
366 - if ( 1 === $_mw_adminimize_header ) {
367 - wp_enqueue_script(
368 - '_mw_adminimize_remove_header',
369 - WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
370 - [ 'jquery' ]
371 - );
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;
372 324 }
373 325
374 - // Post-page options.
375 - if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
326 + //post-page options
327 + if ( in_array( $pagenow, $def_post_pages, FALSE ) ) {
376 328
377 329 $_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
378 330 switch ( $_mw_adminimize_tb_window ) {
379 331 case 1:
@@ -395,9 +347,9 @@
395 347 );
396 348 break;
397 349 }
398 350
399 - // Category options.
351 + //category options
400 352 $_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
401 353 switch ( $_mw_adminimize_cat_full ) {
402 354 case 1:
403 355 wp_enqueue_style(
@@ -406,82 +358,97 @@
406 358 );
407 359 break;
408 360 }
409 361
410 - // Set default editor tinymce
362 + // set default editor tinymce
411 363 if ( _mw_adminimize_recursive_in_array(
412 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
413 - $disabled_metaboxes_page_all
414 - )
415 - || _mw_adminimize_recursive_in_array(
416 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
417 - $disabled_metaboxes_post_all
418 - )
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 + )
419 371 ) {
420 - add_filter( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
421 - /**
422 - * Return string tinymce.
423 - * Necessary for php 5.2 usage :(; not possible to use an anonymous function.
424 - *
425 - * @return string
426 - */
427 - function _mw_admininimize_return_tinmyce() {
428 - return 'tinymce';
429 - }
372 + add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
430 373 }
431 374
432 - // Remove media buttons
375 + // remove media bottons
433 376 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
434 - || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
377 + || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
435 378 ) {
436 379 remove_action( 'media_buttons', 'media_buttons' );
437 380 }
438 381 }
382 +
439 383 }
440 384
441 - // set meta-box post option
442 - 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 ) ) {
443 392 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
444 393 }
445 - // set meta-box page option
446 - 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 ) ) {
447 396 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
448 397 }
449 398 // set custom post type options
450 - if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
451 - && 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 + )
452 403 ) {
453 404 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
454 405 }
455 406 // set link option
456 - if ( in_array( $pagenow, $link_pages, TRUE ) ) {
407 + if ( in_array( $pagenow, $link_pages, FALSE ) ) {
457 408 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
458 409 }
459 410 // set wp nav menu options
460 - if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
411 + if ( in_array( $pagenow, $nav_menu_pages, FALSE ) ) {
461 412 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
462 413 }
463 414 // set widget options
464 - if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
415 + if ( in_array( $pagenow, $widget_pages, FALSE ) ) {
465 416 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
466 417 }
418 +
419 + $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
420 + $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
467 421 }
468 422
469 -// Change menu via settings of Adminimize.
470 -//add_filter( 'custom_menu_order', '__return_true' );
471 -add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
423 +/**
424 + * Init always with WP
425 + */
426 +function _mw_adminimize_init() {
472 427
473 -// global_options
474 -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 +
475 438 // on admin init
439 +define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
476 440 if ( is_admin() ) {
477 - 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 );
478 443 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
479 444 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
480 445 }
446 +add_action( 'init', '_mw_adminimize_init', 2 );
481 447
482 448 register_activation_hook( __FILE__, '_mw_adminimize_install' );
483 -register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
449 +register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
450 +//register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
484 451
485 452 /**
486 453 * Remove the dashboard
487 454 */
@@ -498,17 +465,17 @@
498 465 }
499 466
500 467 global $menu, $user_ID;
501 468
502 - $disabled_menu_ = array();
503 - $disabled_submenu_ = array();
469 + $disabled_menu_ = '';
470 + $disabled_submenu_ = '';
504 471 $user_roles = _mw_adminimize_get_all_user_roles();
505 472
506 473 foreach ( $user_roles as $role ) {
507 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
474 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
508 475 'mw_adminimize_disabled_menu_' . $role . '_items'
509 476 );
510 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
477 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
511 478 'mw_adminimize_disabled_submenu_' . $role . '_items'
512 479 );
513 480 }
514 481
@@ -526,9 +493,9 @@
526 493 $redirect = FALSE;
527 494 foreach ( $user_roles as $role ) {
528 495 if ( _mw_adminimize_current_user_has_role( $role ) ) {
529 496 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
530 - || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
497 + || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
531 498 ) {
532 499 $redirect = TRUE;
533 500 }
534 501 }
@@ -533,9 +500,9 @@
533 500 }
534 501 }
535 502 }
536 503
537 - // Redirect option, if Dashboard is inactive
504 + // redirect option, if Dashboard is inactive
538 505 if ( $redirect ) {
539 506 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
540 507 '_mw_adminimize_db_redirect'
541 508 );
@@ -570,14 +537,14 @@
570 537
571 538 $dashboard_core_string = esc_attr__( 'Dashboard' );
572 539 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
573 540 while (
574 - ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
541 + ! in_array( $dashboard_core_string, $dashboard, FALSE ) && next( $menu )
575 542 ) {
576 543 $page = key( $menu );
577 544 }
578 545
579 - if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
546 + if ( in_array( $dashboard_core_string, $dashboard, FALSE ) ) {
580 547 unset( $menu[ $page ] );
581 548 }
582 549 reset( $menu );
583 550 $page = key( $menu );
@@ -586,15 +553,112 @@
586 553 $page = key( $menu );
587 554 }
588 555
589 556 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
590 - wp_safe_redirect( $_mw_adminimize_db_redirect );
557 + wp_redirect( $_mw_adminimize_db_redirect );
591 558 }
592 559 }
560 +
593 561 }
594 562 }
595 563
596 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 +/**
597 661 * Set menu for settings
598 662 */
599 663 function _mw_adminimize_set_menu_option() {
600 664
@@ -599,9 +663,9 @@
599 663 function _mw_adminimize_set_menu_option() {
600 664
601 665 // exclude super admin
602 666 if ( _mw_adminimize_exclude_super_admin() ) {
603 - return;
667 + return NULL;
604 668 }
605 669
606 670 // Leave the settings screen from Adminimize to see all areas on settings.
607 671 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -608,40 +672,22 @@
608 672 return;
609 673 }
610 674
611 675 global $menu, $submenu;
612 - $wp_menu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_menu' );
613 - $wp_submenu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_submenu' );
614 676
615 - // Object to array
616 - if ( is_object( $wp_submenu ) ) {
617 - $wp_submenu = get_object_vars( $wp_submenu );
618 - }
619 -
620 - if ( ! isset( $wp_menu ) || empty( $wp_menu ) ) {
621 - $wp_menu = $menu;
622 - }
623 - if ( ! isset( $wp_submenu ) || empty( $wp_submenu ) ) {
624 - $wp_submenu = $submenu;
625 - }
626 677 if ( ! isset( $menu ) || empty( $menu ) ) {
627 678 return;
628 679 }
629 680
630 - _mw_adminimize_debug( $wp_menu, 'Adminimize, WordPress Menu:' );
631 - _mw_adminimize_debug( $wp_submenu, 'Adminimize, WordPress Sub-Menu:' );
681 + $user_roles = _mw_adminimize_get_all_user_roles();
682 + $disabled_menu_ = '';
683 + $disabled_submenu_ = '';
632 684
633 - $disabled_menu_ = array();
634 - $disabled_submenu_ = array();
635 - $user = wp_get_current_user();
636 - $user_roles = $user->roles;
637 - _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
638 -
639 685 foreach ( $user_roles as $role ) {
640 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
686 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
641 687 'mw_adminimize_disabled_menu_' . $role . '_items'
642 688 );
643 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
689 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
644 690 'mw_adminimize_disabled_submenu_' . $role . '_items'
645 691 );
646 692 }
647 693
@@ -649,69 +695,52 @@
649 695 $mw_adminimize_submenu = array();
650 696
651 697 // Set admin-menu.
652 698 foreach ( $user_roles as $role ) {
653 - if ( in_array( $role, $user->roles, TRUE )
654 - && _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 + )
655 706 ) {
656 - // Create array about all items with all affected roles.
657 - foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
658 - $mw_adminimize_menu[] = $menu_item;
659 - }
660 - foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
661 - $mw_adminimize_submenu[] = $submenu_item;
662 - }
707 + $mw_adminimize_menu = $disabled_menu_[ $role ];
708 + $mw_adminimize_submenu = $disabled_submenu_[ $role ];
663 709 }
664 710 }
665 711
666 - // Support Multiple Roles for users.
667 - // Leave only the items, there are active on each roles of the users.
668 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
669 - $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
670 - $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
671 - } else {
672 - // Alternative filter the array to remove duplicates, much faster.
673 - $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
674 - $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';
675 715 }
676 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
677 - _mw_adminimize_debug( $mw_adminimize_submenu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
678 716
679 - foreach ( $wp_menu as $key => $item ) {
717 + foreach ( $menu as $index => $item ) {
680 718
681 - _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
719 + if ( 'index.php' === $item ) {
720 + continue;
721 + }
682 722
683 - // Menu
684 723 if ( isset( $item[ 2 ] ) ) {
685 - $menu_slug = $item[ 2 ];
686 - // Check, if the Menu item in the current user role settings?
687 - 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 + )
688 728 ) {
689 - remove_menu_page( $menu_slug );
690 - // Prevent access to the page with the slug, there was inactive.
691 - _mw_adminimize_check_page_access( $menu_slug );
729 + unset( $menu[ $index ] );
692 730 }
693 731
694 - // Sub Menu Settings.
695 - if ( isset( $wp_submenu ) && ! empty( $wp_submenu[ $menu_slug ] ) ) {
696 - foreach ( (array) $wp_submenu[ $menu_slug ] as $subindex => $subitem ) {
697 -
698 - // @see https://github.com/bueltge/adminimize/issues/149
699 - if ( is_object( $subitem ) ) {
700 - $subitem = json_decode( json_encode( $subitem ), true );
701 - }
702 -
703 - // 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?
704 735 if (
705 736 isset( $mw_adminimize_submenu )
706 737 && _mw_adminimize_in_arrays(
707 - array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
738 + array( $subitem[ 2 ], $item[ 2 ] . '__' . $subindex ),
708 739 $mw_adminimize_submenu
709 740 )
710 741 ) {
711 - remove_submenu_page( $menu_slug, $subitem[ 2 ] );
712 - // Prevent access to the page with the slug, there was inactive.
713 - _mw_adminimize_check_page_access( $subitem[ 2 ] );
742 + unset( $submenu[ $item[ 2 ] ][ $subindex ] );
714 743 }
715 744 }
716 745 }
717 746 }
@@ -719,12 +748,14 @@
719 748
720 749 }
721 750
722 751 /**
723 - * Set global options in backend in all areas.
752 + * set global options in backend in all areas
724 753 */
725 754 function _mw_adminimize_set_global_option() {
726 755
756 + global $_wp_admin_css_colors;
757 +
727 758 // exclude super admin
728 759 if ( _mw_adminimize_exclude_super_admin() ) {
729 760 return NULL;
730 761 }
@@ -735,59 +766,53 @@
735 766 }
736 767
737 768 $user_roles = _mw_adminimize_get_all_user_roles();
738 769 $_mw_adminimize_admin_head = '';
739 - $disabled_global_option = array();
740 - $disabled_global_option_ = array();
741 - $user = wp_get_current_user();
742 770
743 - // Get settings for each role.
744 771 foreach ( $user_roles as $role ) {
745 - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
772 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
746 773 'mw_adminimize_disabled_global_option_' . $role . '_items'
747 774 );
748 775 }
749 776
750 - // Write global options in an var.
751 777 foreach ( $user_roles as $role ) {
752 - 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 + }
753 782
754 - // Create array about all items with all affected roles, important for multiple roles.
755 - foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
756 - $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 ] );
757 793 }
758 794 }
759 795 }
760 -
761 - // Support Multiple Roles for users.
762 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
763 - $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
764 - }
765 - $global_options = implode( ', ', $disabled_global_option );
766 -
767 - if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
768 - global $_wp_admin_css_colors;
796 + if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
769 797 $_wp_admin_css_colors = 0;
770 798 }
771 799 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
772 800 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
773 801
774 - // List options if the debug option is active.
775 - _mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
776 -
777 - if ( '' !== $global_options ) {
802 + if ( ! empty( $global_options ) ) {
778 803 echo $_mw_adminimize_admin_head;
779 804 }
780 805 }
781 806
782 807 /**
783 - * Set metabox options from database an area post.
808 + * set metabox options from database an area post
784 809 */
785 810 function _mw_adminimize_set_metabox_post_option() {
786 811
787 812 // exclude super admin
788 813 if ( _mw_adminimize_exclude_super_admin() ) {
789 - return;
814 + return NULL;
790 815 }
791 816
792 817 // Leave the settings screen from Adminimize to see all areas on settings.
793 818 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -795,10 +820,9 @@
795 820 }
796 821
797 822 $user_roles = _mw_adminimize_get_all_user_roles();
798 823 $_mw_adminimize_admin_head = '';
799 - // It's better to declare $metaboxes as an array for better manipulation later.
800 - $metaboxes = array();
824 + $metaboxes = '';
801 825
802 826 foreach ( $user_roles as $role ) {
803 827 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
804 828 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
@@ -803,42 +827,28 @@
803 827 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
804 828 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
805 829 );
806 830
807 - if ( ! isset( $disabled_metaboxes_post_[ $role ]['0'] ) ) {
808 - $disabled_metaboxes_post_[ $role ]['0'] = '';
809 -
810 - /**
811 - * @todo Think why keep going if $role does not even have boxes to hide? We may as well jump to the next $role.
812 - */
813 - continue;
831 + if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
832 + $disabled_metaboxes_post_[ $role ][ '0' ] = '';
814 833 }
815 834
816 - /**
817 - * @todo Think why call a function as we can use a global variable already declared by WordPress.
818 - * @var WP_User $user Instance of WP_User.
819 - * @since 1.7.8
820 - * @version 1.11.4
821 - */
822 - $user = $GLOBALS['current_user'];
823 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
835 + // new 1.7.8
836 + $user = wp_get_current_user();
837 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
824 838 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
825 - && is_array(
826 - $disabled_metaboxes_post_[ $role ]
827 - )
839 + && is_array(
840 + $disabled_metaboxes_post_[ $role ]
841 + )
828 842 ) {
829 - // The previous way $metaboxes was being filled it could be at some point non empty and empty afterwards.
830 - // For instance, if a $role has items to be hidden and the user has this $role, $metaboxes will be filled.
831 - // But in next loop $metaboxes may receive '' as the next $role might not have items to hide and the user might has the next $role.
832 - $metaboxes[] = implode( ',', $disabled_metaboxes_post_[ $role ] );
843 + $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
833 844 }
834 845 }
835 846 }
836 847
837 848 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
838 - // And below we implode $metaboxes because it's an array now.
839 849 $_mw_adminimize_admin_head .= '<style type="text/css">' .
840 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
850 + $metaboxes . ' {display:none !important;}</style>' . "\n";
841 851
842 852 if ( ! empty( $metaboxes ) ) {
843 853 echo $_mw_adminimize_admin_head;
844 854 }
@@ -844,9 +854,9 @@
844 854 }
845 855 }
846 856
847 857 /**
848 - * Set metabox options from database an area page.
858 + * set metabox options from database an area page
849 859 */
850 860 function _mw_adminimize_set_metabox_page_option() {
851 861
852 862 // exclude super admin
@@ -871,14 +881,14 @@
871 881 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
872 882 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
873 883 }
874 884
875 - // New since version 1.7.8.
885 + // new 1.7.8
876 886 $user = wp_get_current_user();
877 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
887 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
878 888 if ( _mw_adminimize_current_user_has_role( $role )
879 - && isset( $disabled_metaboxes_page_[ $role ] )
880 - && is_array( $disabled_metaboxes_page_[ $role ] )
889 + && isset( $disabled_metaboxes_page_[ $role ] )
890 + && is_array( $disabled_metaboxes_page_[ $role ] )
881 891 ) {
882 892 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
883 893 }
884 894 }
@@ -885,9 +895,9 @@
885 895 }
886 896
887 897 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
888 898 $_mw_adminimize_admin_head .= '<style type="text/css">' .
889 - $metaboxes . ' {display:none !important;}</style>' . "\n";
899 + $metaboxes . ' {display:none !important;}</style>' . "\n";
890 900
891 901 if ( ! empty( $metaboxes ) ) {
892 902 echo $_mw_adminimize_admin_head;
893 903 }
@@ -893,9 +903,9 @@
893 903 }
894 904 }
895 905
896 906 /**
897 - * Set metabox options from database an area post.
907 + * set metabox options from database an area post
898 908 */
899 909 function _mw_adminimize_set_metabox_cp_option() {
900 910
901 911 // exclude super admin
@@ -907,21 +917,17 @@
907 917 if ( _mw_adminimize_exclude_settings_page() ) {
908 918 return;
909 919 }
910 920
911 - $post_id = 0;
912 921 if ( isset( $_GET[ 'post' ] ) ) {
913 922 $post_id = (int) $_GET[ 'post' ];
914 923 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
915 924 $post_id = (int) $_POST[ 'post_ID' ];
925 + } else {
926 + $post_id = 0;
916 927 }
917 928
918 - if ( ! isset( $GLOBALS[ 'post_type' ] ) || empty( $GLOBALS[ 'post_type' ] ) ) {
919 - $current_post_type = get_post_type();
920 - } else {
921 - $current_post_type = $GLOBALS[ 'post_type' ];
922 - }
923 -
929 + $current_post_type = $GLOBALS[ 'post_type' ];
924 930 if ( ! isset( $current_post_type ) ) {
925 931 $current_post_type = get_post_type( $post_id );
926 932 }
927 933
@@ -935,9 +941,9 @@
935 941 }
936 942
937 943 $user_roles = _mw_adminimize_get_all_user_roles();
938 944 $_mw_adminimize_admin_head = '';
939 - $metaboxes = array();
945 + $metaboxes = '';
940 946
941 947 foreach ( $user_roles as $role ) {
942 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
943 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
@@ -942,21 +948,19 @@
942 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
943 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
944 950 );
945 951
946 - if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
947 - $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
948 -
949 - continue;
952 + if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
953 + $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
950 954 }
951 955
952 - $user = $GLOBALS['current_user'];
953 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
956 + $user = wp_get_current_user();
957 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
954 958 if ( _mw_adminimize_current_user_has_role( $role )
955 - && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
956 - && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
959 + && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
960 + && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
957 961 ) {
958 - $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
962 + $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
959 963 }
960 964 }
961 965 }
962 966
@@ -961,9 +965,9 @@
961 965 }
962 966
963 967 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
964 968 $_mw_adminimize_admin_head .= '<style type="text/css">' .
965 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
969 + $metaboxes . ' {display:none !important;}</style>' . "\n";
966 970
967 971 if ( ! empty( $metaboxes ) ) {
968 972 echo $_mw_adminimize_admin_head;
969 973 }
@@ -969,9 +973,9 @@
969 973 }
970 974 }
971 975
972 976 /**
973 - * Set link options in area links of back end.
977 + * set link options in area Links of Backend
974 978 */
975 979 function _mw_adminimize_set_link_option() {
976 980
977 981 // exclude super admin
@@ -999,11 +1003,12 @@
999 1003 }
1000 1004 }
1001 1005
1002 1006 $link_options = '';
1007 + // new 1.7.8
1003 1008 foreach ( $user_roles as $role ) {
1004 1009 $user = wp_get_current_user();
1005 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1010 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1006 1011 if ( _mw_adminimize_current_user_has_role( $role )
1007 1012 && isset( $disabled_link_option_[ $role ] )
1008 1013 && is_array( $disabled_link_option_[ $role ] )
1009 1014 ) {
@@ -1013,9 +1018,9 @@
1013 1018 }
1014 1019
1015 1020 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
1016 1021 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1017 - $link_options . ' {display:none !important;}</style>' . "\n";
1022 + $link_options . ' {display:none !important;}</style>' . "\n";
1018 1023
1019 1024 if ( ! empty( $link_options ) ) {
1020 1025 echo $_mw_adminimize_admin_head;
1021 1026 }
@@ -1021,9 +1026,9 @@
1021 1026 }
1022 1027 }
1023 1028
1024 1029 /**
1025 - * Remove objects on wp nav menu.
1030 + * remove objects on wp nav menu
1026 1031 */
1027 1032 function _mw_adminimize_set_nav_menu_option() {
1028 1033
1029 1034 // exclude super admin
@@ -1051,11 +1056,12 @@
1051 1056 }
1052 1057 }
1053 1058
1054 1059 $nav_menu_options = '';
1060 + // new 1.7.8
1055 1061 foreach ( $user_roles as $role ) {
1056 1062 $user = wp_get_current_user();
1057 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1063 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1058 1064 if ( _mw_adminimize_current_user_has_role( $role )
1059 1065 && isset( $disabled_nav_menu_option_[ $role ] )
1060 1066 && is_array( $disabled_nav_menu_option_[ $role ] )
1061 1067 ) {
@@ -1062,12 +1068,13 @@
1062 1068 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1063 1069 }
1064 1070 }
1065 1071 }
1072 + //remove_meta_box( $id, 'nav-menus', 'side' );
1066 1073
1067 1074 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1068 1075 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1069 - $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1076 + $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1070 1077
1071 1078 if ( $nav_menu_options ) {
1072 1079 echo $_mw_adminimize_admin_head;
1073 1080 }
@@ -1103,11 +1110,12 @@
1103 1110 }
1104 1111 }
1105 1112
1106 1113 $widget_options = '';
1114 + // new 1.7.8
1107 1115 foreach ( $user_roles as $role ) {
1108 1116 $user = wp_get_current_user();
1109 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1117 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1110 1118 if ( _mw_adminimize_current_user_has_role( $role )
1111 1119 && isset( $disabled_widget_option_[ $role ] )
1112 1120 && is_array( $disabled_widget_option_[ $role ] )
1113 1121 ) {
@@ -1114,12 +1122,13 @@
1114 1122 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1115 1123 }
1116 1124 }
1117 1125 }
1126 + //remove_meta_box( $id, 'nav-menus', 'side' );
1118 1127
1119 1128 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1120 1129 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1121 - $widget_options . ' {display: none !important;}</style>' . "\n";
1130 + $widget_options . ' {display: none !important;}</style>' . "\n";
1122 1131
1123 1132 if ( $widget_options ) {
1124 1133 echo $_mw_adminimize_admin_head;
1125 1134 }
@@ -1125,9 +1134,9 @@
1125 1134 }
1126 1135 }
1127 1136
1128 1137 /**
1129 - * Print small user-info.
1138 + * small user-info
1130 1139 */
1131 1140 function _mw_adminimize_small_user_info() {
1132 1141
1133 1142 ?>
@@ -1142,15 +1151,13 @@
1142 1151 </div>
1143 1152 <?php
1144 1153 }
1145 1154
1155 +// Include message class.
1156 +require_once 'inc-setup/messages.php';
1146 1157 // include helping functions
1147 -require_once 'inc-setup/DebugListener.php';
1148 1158 require_once 'inc-setup/helping_hands.php';
1149 1159
1150 -// Include message class.
1151 -require_once 'inc-setup/messages.php';
1152 -
1153 1160 // inc. settings page
1154 1161 require_once 'adminimize_page.php';
1155 1162
1156 1163 // dashboard options
@@ -1157,11 +1164,14 @@
1157 1164 require_once 'inc-setup/dashboard.php';
1158 1165
1159 1166 // widget options
1160 1167 require_once 'inc-setup/widget.php';
1161 -require_once 'inc-setup/footer.php';
1162 1168 require_once 'inc-setup/admin-footer.php';
1163 1169
1170 +// global settings
1171 +// @TODO Testing, not ready for productive
1172 +//require_once( 'inc-options/settings_notice.php' );
1173 +
1164 1174 // remove admin bar
1165 1175 require_once 'inc-setup/remove-admin-bar.php';
1166 1176
1167 1177 // admin bar helper, setup
@@ -1174,19 +1184,15 @@
1174 1184
1175 1185 // Remove Admin Notices.
1176 1186 require_once 'inc-setup/remove-admin-notices.php';
1177 1187
1178 -// Add Ex-Import functions.
1179 -require_once 'inc-setup/export.php';
1180 -require_once 'inc-setup/import.php';
1181 -
1182 1188 /**
1183 1189 * Add action link(s) to plugins page
1184 1190 *
1185 - * @param array $links
1186 - * @param string $file
1191 + * @param $links , $file
1192 + * @param $file
1187 1193 *
1188 - * @return array $links
1194 + * @return $links
1189 1195 */
1190 1196 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1191 1197
1192 1198 /* create link */
@@ -1192,12 +1198,9 @@
1192 1198 /* create link */
1193 1199 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1194 1200 array_unshift(
1195 1201 $links,
1196 - sprintf(
1197 - '<a href="options-general.php?page=adminimize-options">%s</a>',
1198 - esc_attr__( 'Settings' )
1199 - )
1202 + sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, esc_attr__( 'Settings' ) )
1200 1203 );
1201 1204 }
1202 1205
1203 1206 return $links;
@@ -1203,9 +1206,9 @@
1203 1206 return $links;
1204 1207 }
1205 1208
1206 1209 /**
1207 - * Add settings in plugin-admin-page.
1210 + * settings in plugin-admin-page
1208 1211 */
1209 1212 function _mw_adminimize_add_settings_page() {
1210 1213
1211 1214 $pagehook = add_options_page(
@@ -1211,12 +1214,11 @@
1211 1214 $pagehook = add_options_page(
1212 1215 esc_attr__( 'Adminimize Options', 'adminimize' ),
1213 1216 esc_attr__( 'Adminimize', 'adminimize' ),
1214 1217 'manage_options',
1215 - 'adminimize-options',
1218 + __FILE__,
1216 1219 '_mw_adminimize_options'
1217 1220 );
1218 -
1219 1221 if ( ! is_network_admin() ) {
1220 1222 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1221 1223 }
1222 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
@@ -1221,23 +1223,15 @@
1221 1223 }
1222 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1223 1225 }
1224 1226
1225 -/**
1226 - * Enqueue script and styles for the settings page.
1227 - */
1228 1227 function _mw_adminimize_on_load_page() {
1229 1228
1230 - // Load translation files on options page.
1231 - _mw_adminimize_textdomain();
1232 -
1233 1229 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1234 1230
1235 - wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1236 1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1237 1232 wp_enqueue_style( 'adminimize-style' );
1238 1233
1239 - wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1240 1234 wp_register_script(
1241 1235 'adminimize-settings-script',
1242 1236 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1243 1237 array( 'jquery' ),
@@ -1247,36 +1241,53 @@
1247 1241 wp_enqueue_script( 'adminimize-settings-script' );
1248 1242 }
1249 1243
1250 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 +/**
1251 1269 * Get setting value for each options key.
1252 1270 *
1253 1271 * @param string|bool $key
1254 1272 *
1255 - * @return string
1273 + * @return array
1256 1274 */
1257 -function _mw_adminimize_get_option_value( $key = false ) {
1275 +function _mw_adminimize_get_option_value( $key = FALSE ) {
1258 1276
1259 - $adminimizeoptions = false;
1260 - if ( ! _mw_adminimize_exclude_settings_page() ) {
1261 - $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() );
1262 1282 }
1263 1283
1264 - if ( false === $adminimizeoptions ) {
1265 - // check for use on multisite.
1266 - if ( _mw_adminimize_is_active_on_multisite() ) {
1267 - $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1268 - } else {
1269 - $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1270 - }
1271 - wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1272 - }
1273 -
1274 1284 if ( ! $key ) {
1275 1285 return $adminimizeoptions;
1276 1286 }
1277 1287
1278 - return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : null;
1288 + /** @var array $adminimizeoptions */
1289 + return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1279 1290 }
1280 1291
1281 1292 /**
1282 1293 * Update options.
@@ -1281,36 +1292,20 @@
1281 1292 /**
1282 1293 * Update options.
1283 1294 *
1284 1295 * @param array $options
1285 - *
1286 - * @return bool
1287 1296 */
1288 1297 function _mw_adminimize_update_option( $options ) {
1289 1298
1290 1299 if ( ! current_user_can( 'manage_options' ) ) {
1291 - return FALSE;
1300 + return;
1292 1301 }
1293 1302
1294 - if ( _mw_adminimize_is_roles_options_import( $options ) ){
1295 - $options = _mw_adminimize_roles_complete_options( $options );
1296 - }
1297 -
1298 - // Remove slashes always.
1299 - foreach ( $options as $key => $value ) {
1300 - $options[ $key ] = stripslashes_deep( $value );
1301 - }
1302 -
1303 - // Kill the cache for the settings page.
1304 - wp_cache_delete( 'mw_adminimize' );
1305 1303 if ( _mw_adminimize_is_active_on_multisite() ) {
1306 1304 update_site_option( 'mw_adminimize', $options );
1307 1305 } else {
1308 1306 update_option( 'mw_adminimize', $options );
1309 1307 }
1310 - wp_cache_add( 'mw_adminimize', $options );
1311 -
1312 - return TRUE;
1313 1308 }
1314 1309
1315 1310 /**
1316 1311 * Update options in database
@@ -1334,33 +1329,8 @@
1334 1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1335 1330 }
1336 1331 }
1337 1332
1338 - // Plugin Self Settings.
1339 - if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1340 - $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1341 - } else {
1342 - $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1343 - }
1344 -
1345 - if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1346 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1347 - } else {
1348 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1349 - }
1350 -
1351 - if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1352 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1353 - } else {
1354 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1355 - }
1356 -
1357 - if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1358 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1359 - } else {
1360 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1361 - }
1362 -
1363 1333 // Admin Bar Front end settings
1364 1334 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1365 1335 'mw_adminimize_admin_bar_frontend_nodes'
1366 1336 );
@@ -1365,9 +1335,9 @@
1365 1335 'mw_adminimize_admin_bar_frontend_nodes'
1366 1336 );
1367 1337 // admin bar front end options
1368 1338 foreach ( $user_roles as $role ) {
1369 - // admin bar front-end options
1339 + // admin bar fron tend options
1370 1340 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1371 1341 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1372 1342 } else {
1373 1343 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
@@ -1428,19 +1398,10 @@
1428 1398 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1429 1399 }
1430 1400
1431 1401 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1432 - $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1433 - $_POST[ '_mw_adminimize_advice_txt' ],
1434 - array(
1435 - 'a' => array(
1436 - 'href' => array(),
1437 - 'title' => array()
1438 - ),
1439 - 'br' => array(),
1440 - 'em' => array(),
1441 - 'strong' => array(),
1442 - )
1402 + $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = htmlspecialchars(
1403 + stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] )
1443 1404 );
1444 1405 } else {
1445 1406 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1446 1407 }
@@ -1473,27 +1434,8 @@
1473 1434 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1474 1435 }
1475 1436 }
1476 1437
1477 - // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1478 -
1479 - // own menu slug
1480 - if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1481 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1482 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1483 - );
1484 - } else {
1485 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1486 - }
1487 - // own custom menu slug
1488 - if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1489 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1490 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1491 - );
1492 - } else {
1493 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1494 - }
1495 -
1496 1438 // global_options, metaboxes update
1497 1439 foreach ( $user_roles as $role ) {
1498 1440
1499 1441 // global options
@@ -1560,19 +1502,15 @@
1560 1502 }
1561 1503
1562 1504 // own options
1563 1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1564 - $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1565 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1566 - );
1506 + $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1567 1507 } else {
1568 1508 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1569 1509 }
1570 1510
1571 1511 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1572 - $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1573 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1574 - );
1512 + $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1575 1513 } else {
1576 1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1577 1515 }
1578 1516
@@ -1578,9 +1516,9 @@
1578 1516
1579 1517 // own post options
1580 1518 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1581 1519 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1582 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1520 + $_POST[ '_mw_adminimize_own_post_values' ]
1583 1521 );
1584 1522 } else {
1585 1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1586 1524 }
@@ -1586,9 +1524,9 @@
1586 1524 }
1587 1525
1588 1526 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1589 1527 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1590 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1528 + $_POST[ '_mw_adminimize_own_post_options' ]
1591 1529 );
1592 1530 } else {
1593 1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1594 1532 }
@@ -1595,9 +1533,9 @@
1595 1533
1596 1534 // own page options
1597 1535 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1598 1536 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1599 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1537 + $_POST[ '_mw_adminimize_own_page_values' ]
1600 1538 );
1601 1539 } else {
1602 1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1603 1541 }
@@ -1603,9 +1541,9 @@
1603 1541 }
1604 1542
1605 1543 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1606 1544 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1607 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1545 + $_POST[ '_mw_adminimize_own_page_options' ]
1608 1546 );
1609 1547 } else {
1610 1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1611 1549 }
@@ -1613,9 +1551,9 @@
1613 1551 // own custom post options
1614 1552 foreach ( $post_types as $post_type ) {
1615 1553 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1616 1554 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1617 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1555 + $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1618 1556 );
1619 1557 } else {
1620 1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1621 1559 }
@@ -1621,9 +1559,9 @@
1621 1559 }
1622 1560
1623 1561 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1624 1562 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1625 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1563 + $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1626 1564 );
1627 1565 } else {
1628 1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1629 1567 }
@@ -1631,9 +1569,9 @@
1631 1569
1632 1570 // own link options
1633 1571 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1634 1572 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1635 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1573 + $_POST[ '_mw_adminimize_own_link_values' ]
1636 1574 );
1637 1575 } else {
1638 1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1639 1577 }
@@ -1639,9 +1577,9 @@
1639 1577 }
1640 1578
1641 1579 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1642 1580 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1643 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1581 + $_POST[ '_mw_adminimize_own_link_options' ]
1644 1582 );
1645 1583 } else {
1646 1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1647 1585 }
@@ -1648,9 +1586,9 @@
1648 1586
1649 1587 // wp nav menu options
1650 1588 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1651 1589 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1652 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1590 + $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1653 1591 );
1654 1592 } else {
1655 1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1656 1594 }
@@ -1656,9 +1594,9 @@
1656 1594 }
1657 1595
1658 1596 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1659 1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1660 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1598 + $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1661 1599 );
1662 1600 } else {
1663 1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1664 1602 }
@@ -1665,9 +1603,9 @@
1665 1603
1666 1604 // widget options
1667 1605 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1668 1606 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1669 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1607 + $_POST[ '_mw_adminimize_own_widget_values' ]
1670 1608 );
1671 1609 } else {
1672 1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1673 1611 }
@@ -1673,9 +1611,9 @@
1673 1611 }
1674 1612
1675 1613 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1676 1614 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1677 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1615 + $_POST[ '_mw_adminimize_own_widget_options' ]
1678 1616 );
1679 1617 } else {
1680 1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1681 1619 }
@@ -1682,9 +1620,9 @@
1682 1620
1683 1621 // own dashboard options
1684 1622 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1685 1623 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1686 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1624 + $_POST[ '_mw_adminimize_own_dashboard_values' ]
1687 1625 );
1688 1626 } else {
1689 1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1690 1628 }
@@ -1690,9 +1628,9 @@
1690 1628 }
1691 1629
1692 1630 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1693 1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1694 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1632 + $_POST[ '_mw_adminimize_own_dashboard_options' ]
1695 1633 );
1696 1634 } else {
1697 1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1698 1636 }
@@ -1707,45 +1645,23 @@
1707 1645 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1708 1646 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1709 1647 }
1710 1648
1711 - /**
1712 - * Filter the adminimize options.
1713 - *
1714 - * Make the options filterable, so we can modify what is saved before it's sent to the db
1715 - *
1716 - * @since 1.11.6
1717 - *
1718 - * @param array $adminimizeoptions the original options.
1719 - * @param array $user_roles Array of the user roles.
1720 - * @param array $_POST Post data.
1721 - */
1722 - $adminimizeoptions = apply_filters( 'mw_adminimize_options_before_update', $adminimizeoptions, $user_roles, $_POST );
1723 -
1724 1649 // update
1725 - $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1650 + _mw_adminimize_update_option( $adminimizeoptions );
1726 1651
1727 1652 $myErrors = new _mw_adminimize_message_class();
1728 - if ( $update_status ) {
1729 - $message = $myErrors->get_error(
1653 + $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1730 1654 '_mw_adminimize_update'
1731 - );
1732 - } else {
1733 - $message = $myErrors->get_error(
1734 - '_mw_adminimize_access_denied'
1735 - );
1736 - }
1737 - echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1738 -
1739 - return TRUE;
1655 + ) . '</p></div>';
1656 + echo $myErrors;
1740 1657 }
1741 1658
1742 1659 /**
1743 1660 * Delete options in database
1744 1661 */
1745 -function _mw_adminimize_uninstall() {
1662 +function _mw_adminimize_deinstall() {
1746 1663
1747 - wp_cache_delete( 'mw_adminimize' );
1748 1664 delete_site_option( 'mw_adminimize' );
1749 1665 delete_option( 'mw_adminimize' );
1750 1666 }
1751 1667
@@ -1754,16 +1670,11 @@
1754 1670 */
1755 1671 function _mw_adminimize_install() {
1756 1672
1757 1673 if ( ! is_admin() ) {
1758 - return;
1674 + return NULL;
1759 1675 }
1760 1676
1761 - // If is AJAX Call.
1762 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
1763 - return;
1764 - }
1765 -
1766 1677 global $menu, $submenu;
1767 1678
1768 1679 $user_roles = _mw_adminimize_get_all_user_roles();
1769 1680 $adminimizeoptions = array();
@@ -1791,55 +1702,71 @@
1791 1702 add_site_option( 'mw_adminimize', $adminimizeoptions );
1792 1703 } else {
1793 1704 add_option( 'mw_adminimize', $adminimizeoptions );
1794 1705 }
1795 - wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1796 1706 }
1797 1707
1798 1708 /**
1799 - * Make sure adminimize option is complete when a role json file is imported
1800 - *
1801 - * @param array $roles_options
1802 - *
1803 - * @return array
1709 + * Process a settings export that generates a .json file of the shop settings
1804 1710 */
1805 -function _mw_adminimize_roles_complete_options( $roles_options ){
1711 +function _mw_adminimize_export_json() {
1806 1712
1807 - $adminimizeoption = _mw_adminimize_get_option_value();
1713 + if ( empty( $_GET[ '_mw_adminimize_export' ] ) || 'true' !== $_GET[ '_mw_adminimize_export' ] ) {
1714 + return;
1715 + }
1808 1716
1809 - foreach ( $roles_options as $role_option_name => $role_option_value ){
1810 - $adminimizeoption[$role_option_name] = $role_option_value;
1717 + require_once ABSPATH . 'wp-includes/pluggable.php';
1718 + if ( ! wp_verify_nonce( $_GET[ 'mw_adminimize_export_nonce' ], 'mw_adminimize_export_nonce' ) ) {
1719 + return;
1811 1720 }
1812 1721
1813 - return $adminimizeoption;
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();
1814 1737 }
1815 1738
1816 1739 /**
1817 - * Check if options comes from roles adminimize settings export
1818 - *
1819 - * @param array $options
1820 - *
1821 - * @return bool
1740 + * Process a settings import from a json file
1822 1741 */
1823 -function _mw_adminimize_is_roles_options_import( $options ){
1824 - global $wp_roles;
1742 +function _mw_adminimize_import_json() {
1825 1743
1826 - $roles_options = [];
1827 - foreach ( $wp_roles->role_names as $role_slug => $role_name ){
1744 + if ( empty( $_POST[ '_mw_adminimize_action' ] ) || '_mw_adminimize_import' !== $_POST[ '_mw_adminimize_action' ] ) {
1745 + return;
1746 + }
1828 1747
1829 - $role_options = array_filter(
1830 - $options, function ( $option_key ) use ( $role_slug ) {
1831 - return stripos( $option_key, '_' . $role_slug ) !== false;
1832 - }, ARRAY_FILTER_USE_KEY
1833 - );
1748 + if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_import_nonce' ], 'mw_adminimize_import_nonce' ) ) {
1749 + return;
1750 + }
1834 1751
1835 - if ( empty( $roles_options ) ){
1836 - $roles_options = $role_options;
1837 - } else {
1838 - $roles_options = array_merge( $roles_options, $role_options );
1839 - }
1752 + if ( ! current_user_can( 'manage_options' ) ) {
1753 + return;
1840 1754 }
1841 1755
1842 - if ( count( $options ) === count( $roles_options ) ){
1843 - return true;
1756 + $extension = pathinfo( $_FILES[ 'import_file' ][ 'name' ], PATHINFO_EXTENSION );
1757 + if ( $extension !== 'json' ) {
1758 + wp_die( esc_attr__( 'Please upload a valid .json file' ) );
1844 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 );
1845 1772 }