File tree Expand file tree Collapse file tree 1 file changed +34
-3
lines changed Expand file tree Collapse file tree 1 file changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,15 @@ class AdminAccess implements HookSubscriberInterface
16
16
{
17
17
public function subscribe (HookService $ service )
18
18
{
19
- if (! is_admin ()) {
20
- return ;
19
+ if (is_admin ()) {
20
+ $ service -> add_action ( ' auth_redirect ' , [ $ this , ' authorize_admin_access ' ]) ;
21
21
}
22
22
23
- $ service ->add_action ('auth_redirect ' , [$ this , 'authorize_admin_access ' ]);
23
+ $ service ->add_filter ( 'login_redirect ' ,
24
+ [$ this , 'admin_login_redirect ' ],
25
+ 10 ,
26
+ 3
27
+ );
24
28
}
25
29
26
30
/**
@@ -57,4 +61,31 @@ public function authorize_admin_access($user_id)
57
61
58
62
wp_die (__ ('Sorry, you are not allowed to access this page. ' ));
59
63
}
64
+
65
+ public function admin_login_redirect ($ redirect_to , $ requested_redirect_to , $ user )
66
+ {
67
+ $ intercept = empty ($ redirect_to ) || mb_strpos ($ redirect_to , 'wp-admin ' ) !== false ;
68
+ if (!$ intercept ) {
69
+ return $ redirect_to ;
70
+ }
71
+
72
+ $ rua_user = rua_get_user ($ user );
73
+ if ($ rua_user ->has_global_access ()) {
74
+ return $ redirect_to ;
75
+ }
76
+
77
+ $ user_levels = $ rua_user ->get_level_ids ();
78
+ if (empty ($ user_levels )) {
79
+ return $ redirect_to ;
80
+ }
81
+
82
+ $ metadata = \RUA_App::instance ()->level_manager ->metadata ()->get ('admin_access ' );
83
+ foreach ($ user_levels as $ level_id ) {
84
+ if ($ metadata ->get_data ($ level_id , true )) {
85
+ return $ redirect_to ;
86
+ }
87
+ }
88
+
89
+ return home_url ();
90
+ }
60
91
}
You can’t perform that action at this time.
0 commit comments