Skip to content

Commit 665f541

Browse files
authored
Merge pull request #2 from angelorocha/v1.1.2
V1.1.2
2 parents fe69110 + 0359cd8 commit 665f541

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2010
-658
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@ This plugin allows efficient management of users, roles and capabilities. Create
1010
- Set default role for user without roles;
1111
- Access to admin menu by role;
1212
- Auto add role to new users;
13+
- Show/Hide admin bar to specific roles;
14+
- Show/Hide Widgets on admin/front to specific roles;
15+
- Show/Hide individual sidebar widgets to specific roles;
16+
- Content access by user role;
1317

1418
### Installation
1519
1. Upload plugin folder to the `/wp-content/plugins/` directory
1620
2. Activate the plugin through the 'Plugins' menu in WordPress
1721
3. Enjoy
1822

23+
### Developing
24+
To contribute to the plugin, open your favorite terminal and navigate to the root directory of the plugin.
25+
Type the command: `npm install`.
26+
27+
After the dependencies are installed, type `gulp watch` and start developing.
28+
29+
Source files to scss: `assets/src/sass/`
30+
31+
Source files to js: `assets/src/js/`
32+
1933
### Screenshots
2034
![Screen](./assets/screens/screenshot-1.png "Screen")
2135
![Screen](./assets/screens/screenshot-2.png "Screen")
@@ -24,3 +38,9 @@ This plugin allows efficient management of users, roles and capabilities. Create
2438
![Screen](./assets/screens/screenshot-5.png "Screen")
2539
![Screen](./assets/screens/screenshot-6.png "Screen")
2640
![Screen](./assets/screens/screenshot-7.png "Screen")
41+
![Screen](./assets/screens/screenshot-8.png "Screen")
42+
![Screen](./assets/screens/screenshot-9.png "Screen")
43+
![Screen](./assets/screens/screenshot-10.png "Screen")
44+
![Screen](./assets/screens/screenshot-11.png "Screen")
45+
![Screen](./assets/screens/screenshot-12.png "Screen")
46+
![Screen](./assets/screens/screenshot-13.png "Screen")

admin/classes/WPSSAdminFrontend.php

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace WpssUserManager\Admin;
44

55
/** Prevent direct access */
6-
if ( ! function_exists( 'add_action' ) ):
6+
if ( !defined( 'ABSPATH' ) ) {
77
header( 'HTTP/1.0 403 Forbidden' );
88
exit;
9-
endif;
9+
}
1010

1111
/**
1212
* Class WPSSAdminFrontend
@@ -34,11 +34,13 @@ public static function admin_main_content(): void {
3434
*/
3535
public static function nav_menu_tabs(): array {
3636
return [
37-
'roles-tab' => __( 'Roles List', 'wpss-ultimate-user-management' ),
38-
'menus-tab' => __( 'Menu Items', 'wpss-ultimate-user-management' ),
39-
'caps-tab' => __( 'Capabilities List', 'wpss-ultimate-user-management' ),
40-
'users-tab' => __( 'User Management', 'wpss-ultimate-user-management' ),
41-
'settings-tab' => __( 'Settings', 'wpss-ultimate-user-management' ),
37+
'roles-tab' => __( 'Roles List', 'wpss-ultimate-user-management' ),
38+
'menus-tab' => __( 'Menu Items', 'wpss-ultimate-user-management' ),
39+
'caps-tab' => __( 'Capabilities List', 'wpss-ultimate-user-management' ),
40+
'users-tab' => __( 'User Management', 'wpss-ultimate-user-management' ),
41+
'widgets-tab' => __( 'Admin/Front Widgets', 'wpss-ultimate-user-management' ),
42+
'individual-widgets-tab' => __( 'Sidebar Widgets', 'wpss-ultimate-user-management' ),
43+
'settings-tab' => __( 'Settings', 'wpss-ultimate-user-management' ),
4244
];
4345
}
4446

@@ -54,12 +56,13 @@ public static function nav_menu_tabs(): array {
5456
public static function render_template( array $template ): void {
5557
if ( in_array( $template['template'], self::template_whitelist() ) ) {
5658
$file_path = WPSS_URCM_PLUGIN_PATH . "admin/templates/{$template['template']}.php";
57-
$output = __( 'Template not found...', 'wpss-ultimate-user-management' );
58-
if ( file_exists( $file_path ) ):
59+
$output = __( 'Template not found...', 'wpss-ultimate-user-management' );
60+
if ( file_exists( $file_path ) ) {
5961
ob_start();
6062
require $file_path;
6163
$output = ob_get_clean();
62-
endif;
64+
}
65+
6366
echo wp_kses( $output, self::sanitize_output() );
6467
}
6568
}
@@ -71,49 +74,61 @@ public static function render_template( array $template ): void {
7174
*/
7275
public static function sanitize_output(): array {
7376
return [
74-
'div' => [ 'class' => [], 'id' => [] ],
75-
'table' => [ 'class' => [], 'id' => [] ],
76-
'thead' => [ 'class' => [], 'id' => [] ],
77-
'tr' => [ 'class' => [], 'id' => [] ],
78-
'td' => [ 'class' => [], 'id' => [], 'colspan' => [] ],
79-
'th' => [ 'scope' => [] ],
80-
'caption' => [ 'class' => [] ],
81-
'tbody' => [ 'class' => [], 'id' => [] ],
82-
'tfoot' => [ 'class' => [], 'id' => [] ],
83-
'a' => [ 'href' => [], 'title' => [], 'class' => [], 'id' => [], 'target' => [] ],
84-
'p' => [ 'class' => [], 'id' => [] ],
85-
'hr' => [],
86-
'ul' => [ 'class' => [], 'id' => [] ],
87-
'li' => [ 'label' => [], 'class' => [] ],
88-
'h3' => [ 'class' => [], 'id' => [] ],
89-
'u' => [],
90-
'br' => [],
91-
'img' => [ 'alt' => [], 'src' => [], 'class' => [], 'id' => [] ],
92-
'strong' => [ 'class' => [], 'id' => [] ],
93-
'span' => [
77+
'div' => [ 'class' => [], 'id' => [], 'role' => [], 'aria-label' => [], 'aria-pressed' => [] ],
78+
'table' => [ 'class' => [], 'id' => [] ],
79+
'thead' => [ 'class' => [], 'id' => [] ],
80+
'tr' => [ 'class' => [], 'id' => [] ],
81+
'td' => [ 'class' => [], 'id' => [], 'colspan' => [] ],
82+
'th' => [ 'scope' => [] ],
83+
'caption' => [ 'class' => [] ],
84+
'tbody' => [ 'class' => [], 'id' => [] ],
85+
'tfoot' => [ 'class' => [], 'id' => [] ],
86+
'a' => [ 'href' => [], 'title' => [], 'class' => [], 'id' => [], 'target' => [] ],
87+
'p' => [ 'class' => [], 'id' => [] ],
88+
'hr' => [],
89+
'ul' => [ 'class' => [], 'id' => [] ],
90+
'li' => [ 'label' => [], 'class' => [] ],
91+
'h1' => [ 'class' => [], 'id' => [] ],
92+
'h2' => [ 'class' => [], 'id' => [] ],
93+
'h3' => [ 'class' => [], 'id' => [] ],
94+
'h4' => [ 'class' => [], 'id' => [] ],
95+
'u' => [],
96+
'i' => [ 'class' => [], 'id' => [] ],
97+
'link' => [ 'rel' => [], 'href' => [], 'id' => [] ],
98+
'small' => [],
99+
'pre' => [],
100+
'br' => [],
101+
'img' => [ 'alt' => [], 'src' => [], 'class' => [], 'id' => [] ],
102+
'strong' => [ 'class' => [], 'id' => [] ],
103+
'span' => [
94104
'class' => [],
95105
'id' => [],
96106
'data-role-id' => [],
97107
'data-role-name' => [],
98108
'data-user-id' => [],
99109
'title' => [],
100110
],
101-
'form' => [ 'method' => [], 'action' => [], 'class' => [] ],
102-
'label' => [ 'for' => [], 'class' => [], 'id' => [] ],
103-
'input' => [
104-
'type' => [],
105-
'name' => [],
106-
'value' => [],
107-
'id' => [],
108-
'class' => [],
109-
'required' => [],
110-
'checked' => [],
111-
'placeholder' => [],
112-
'title' => [],
111+
'form' => [ 'method' => [], 'action' => [], 'class' => [], 'id' => [] ],
112+
'label' => [ 'for' => [], 'class' => [], 'id' => [] ],
113+
'input' => [
114+
'type' => [],
115+
'name' => [],
116+
'value' => [],
117+
'id' => [],
118+
'class' => [],
119+
'required' => [],
120+
'checked' => [],
121+
'placeholder' => [],
122+
'title' => [],
123+
'autocomplete' => [],
124+
'aria-expanded' => [],
125+
'aria-owns' => [],
126+
'style' => [],
113127
],
114-
'select' => [ 'name' => [], 'class' => [], 'id' => [], 'required' => [], 'onchange' => [], ],
115-
'option' => [ 'value' => [], 'selected' => [] ],
116-
'button' => [ 'type' => [], 'class' => [], 'id' => [] ],
128+
'select' => [ 'name' => [], 'class' => [], 'id' => [], 'required' => [], 'onchange' => [], ],
129+
'textarea' => [ 'name' => [], 'class' => [], 'id' => [], 'rows' => [], 'cols' => [] ],
130+
'option' => [ 'value' => [], 'selected' => [] ],
131+
'button' => [ 'type' => [], 'class' => [], 'id' => [], 'role' => [], 'hidefocus' => [] ],
117132
];
118133
}
119134

@@ -129,10 +144,13 @@ public static function template_whitelist(): array {
129144
'menus-tab',
130145
'roles-tab',
131146
'users-tab',
147+
'widgets-tab',
148+
'individual-widgets-tab',
132149
'settings-tab',
133150
'content/caps-actions',
134151
'content/user-details',
135152
'content/users-table',
153+
'content/post-type-access-metabox',
136154
'messages/user-role-add',
137155
'messages/user-role-remove',
138156
'messages/add-role-cap',

admin/classes/WPSSAdminPages.php

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use JetBrains\PhpStorm\NoReturn;
66

77
/** Prevent direct access */
8-
if ( ! function_exists( 'add_action' ) ):
8+
if ( !defined( 'ABSPATH' ) ) {
99
header( 'HTTP/1.0 403 Forbidden' );
1010
exit;
11-
endif;
11+
}
1212

1313
/**
1414
* Class WPSSAdminPages
@@ -53,57 +53,59 @@ public function __construct() {
5353
* @since 1.0.0
5454
*/
5555
public static function instance(): object {
56-
if ( is_null( self::$instance ) ):
56+
if ( is_null( self::$instance ) ) {
5757
self::$instance = new self();
58-
endif;
58+
}
5959

6060
return self::$instance;
6161
}
6262

6363
/**
6464
* Insert options action
65+
* @return void
6566
* @since 1.0.0
6667
*/
6768
#[NoReturn] public static function insert_options_action(): void {
6869
WPSSUserRolesCapsManager::wpss_ajax_check_referer();
69-
$get_data = WPSSPostGet::post('wpss_admin_menus');
70+
$get_data = WPSSPostGet::post( 'wpss_admin_menus' );
7071
parse_str( $get_data, $menu_data );
7172
$key = wp_strip_all_tags( $menu_data['wpss-get-role-to-remove-menu'] );
7273
$val = [];
73-
if ( ! empty( $menu_data['wpss-show-menu-item'] ) ) {
74-
$val = array_map( 'wp_strip_all_tags', (array) $menu_data['wpss-show-menu-item'] );
74+
if ( !empty( $menu_data['wpss-show-menu-item'] ) ) {
75+
$val = array_map( 'wp_strip_all_tags', (array)$menu_data['wpss-show-menu-item'] );
7576
}
7677
$format_data = [ $key => $val ];
77-
if ( empty( $key ) ):
78+
if ( empty( $key ) ) {
7879
echo esc_html__( 'Select a valid role', 'wpss-ultimate-user-management' );
7980
exit;
80-
endif;
81+
}
8182
self::instance()->set_option( wp_json_encode( $format_data ) );
8283
echo esc_html__( 'Options updated successfully', 'wpss-ultimate-user-management' );
8384
exit;
8485
}
8586

8687
/**
8788
* Remove admin menus from a role
89+
* @return void
8890
* @since 1.0.0
8991
*/
9092
public function remove_menu_items_from_role(): void {
91-
if ( ! empty( self::get_option() ) ):
93+
if ( !empty( self::get_option() ) ) {
9294
global $menu;
93-
foreach ( self::get_option() as $get_role => $get_menu ):
94-
if ( current_user_can( $get_role ) && ! is_super_admin() ):
95-
foreach ( $get_menu as $remove_menu ):
95+
foreach ( self::get_option() as $get_role => $get_menu ) {
96+
if ( current_user_can( $get_role ) && !is_super_admin() ) {
97+
foreach ( $get_menu as $remove_menu ) {
9698
/** @var array $menu Avoid php warnings, related bug
9799
* here: https://core.trac.wordpress.org/ticket/23767
98100
* Some menus are not removed in the admin_menu hook, to
99101
* solve this problem this method is linked to the admin_init hook.
100102
*/
101103
$menu[] = $remove_menu;
102104
remove_menu_page( $remove_menu );
103-
endforeach;
104-
endif;
105-
endforeach;
106-
endif;
105+
}
106+
}
107+
}
108+
}
107109
}
108110

109111
/**
@@ -117,15 +119,15 @@ public static function get_menu_list(): array {
117119
* Key 1: Menu capabilities
118120
* Key 2: Menu ID (used to unset)
119121
*/
120-
$menus = self::instance()->get_admin_menu();
122+
$menus = self::instance()->get_admin_menu();
121123
$get_menus = [];
122-
foreach ( $menus as $menu ):
123-
if ( $menu[1] !== 'read' ):
124+
foreach ( $menus as $menu ) {
125+
if ( $menu[1] !== 'read' ) {
124126
/** @var array $menu_title remove menu notifications from option title */
125127
preg_match( '/(?<=^|>).*?(?=<|$)/s', $menu[0], $menu_title );
126128
$get_menus[ $menu[2] ] = esc_attr( $menu_title[0] );
127-
endif;
128-
endforeach;
129+
}
130+
}
129131

130132
return $get_menus;
131133
}
@@ -137,10 +139,10 @@ public static function get_menu_list(): array {
137139
*/
138140
public static function get_option(): array {
139141
$instance = self::instance();
140-
$output = [];
141-
if ( $instance->option_exists() ):
142+
$output = [];
143+
if ( $instance->option_exists() ) {
142144
$output = json_decode( WPSSPluginHelper::get_option( self::$admin_menu_perms_option ), true );
143-
endif;
145+
}
144146

145147
return $output;
146148
}
@@ -149,33 +151,33 @@ public static function get_option(): array {
149151
* Set access options
150152
*
151153
* @param string $value
152-
*
154+
* @return void
153155
* @since 1.0.0
154156
*/
155157
public function set_option( string $value ): void {
156-
if ( ! self::option_exists() ):
158+
if ( !self::option_exists() ) {
157159
WPSSPluginHelper::add_option( self::$admin_menu_perms_option, $value );
158-
else:
160+
} else {
159161
self::update_option( $value );
160-
endif;
162+
}
161163
}
162164

163165
/**
164166
* Update access options
165167
*
166168
* @param string $update
167-
*
169+
* @return void
168170
* @since 1.0.0
169171
*/
170172
public function update_option( string $update ): void {
171173
$update_data = self::get_option();
172-
$get_data = json_decode( $update, true );
173-
foreach ( $get_data as $key => $val ):
174+
$get_data = json_decode( $update, true );
175+
foreach ( $get_data as $key => $val ) {
174176
$update_data[ $key ] = $val;
175-
if ( empty( $update_data[ $key ] ) ):
177+
if ( empty( $update_data[ $key ] ) ) {
176178
unset( $update_data[ $key ] );
177-
endif;
178-
endforeach;
179+
}
180+
}
179181
WPSSPluginHelper::update_option( self::$admin_menu_perms_option, wp_json_encode( $update_data ) );
180182
}
181183

@@ -185,9 +187,9 @@ public function update_option( string $update ): void {
185187
* @since 1.0.0
186188
*/
187189
public function option_exists(): bool {
188-
if ( ! WPSSPluginHelper::get_option( self::$admin_menu_perms_option ) ):
190+
if ( !WPSSPluginHelper::get_option( self::$admin_menu_perms_option ) ) {
189191
return false;
190-
endif;
192+
}
191193

192194
return true;
193195
}
@@ -199,9 +201,9 @@ public function option_exists(): bool {
199201
*/
200202
public function get_admin_menu(): array {
201203
global $menu;
202-
if ( empty( self::$get_menus ) ):
204+
if ( empty( self::$get_menus ) ) {
203205
self::$get_menus = $menu;
204-
endif;
206+
}
205207

206208
return self::$get_menus;
207209
}

0 commit comments

Comments
 (0)