Hello @soosdani
Subscribers can only see http://xyz/wp-admin/profile.php because they have no rights to the dashboard.
If you want them to see http://xyz/wp-admin/index.php, you need to give them more priveleges like “contributor” “author” or “editor” — but then, they can also make some changes!
https://developer.ww.wp.xz.cn/plugins/users/roles-and-capabilities/
Subscribers can access the dashboard though there’s little reason since there’s nothing to do there. Some of the usual dashboard widgets will not be loaded for subscribers. There’s little reason for subscribers to access the admin area except to edit their profile, so that’s why they are taken there directly.
In any case, logins can be redirected to the dashboard or any valid location with the “login_redirect” filter. Have the filter callback return the desired destination URL.
@bcworkz Good point. Maybe @soosdani has a special dashboard!
@bcworkz and @littlepackage yes, I have special dashboard with own dashboard widgets. My plugin: ~/wp-content/plugins/xyz/xyz.php:
add_filter ( 'login_redirect', 'http://xyz/wp-admin/index.php' );
Not work and the ~/wp-content/plugins/xyz/functions.php:
add_filter ( 'login_redirect', 'http://xyz/wp-admin/index.php' );
Not work too. How to?
What @bcworkz is saying is there is no point sending “subscribers” to your dashboard when they won’t see your widgets. Have you somehow set up the special widgets to be viewable by subscribers?
If yes, you are still using the ‘login_redirect’ filter wrong. You need to provide a function as the second parameter of add_filter().
-
This reply was modified 6 years, 3 months ago by
Little Package. Reason: significant grammar error
Have you somehow set up the special widgets to be viewable by subscribers?
Yes, I use add_action ( ‘wp_dashboard_setup’, … ) and wp_add_dashboard_widget. The subscribers see my dashboard widget.
The code (~/wp-content/plugins/xyz/xyz.php):
add_filter ( 'login_redirect', 'rdrct' );
function rdrct () {
return 'wp-admin';
}
It works, but is it good?
-
This reply was modified 6 years, 3 months ago by
soosdani.
-
This reply was modified 6 years, 3 months ago by
soosdani.
@soosdani
It looks fine, but you might want to give your function a really unique name to avoid conflicts with other functions that might be named rdrct() (unlikely but possible).
add_filter ( 'login_redirect', 'my_very_own_rdrct', 10, 3 );
function my_very_own_rdrct( $redirect_to, $requested_redirect_to, $user ) {
return 'wp-admin';
}
Also, this function will redirect ALL users (admin, editor, author, subscriber, etc) to the /wp-admin page. If you need to be more selective you can add a conditional to my_very_own_rdrct(). Overall, good job 🙂