I have a script that enables a logged in user (role Author) to delete their own posts using get_delete_post_link()
. However, I also want to be able to restrict the author’s access to the dashboard. Any attempt to do so using a plugin (Theme my Login, for example) or a simple script like those linked below disables my ability to use get_delete_post_link()
. Is there a way to restrict access to the dashboard for the “Author” user role while still permitting the deletion of posts via get_delete_post_link()
?
http://www.tutorialstag.com/restrict-wordpress-dashboard-access.html
This is how I ended up solving this issue. Originally I used this code for the link to delete an individual post:
After checking to see if the user was logged in and if the user was the author of this post. This didn’t work as mentioned in my original post.
Instead I used a simple delete button (with the same checks as mentioned above):
and this jQuery script to make an ajax call that will run my php script:
In my functions.php file, I set up my ajax call:
And then, the actual php script to delete the post in my functions_custom.php file:
How about a targeted redirect when an Author attempts to view the dashboard?
(Hacked together from your linked resources and the WP Codex page for the
admin_init
action)EDIT: How to implement post-deletion redirect to a specific URL in light of the additional information provided in the comments: