Skip to content

Commit

Permalink
Fix reducing of Menu items on multiple roles, new release
Browse files Browse the repository at this point in the history
  • Loading branch information
bueltge committed Jun 28, 2016
1 parent 295f96c commit 61897a5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Change Log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/bueltge/Adminimize/compare/1.10.4...HEAD)
## [Unreleased](https://github.com/bueltge/Adminimize/compare/1.10.5...HEAD)
*

## [1.10.4](https://github.com/bueltge/Adminimize/compare/1.10.4...1.10.5) - 2016-06-28
### Fixed
* Fix PHP Warning
* Fix check for active usage of Link Manager
* Fix menu var type, if is object.
* Check for multiple roles on Menu Settings, that it works only, if the option is still active on each role of this user.

## [1.10.4](https://github.com/bueltge/Adminimize/compare/1.10.3...1.10.4) - 2016-06-03
### Added
Expand Down
27 changes: 17 additions & 10 deletions adminimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* 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.
* Author: Frank Bültge
* Author URI: http://bueltge.de/
* Version: 1.10.5-dev
* Version: 1.10.5
* License: GPLv3+
*
* @package WordPress
* @author Frank Bültge <[email protected]>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 22016-06-24
* @version 22016-06-28
*/

/**
Expand All @@ -22,6 +22,7 @@
* of differently user-right and a user-friendly range in admin-area via reduce areas.
* :( grmpf i have so much wishes and hints form users, there use the plugin and
* it is not easy to development this on my free time.
* Also I hate the source, old and harrd to maintain, no OOP.
*/

if ( ! function_exists( 'add_action' ) ) {
Expand Down Expand Up @@ -581,9 +582,12 @@ function _mw_adminimize_set_menu_option() {
_mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
_mw_adminimize_debug( $submenu, 'Adminimize, WordPress Sub-Menu:' );

$user_roles = _mw_adminimize_get_all_user_roles();
//$user_roles = _mw_adminimize_get_all_user_roles();
$disabled_menu_ = array();
$disabled_submenu_ = array();
$user = wp_get_current_user();
$user_roles = $user->roles;
_mw_adminimize_debug( $user, 'Adminimize, Current User:' );

foreach ( $user_roles as $role ) {
$disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
Expand All @@ -596,16 +600,14 @@ function _mw_adminimize_set_menu_option() {

$mw_adminimize_menu = array();
$mw_adminimize_submenu = array();
$user = wp_get_current_user();
_mw_adminimize_debug( $user, 'Adminimize, Current User:' );

// Set admin-menu.
foreach ( $user_roles as $role ) {

if ( in_array( $role, $user->roles, FALSE )
&& _mw_adminimize_current_user_has_role( $role )
) {
// Create array about all items with all affected roles, important for multiple roles.
// Create array about all items with all affected roles.
foreach ( $disabled_menu_[ $role ] as $menu_item ) {
$mw_adminimize_menu[] = $menu_item;
}
Expand All @@ -617,12 +619,17 @@ function _mw_adminimize_set_menu_option() {
}

// Support Multiple Roles for users.
// Leave only the items, there are active on each roles of the users.
if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
$mw_adminimize_menu = _mw_adminimize_get_duplicate( $mw_adminimize_menu );
$mw_adminimize_submenu = _mw_adminimize_get_duplicate( $mw_adminimize_submenu );
$mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
$mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
} else {
// Alternative filter the array to remove duplicates, much faster.
$mw_adminimize_menu = array_unique( $mw_adminimize_menu );
$mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
}
_mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Settings Menu:' );
_mw_adminimize_debug( $mw_adminimize_submenu, 'Adminimize, Settings Sub-Menu:' );
_mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
_mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );

// Fallback on users.php on all user roles smaller admin.
if ( in_array( 'users.php', $mw_adminimize_menu, FALSE ) ) {
Expand Down
18 changes: 16 additions & 2 deletions inc-setup/helping_hands.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ function _mw_adminimize_debug( $data, $description = '' ) {

// Buffering to solve problems with WP core, header() etc.
ob_start();
$output = 'console.info(' . json_encode( $description ) . ');';
$output = 'console.info(' . json_encode( $description ) . ');';
$output .= 'console.log(' . json_encode( $data ) . ');';
$output = sprintf( '<script>%s</script>', $output );
$output = sprintf( '<script>%s</script>', $output );

echo $output;
}
Expand All @@ -111,3 +111,17 @@ function _mw_adminimize_get_duplicate( $array ) {
array_diff_assoc( $array, array_unique( $array ) )
);
}

/**
* Get intersection of a multiple array.
*
* @since 2016-06-28
*
* @param $array array Array with settings of all roles.
*
* @return array Data with only the data, there in each role active.
*/
function _mw_adminimize_get_intersection( $array ) {

return (array) call_user_func_array( 'array_intersect', $array );
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Adminimize",
"version": "1.10.1",
"version": "1.10.5",
"repository": {
"type": "git",
"url": "[email protected]:bueltge/Adminimize.git"
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: Bueltge, inpsyde
Donate link: https://www.paypal.me/FrankBueltge
Tags: color, scheme, theme, admin, dashboard, color scheme, plugin, interface, ui, metabox, hide, editor, minimal, menu, customization, interface, administration, lite, light, usability, lightweight, layout, zen
Requires at least: 4.0
Tested up to: 4.5.2
Stable tag: 1.10.4
Tested up to: 4.5.3
Stable tag: 1.10.5

Adminimize that lets you hide 'unnecessary' items from the WordPress backend

Expand Down Expand Up @@ -43,6 +43,12 @@ Use the installer via back-end of your install or ...
1. Settings area in WP 4.5-alpha

== Changelog ==
= 1.10.5 (2016-06-28) =
* Fix PHP Warning
* Fix check for active usage of Link Manager
* Fix menu var type, if is object.
* Check for multiple roles on Menu Settings, that it works only, if the option is still active on each role of this user.

= 1.10.4 (2016-06-03) =
* Add support for multiple roles to remove the Admin Bar via global options.
* Add support for multiple roles to remove the Admin Bar Back end items.
Expand Down

0 comments on commit 61897a5

Please sign in to comment.