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 +460 -528 1.11.11 → 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.11
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 14 * @author Frank Bültge <[email protected]>
17 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 - * @version 2024-03-15
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,13 +917,14 @@
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 929 $current_post_type = $GLOBALS[ 'post_type' ];
919 930 if ( ! isset( $current_post_type ) ) {
@@ -930,9 +941,9 @@
930 941 }
931 942
932 943 $user_roles = _mw_adminimize_get_all_user_roles();
933 944 $_mw_adminimize_admin_head = '';
934 - $metaboxes = array();
945 + $metaboxes = '';
935 946
936 947 foreach ( $user_roles as $role ) {
937 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
938 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
@@ -937,21 +948,19 @@
937 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
938 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
939 950 );
940 951
941 - if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
942 - $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
943 -
944 - continue;
952 + if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
953 + $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
945 954 }
946 955
947 - $user = $GLOBALS['current_user'];
948 - 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 ) ) {
949 958 if ( _mw_adminimize_current_user_has_role( $role )
950 - && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
951 - && 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 ] )
952 961 ) {
953 - $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
962 + $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
954 963 }
955 964 }
956 965 }
957 966
@@ -956,9 +965,9 @@
956 965 }
957 966
958 967 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
959 968 $_mw_adminimize_admin_head .= '<style type="text/css">' .
960 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
969 + $metaboxes . ' {display:none !important;}</style>' . "\n";
961 970
962 971 if ( ! empty( $metaboxes ) ) {
963 972 echo $_mw_adminimize_admin_head;
964 973 }
@@ -964,9 +973,9 @@
964 973 }
965 974 }
966 975
967 976 /**
968 - * Set link options in area links of back end.
977 + * set link options in area Links of Backend
969 978 */
970 979 function _mw_adminimize_set_link_option() {
971 980
972 981 // exclude super admin
@@ -994,11 +1003,12 @@
994 1003 }
995 1004 }
996 1005
997 1006 $link_options = '';
1007 + // new 1.7.8
998 1008 foreach ( $user_roles as $role ) {
999 1009 $user = wp_get_current_user();
1000 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1010 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1001 1011 if ( _mw_adminimize_current_user_has_role( $role )
1002 1012 && isset( $disabled_link_option_[ $role ] )
1003 1013 && is_array( $disabled_link_option_[ $role ] )
1004 1014 ) {
@@ -1008,9 +1018,9 @@
1008 1018 }
1009 1019
1010 1020 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
1011 1021 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1012 - $link_options . ' {display:none !important;}</style>' . "\n";
1022 + $link_options . ' {display:none !important;}</style>' . "\n";
1013 1023
1014 1024 if ( ! empty( $link_options ) ) {
1015 1025 echo $_mw_adminimize_admin_head;
1016 1026 }
@@ -1016,9 +1026,9 @@
1016 1026 }
1017 1027 }
1018 1028
1019 1029 /**
1020 - * Remove objects on wp nav menu.
1030 + * remove objects on wp nav menu
1021 1031 */
1022 1032 function _mw_adminimize_set_nav_menu_option() {
1023 1033
1024 1034 // exclude super admin
@@ -1046,11 +1056,12 @@
1046 1056 }
1047 1057 }
1048 1058
1049 1059 $nav_menu_options = '';
1060 + // new 1.7.8
1050 1061 foreach ( $user_roles as $role ) {
1051 1062 $user = wp_get_current_user();
1052 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1063 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1053 1064 if ( _mw_adminimize_current_user_has_role( $role )
1054 1065 && isset( $disabled_nav_menu_option_[ $role ] )
1055 1066 && is_array( $disabled_nav_menu_option_[ $role ] )
1056 1067 ) {
@@ -1057,12 +1068,13 @@
1057 1068 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1058 1069 }
1059 1070 }
1060 1071 }
1072 + //remove_meta_box( $id, 'nav-menus', 'side' );
1061 1073
1062 1074 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1063 1075 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1064 - $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1076 + $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1065 1077
1066 1078 if ( $nav_menu_options ) {
1067 1079 echo $_mw_adminimize_admin_head;
1068 1080 }
@@ -1098,11 +1110,12 @@
1098 1110 }
1099 1111 }
1100 1112
1101 1113 $widget_options = '';
1114 + // new 1.7.8
1102 1115 foreach ( $user_roles as $role ) {
1103 1116 $user = wp_get_current_user();
1104 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1117 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1105 1118 if ( _mw_adminimize_current_user_has_role( $role )
1106 1119 && isset( $disabled_widget_option_[ $role ] )
1107 1120 && is_array( $disabled_widget_option_[ $role ] )
1108 1121 ) {
@@ -1109,12 +1122,13 @@
1109 1122 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1110 1123 }
1111 1124 }
1112 1125 }
1126 + //remove_meta_box( $id, 'nav-menus', 'side' );
1113 1127
1114 1128 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1115 1129 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1116 - $widget_options . ' {display: none !important;}</style>' . "\n";
1130 + $widget_options . ' {display: none !important;}</style>' . "\n";
1117 1131
1118 1132 if ( $widget_options ) {
1119 1133 echo $_mw_adminimize_admin_head;
1120 1134 }
@@ -1120,9 +1134,9 @@
1120 1134 }
1121 1135 }
1122 1136
1123 1137 /**
1124 - * Print small user-info.
1138 + * small user-info
1125 1139 */
1126 1140 function _mw_adminimize_small_user_info() {
1127 1141
1128 1142 ?>
@@ -1137,15 +1151,13 @@
1137 1151 </div>
1138 1152 <?php
1139 1153 }
1140 1154
1155 +// Include message class.
1156 +require_once 'inc-setup/messages.php';
1141 1157 // include helping functions
1142 -require_once 'inc-setup/DebugListener.php';
1143 1158 require_once 'inc-setup/helping_hands.php';
1144 1159
1145 -// Include message class.
1146 -require_once 'inc-setup/messages.php';
1147 -
1148 1160 // inc. settings page
1149 1161 require_once 'adminimize_page.php';
1150 1162
1151 1163 // dashboard options
@@ -1152,11 +1164,14 @@
1152 1164 require_once 'inc-setup/dashboard.php';
1153 1165
1154 1166 // widget options
1155 1167 require_once 'inc-setup/widget.php';
1156 -require_once 'inc-setup/footer.php';
1157 1168 require_once 'inc-setup/admin-footer.php';
1158 1169
1170 +// global settings
1171 +// @TODO Testing, not ready for productive
1172 +//require_once( 'inc-options/settings_notice.php' );
1173 +
1159 1174 // remove admin bar
1160 1175 require_once 'inc-setup/remove-admin-bar.php';
1161 1176
1162 1177 // admin bar helper, setup
@@ -1169,19 +1184,15 @@
1169 1184
1170 1185 // Remove Admin Notices.
1171 1186 require_once 'inc-setup/remove-admin-notices.php';
1172 1187
1173 -// Add Ex-Import functions.
1174 -require_once 'inc-setup/export.php';
1175 -require_once 'inc-setup/import.php';
1176 -
1177 1188 /**
1178 1189 * Add action link(s) to plugins page
1179 1190 *
1180 - * @param array $links
1181 - * @param string $file
1191 + * @param $links , $file
1192 + * @param $file
1182 1193 *
1183 - * @return array $links
1194 + * @return $links
1184 1195 */
1185 1196 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1186 1197
1187 1198 /* create link */
@@ -1187,12 +1198,9 @@
1187 1198 /* create link */
1188 1199 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1189 1200 array_unshift(
1190 1201 $links,
1191 - sprintf(
1192 - '<a href="options-general.php?page=adminimize-options">%s</a>',
1193 - esc_attr__( 'Settings' )
1194 - )
1202 + sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, esc_attr__( 'Settings' ) )
1195 1203 );
1196 1204 }
1197 1205
1198 1206 return $links;
@@ -1198,9 +1206,9 @@
1198 1206 return $links;
1199 1207 }
1200 1208
1201 1209 /**
1202 - * Add settings in plugin-admin-page.
1210 + * settings in plugin-admin-page
1203 1211 */
1204 1212 function _mw_adminimize_add_settings_page() {
1205 1213
1206 1214 $pagehook = add_options_page(
@@ -1206,12 +1214,11 @@
1206 1214 $pagehook = add_options_page(
1207 1215 esc_attr__( 'Adminimize Options', 'adminimize' ),
1208 1216 esc_attr__( 'Adminimize', 'adminimize' ),
1209 1217 'manage_options',
1210 - 'adminimize-options',
1218 + __FILE__,
1211 1219 '_mw_adminimize_options'
1212 1220 );
1213 -
1214 1221 if ( ! is_network_admin() ) {
1215 1222 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1216 1223 }
1217 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
@@ -1216,23 +1223,15 @@
1216 1223 }
1217 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1218 1225 }
1219 1226
1220 -/**
1221 - * Enqueue script and styles for the settings page.
1222 - */
1223 1227 function _mw_adminimize_on_load_page() {
1224 1228
1225 - // Load translation files on options page.
1226 - _mw_adminimize_textdomain();
1227 -
1228 1229 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1229 1230
1230 - wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1231 1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1232 1232 wp_enqueue_style( 'adminimize-style' );
1233 1233
1234 - wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1235 1234 wp_register_script(
1236 1235 'adminimize-settings-script',
1237 1236 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1238 1237 array( 'jquery' ),
@@ -1242,36 +1241,53 @@
1242 1241 wp_enqueue_script( 'adminimize-settings-script' );
1243 1242 }
1244 1243
1245 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 +/**
1246 1269 * Get setting value for each options key.
1247 1270 *
1248 1271 * @param string|bool $key
1249 1272 *
1250 - * @return string
1273 + * @return array
1251 1274 */
1252 -function _mw_adminimize_get_option_value( $key = false ) {
1275 +function _mw_adminimize_get_option_value( $key = FALSE ) {
1253 1276
1254 - $adminimizeoptions = false;
1255 - if ( ! _mw_adminimize_exclude_settings_page() ) {
1256 - $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() );
1257 1282 }
1258 1283
1259 - if ( false === $adminimizeoptions ) {
1260 - // check for use on multisite.
1261 - if ( _mw_adminimize_is_active_on_multisite() ) {
1262 - $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1263 - } else {
1264 - $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1265 - }
1266 - wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1267 - }
1268 -
1269 1284 if ( ! $key ) {
1270 1285 return $adminimizeoptions;
1271 1286 }
1272 1287
1273 - return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : null;
1288 + /** @var array $adminimizeoptions */
1289 + return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1274 1290 }
1275 1291
1276 1292 /**
1277 1293 * Update options.
@@ -1276,36 +1292,20 @@
1276 1292 /**
1277 1293 * Update options.
1278 1294 *
1279 1295 * @param array $options
1280 - *
1281 - * @return bool
1282 1296 */
1283 1297 function _mw_adminimize_update_option( $options ) {
1284 1298
1285 1299 if ( ! current_user_can( 'manage_options' ) ) {
1286 - return FALSE;
1300 + return;
1287 1301 }
1288 1302
1289 - if ( _mw_adminimize_is_roles_options_import( $options ) ){
1290 - $options = _mw_adminimize_roles_complete_options( $options );
1291 - }
1292 -
1293 - // Remove slashes always.
1294 - foreach ( $options as $key => $value ) {
1295 - $options[ $key ] = stripslashes_deep( $value );
1296 - }
1297 -
1298 - // Kill the cache for the settings page.
1299 - wp_cache_delete( 'mw_adminimize' );
1300 1303 if ( _mw_adminimize_is_active_on_multisite() ) {
1301 1304 update_site_option( 'mw_adminimize', $options );
1302 1305 } else {
1303 1306 update_option( 'mw_adminimize', $options );
1304 1307 }
1305 - wp_cache_add( 'mw_adminimize', $options );
1306 -
1307 - return TRUE;
1308 1308 }
1309 1309
1310 1310 /**
1311 1311 * Update options in database
@@ -1329,33 +1329,8 @@
1329 1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1330 1330 }
1331 1331 }
1332 1332
1333 - // Plugin Self Settings.
1334 - if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1335 - $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1336 - } else {
1337 - $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1338 - }
1339 -
1340 - if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1341 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1342 - } else {
1343 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1344 - }
1345 -
1346 - if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1347 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1348 - } else {
1349 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1350 - }
1351 -
1352 - if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1353 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1354 - } else {
1355 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1356 - }
1357 -
1358 1333 // Admin Bar Front end settings
1359 1334 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1360 1335 'mw_adminimize_admin_bar_frontend_nodes'
1361 1336 );
@@ -1360,9 +1335,9 @@
1360 1335 'mw_adminimize_admin_bar_frontend_nodes'
1361 1336 );
1362 1337 // admin bar front end options
1363 1338 foreach ( $user_roles as $role ) {
1364 - // admin bar front-end options
1339 + // admin bar fron tend options
1365 1340 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1366 1341 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1367 1342 } else {
1368 1343 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
@@ -1423,19 +1398,10 @@
1423 1398 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1424 1399 }
1425 1400
1426 1401 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1427 - $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1428 - $_POST[ '_mw_adminimize_advice_txt' ],
1429 - array(
1430 - 'a' => array(
1431 - 'href' => array(),
1432 - 'title' => array()
1433 - ),
1434 - 'br' => array(),
1435 - 'em' => array(),
1436 - 'strong' => array(),
1437 - )
1402 + $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = htmlspecialchars(
1403 + stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] )
1438 1404 );
1439 1405 } else {
1440 1406 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1441 1407 }
@@ -1468,27 +1434,8 @@
1468 1434 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1469 1435 }
1470 1436 }
1471 1437
1472 - // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1473 -
1474 - // own menu slug
1475 - if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1476 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1477 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1478 - );
1479 - } else {
1480 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1481 - }
1482 - // own custom menu slug
1483 - if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1484 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1485 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1486 - );
1487 - } else {
1488 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1489 - }
1490 -
1491 1438 // global_options, metaboxes update
1492 1439 foreach ( $user_roles as $role ) {
1493 1440
1494 1441 // global options
@@ -1555,19 +1502,15 @@
1555 1502 }
1556 1503
1557 1504 // own options
1558 1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1559 - $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1560 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1561 - );
1506 + $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1562 1507 } else {
1563 1508 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1564 1509 }
1565 1510
1566 1511 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1567 - $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1568 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1569 - );
1512 + $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1570 1513 } else {
1571 1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1572 1515 }
1573 1516
@@ -1573,9 +1516,9 @@
1573 1516
1574 1517 // own post options
1575 1518 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1576 1519 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1577 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1520 + $_POST[ '_mw_adminimize_own_post_values' ]
1578 1521 );
1579 1522 } else {
1580 1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1581 1524 }
@@ -1581,9 +1524,9 @@
1581 1524 }
1582 1525
1583 1526 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1584 1527 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1585 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1528 + $_POST[ '_mw_adminimize_own_post_options' ]
1586 1529 );
1587 1530 } else {
1588 1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1589 1532 }
@@ -1590,9 +1533,9 @@
1590 1533
1591 1534 // own page options
1592 1535 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1593 1536 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1594 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1537 + $_POST[ '_mw_adminimize_own_page_values' ]
1595 1538 );
1596 1539 } else {
1597 1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1598 1541 }
@@ -1598,9 +1541,9 @@
1598 1541 }
1599 1542
1600 1543 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1601 1544 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1602 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1545 + $_POST[ '_mw_adminimize_own_page_options' ]
1603 1546 );
1604 1547 } else {
1605 1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1606 1549 }
@@ -1608,9 +1551,9 @@
1608 1551 // own custom post options
1609 1552 foreach ( $post_types as $post_type ) {
1610 1553 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1611 1554 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1612 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1555 + $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1613 1556 );
1614 1557 } else {
1615 1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1616 1559 }
@@ -1616,9 +1559,9 @@
1616 1559 }
1617 1560
1618 1561 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1619 1562 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1620 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1563 + $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1621 1564 );
1622 1565 } else {
1623 1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1624 1567 }
@@ -1626,9 +1569,9 @@
1626 1569
1627 1570 // own link options
1628 1571 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1629 1572 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1630 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1573 + $_POST[ '_mw_adminimize_own_link_values' ]
1631 1574 );
1632 1575 } else {
1633 1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1634 1577 }
@@ -1634,9 +1577,9 @@
1634 1577 }
1635 1578
1636 1579 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1637 1580 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1638 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1581 + $_POST[ '_mw_adminimize_own_link_options' ]
1639 1582 );
1640 1583 } else {
1641 1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1642 1585 }
@@ -1643,9 +1586,9 @@
1643 1586
1644 1587 // wp nav menu options
1645 1588 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1646 1589 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1647 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1590 + $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1648 1591 );
1649 1592 } else {
1650 1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1651 1594 }
@@ -1651,9 +1594,9 @@
1651 1594 }
1652 1595
1653 1596 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1654 1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1655 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1598 + $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1656 1599 );
1657 1600 } else {
1658 1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1659 1602 }
@@ -1660,9 +1603,9 @@
1660 1603
1661 1604 // widget options
1662 1605 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1663 1606 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1664 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1607 + $_POST[ '_mw_adminimize_own_widget_values' ]
1665 1608 );
1666 1609 } else {
1667 1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1668 1611 }
@@ -1668,9 +1611,9 @@
1668 1611 }
1669 1612
1670 1613 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1671 1614 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1672 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1615 + $_POST[ '_mw_adminimize_own_widget_options' ]
1673 1616 );
1674 1617 } else {
1675 1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1676 1619 }
@@ -1677,9 +1620,9 @@
1677 1620
1678 1621 // own dashboard options
1679 1622 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1680 1623 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1681 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1624 + $_POST[ '_mw_adminimize_own_dashboard_values' ]
1682 1625 );
1683 1626 } else {
1684 1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1685 1628 }
@@ -1685,9 +1628,9 @@
1685 1628 }
1686 1629
1687 1630 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1688 1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1689 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1632 + $_POST[ '_mw_adminimize_own_dashboard_options' ]
1690 1633 );
1691 1634 } else {
1692 1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1693 1636 }
@@ -1702,45 +1645,23 @@
1702 1645 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1703 1646 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1704 1647 }
1705 1648
1706 - /**
1707 - * Filter the adminimize options.
1708 - *
1709 - * Make the options filterable, so we can modify what is saved before it's sent to the db
1710 - *
1711 - * @since 1.11.6
1712 - *
1713 - * @param array $adminimizeoptions the original options.
1714 - * @param array $user_roles Array of the user roles.
1715 - * @param array $_POST Post data.
1716 - */
1717 - $adminimizeoptions = apply_filters( 'mw_adminimize_options_before_update', $adminimizeoptions, $user_roles, $_POST );
1718 -
1719 1649 // update
1720 - $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1650 + _mw_adminimize_update_option( $adminimizeoptions );
1721 1651
1722 1652 $myErrors = new _mw_adminimize_message_class();
1723 - if ( $update_status ) {
1724 - $message = $myErrors->get_error(
1653 + $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1725 1654 '_mw_adminimize_update'
1726 - );
1727 - } else {
1728 - $message = $myErrors->get_error(
1729 - '_mw_adminimize_access_denied'
1730 - );
1731 - }
1732 - echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1733 -
1734 - return TRUE;
1655 + ) . '</p></div>';
1656 + echo $myErrors;
1735 1657 }
1736 1658
1737 1659 /**
1738 1660 * Delete options in database
1739 1661 */
1740 -function _mw_adminimize_uninstall() {
1662 +function _mw_adminimize_deinstall() {
1741 1663
1742 - wp_cache_delete( 'mw_adminimize' );
1743 1664 delete_site_option( 'mw_adminimize' );
1744 1665 delete_option( 'mw_adminimize' );
1745 1666 }
1746 1667
@@ -1749,16 +1670,11 @@
1749 1670 */
1750 1671 function _mw_adminimize_install() {
1751 1672
1752 1673 if ( ! is_admin() ) {
1753 - return;
1674 + return NULL;
1754 1675 }
1755 1676
1756 - // If is AJAX Call.
1757 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
1758 - return;
1759 - }
1760 -
1761 1677 global $menu, $submenu;
1762 1678
1763 1679 $user_roles = _mw_adminimize_get_all_user_roles();
1764 1680 $adminimizeoptions = array();
@@ -1786,55 +1702,71 @@
1786 1702 add_site_option( 'mw_adminimize', $adminimizeoptions );
1787 1703 } else {
1788 1704 add_option( 'mw_adminimize', $adminimizeoptions );
1789 1705 }
1790 - wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1791 1706 }
1792 1707
1793 1708 /**
1794 - * Make sure adminimize option is complete when a role json file is imported
1795 - *
1796 - * @param array $roles_options
1797 - *
1798 - * @return array
1709 + * Process a settings export that generates a .json file of the shop settings
1799 1710 */
1800 -function _mw_adminimize_roles_complete_options( $roles_options ){
1711 +function _mw_adminimize_export_json() {
1801 1712
1802 - $adminimizeoption = _mw_adminimize_get_option_value();
1713 + if ( empty( $_GET[ '_mw_adminimize_export' ] ) || 'true' !== $_GET[ '_mw_adminimize_export' ] ) {
1714 + return;
1715 + }
1803 1716
1804 - foreach ( $roles_options as $role_option_name => $role_option_value ){
1805 - $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;
1806 1720 }
1807 1721
1808 - 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();
1809 1737 }
1810 1738
1811 1739 /**
1812 - * Check if options comes from roles adminimize settings export
1813 - *
1814 - * @param array $options
1815 - *
1816 - * @return bool
1740 + * Process a settings import from a json file
1817 1741 */
1818 -function _mw_adminimize_is_roles_options_import( $options ){
1819 - global $wp_roles;
1742 +function _mw_adminimize_import_json() {
1820 1743
1821 - $roles_options = [];
1822 - 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 + }
1823 1747
1824 - $role_options = array_filter(
1825 - $options, function ( $option_key ) use ( $role_slug ) {
1826 - return stripos( $option_key, '_' . $role_slug ) !== false;
1827 - }, ARRAY_FILTER_USE_KEY
1828 - );
1748 + if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_import_nonce' ], 'mw_adminimize_import_nonce' ) ) {
1749 + return;
1750 + }
1829 1751
1830 - if ( empty( $roles_options ) ){
1831 - $roles_options = $role_options;
1832 - } else {
1833 - $roles_options = array_merge( $roles_options, $role_options );
1834 - }
1752 + if ( ! current_user_can( 'manage_options' ) ) {
1753 + return;
1835 1754 }
1836 1755
1837 - if ( count( $options ) === count( $roles_options ) ){
1838 - 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' ) );
1839 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 );
1840 1772 }