Navigation überspringen

[Gelöst] Form not submitting after adding wp_redirect for admin dashboard

This support ticket is created vor 2 years, 1 month. There's a good chance that you are reading advice that it now obsolete.

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 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 1 reply, hat 2 Stimmen.

Zuletzt aktualisiert von Minesh vor 2 years, 1 month.

Assistiert von: Minesh.

Author
Artikel
#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? versteckter Link

#2699835

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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.