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