Passer la navigation

[Résolu] AJAX pagination does not work with custom role

This support ticket is created Il y a 3 years, 9 months. 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Fuseau horaire du supporter : America/Jamaica (GMT-05:00)

Ce sujet contient 7 réponses, a 2 voix.

Dernière mise à jour par Meg Il y a 3 years, 8 months.

Assisté par: Shane.

Auteur
Publications
#2452197

Meg

Hi,
Is it possible to reopen this topic?
https://toolset.com/forums/topic/ajax-pagination-does-not-work-with-nested-view-2/

I recovered the error logs, where can I upload them?

thanks you

#2452385

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hello,

Unfortunately due to the amount of time that has passed i'm not able to re-open the ticket.

What I recommend is that you upload the logs to Google Drive or Dropbox and share the file with me.

Thanks,
Shane

#2453199

Meg
Immagine 2022-09-08 182624.png

Hi Shane,

here you can find the logs:
lien caché

I noticed on admin-ajax.php a 302 redirect when I try to change pagination with the custom role as if it doesn't have the right permissions to access the content

thank you

#2453267

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hello,

Perhaps there is some permissions issue for your server.

What you can do is to contact your server hosts and have them look at this error for you.

Additionally you can work around this by recreating the user role and then copying the permissions from one of the roles that work.

From there you can re-assign the users to the recreated role.

Thanks,
Shane

#2453817

Meg

Hi Shane,

I did some tests with WordPress default roles.
The subscriber role also has the same problem with pagination.
The permission required for pagination to work properly is "edit_posts".
This is potentially a problem because users under the "Agenti IT" role must not be able to edit posts or access the WordPress administrative area but only this page:
lien caché
Is there a reason why this permission is required in order to use pagination?

thank you

#2453897

Meg

Hi Shane,

I think I have found a solution, I had added this code to prevent users with the "Agenti IT" role from reaching the WordPress dashboard.

function wpse66093_no_admin_access() {
	$redirect = home_url( '/' );
	if ( is_admin() && !current_user_can( 'edit_posts' ) ) { 
		wp_redirect($redirect);
		exit();
	}
}
add_action( 'admin_init', 'wpse66093_no_admin_access' );

However, it seems to create problems with pagination, the problem seems to be solved by adding this this "!wp_doing_ajax()" to condition:

function wpse66093_no_admin_access() {
	$redirect = home_url( '/' );
	if (is_admin() && !wp_doing_ajax() && !current_user_can( 'edit_posts' ) ) { // delete_posts
		wp_redirect($redirect);
		exit();
	}
}
add_action( 'admin_init', 'wpse66093_no_admin_access' );

thank you

#2455673

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Meg,

I'm happy to see that you're able to solve the issue as well as sharing it here as it might be helpful to other users as well.

Thanks,
Shane

#2459187

Meg

My issue is resolved now. Thank you!