[Resolved] Cant Delete a Custom Post …(Only works if I am with administrator Role)
This thread is resolved. Here is a description of the problem and solution.
Problem:
The customer was using the cred-delete-post shortcode to allow users to delete posts but encountered an error message ("Something went wrong, please reload the page and try again") when attempting to delete posts with any role other than administrator. Additionally, a user with the "Adm Entidades" role was incorrectly able to see an edit form that they should not have access to.
Solution:
Upon investigation, we found that the issue stemmed from a custom code snippet that was causing redirection conflicts. Specifically, when the code included a wp_redirect function, it led to an infinite redirect scenario, preventing users from performing the delete action.
To resolve this, we temporarily disabled the custom code and moved it to the Toolset custom code section. We ensured that it would not execute during AJAX calls by unchecking the "Llamadas AJAX" option in the settings. This adjustment allowed users with the "Adm Entidades" role to delete posts without encountering the error.
The customer was able to confirm that the changes worked as intended.
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.
I´m using cred-delete-post shortcode in post view...Works perfect only if I´m logged as administrator.....
But give this error if I have any other role:
"Something went wrong, please reload the page and try again."
I Already check all de access control for any role and it is perfect...but not sure what to do...
When you say you checked the Access settings, there are two places that could affect this.
There are the Post Type settings within Access, but there are also the Toolset Forms settings for post forms that determine the ability to delete posts with via Forms.
Can you confirm that both sets of settings appear to be correct?
I am also having problems with an "edit Form" that a user with the Adm_entities Role should not be seeing, but nevertheless he and other roles that are not authorized see it....perhaps it is a general problem with permissions that also affects the issue of post deletion... I attach a screen.
Here is the code I am using for the edit Link [toolset-edit-post-link content_template_slug='4964' target='self']Editar ADM[/toolset-edit-post-link]
I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.
If you could provide us with a staging copy it'd be even better.
Our Debugging Procedures
I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.
- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link
Please, let me know if you need any additional details. Have a nice day.
I started working on this issue it but I'm still looking for a solution.
I'd like to ask permission to make a copy/staging version of your site where I can debug this closely without affecting the live site.
I'll make sure to delete this copy as soon as we get this issue fixed.
I'm afraid of debugging directly on the live site and cause issues to your visitors. Also, it is important to test a different setup as part of the troubleshooting.
Mateus! Can you make staging copy in our server?
Thats should be ok....you can leave it their after you finish
But it is necessary to create a different Database, so our production site is not affected
All right, I checked it and the issue seems to be originating from the following custom code snippet(permitir_acceso_wp_admin):
hidden link
If I temporarily disable it, then I'm able to delete the documents with a user of the role 'Adm Entidade' just fine, as soon as I re-enable it the error starts happening again. More specifically, I checked that if I comment this part:
wp_redirect(home_url());
The issue stops as well.
It looks like there are other points of the site calling the redirect function, and I belive there could be a conflict or an infinite redirect issue.
What I did in the staging site as a workaround was to move this code to the Toolset custom code: hidden link
Then I unchecked the option 'Llamadas AJAX' (please check the screenshot) so that this code isn't executed when Ajax calls are taking place.
After that I disabled the code in the code snippets plugin: hidden link
Then I tested that the original goal of the code is working, which is, if I try to access the wp-admin with a limited user, I'm sent to the default page, so the code still works and it is no longer causing conflict with the Documents deletion.
Can you please test it on the staging site and confirm it is working as expected?