Skip Navigation

[Resolved] Form not submitting after adding wp_redirect for admin dashboard

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 11 months ago.

Assisted by: Minesh.

Author
Posts
#2699720

Tell us what you are trying to do? I added code to redirect non-admins to the home page (ie prevent them from accessing admin dashboard).

Below is the code for redirect.

function redirect_non_admin_users() {
if (!current_user_can('administrator') && is_admin()) {
wp_redirect(home_url());
exit;
}
}

add_action('admin_init', 'redirect_non_admin_users');

This stops the form from working (will not submit ) in AJAX. Is there a reason for this?

Is there any documentation that you are following? no

Is there a similar example that we can see? no

What is the link to your site? hidden link

#2699835

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Rather using such custom code - what if you try to use plugin to restrict user:
- https://wordpress.org/plugins/restrict-user-access/

You can find any plugin that suits your requirement:
- https://wordpress.org/plugins/search/restrict+user/

#2700833

These plugins is not what I was looking for, I was trying to see why the code impacts it, you can close the case no worries. Toolset should have a forwarding/redirect options for user types etc in my view.