-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-access.php
More file actions
49 lines (41 loc) · 1.05 KB
/
Copy pathadmin-access.php
File metadata and controls
49 lines (41 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Admin felület hozzáférés korlátozása szerepkör szerint.
*
* A nem engedélyezett szerepkörű bejelentkezett felhasználókat a kezdőlapra
* irányítja, ha megpróbálják elérni a wp-admin felületet.
* Az administrator szerepkör mindig hozzáfér.
*
* @package RefiTune
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Admin hozzáférés ellenőrzése és átirányítás.
*
* @return void
*/
function refitune_restrict_admin_access(): void {
if ( wp_doing_ajax() ) {
return;
}
if ( ! is_user_logged_in() ) {
return;
}
$settings = get_option( 'refitune_settings', array() );
$allowed_roles = isset( $settings['admin_access_roles'] ) ? (array) $settings['admin_access_roles'] : array();
if ( empty( $allowed_roles ) ) {
return;
}
$user = wp_get_current_user();
$user_roles = (array) $user->roles;
foreach ( $user_roles as $role ) {
if ( in_array( $role, $allowed_roles, true ) ) {
return;
}
}
wp_safe_redirect( site_url() );
exit;
}
add_action( 'admin_init', 'refitune_restrict_admin_access' );