0

I've built a marketplace-type site that gives users the option to post, edit, and delete listings via get_delete_post_link().

For those listings, I've set up custom post types.

The problem is that only administrators are able to delete posts. The link displays correctly, but when clicked the user either is returned to the site's home page or to the current page, but nothing happens to the post.

I'm really confused about this and have spent several hours googling and trying various solutions, but none of them worked.

Among the things I tried are:

  • setting map_meta_cap to both true and false and setting up either custom capability_type or leaving it at post.
  • setting up a custom user role with specific capability_type permissions
  • installing the Members Plugin and assigning literally all available 181 permissions to the Subscriber role without any effect (i.e. when I var_dump() the capabilities it looks exactly like an admin, but behaves differently)
  • logging out various checks (is_user_logged_in(), current_user_can(), $post->post_author == $current_user->ID, etc.)
  • passing various combinations of arguments to get_delete_post_link()

I'm at the end of my wits with this.

I'd also appreciate any advice on alternative methods of "deleting" my posts. I've also though about coding up a custom AJAX function, but was scared that it would fail because of the same strange permission problem (if it is a permission problem).

Thanks for your help!

5
  • Do you mean the delete link displays and work fine for administrator but for non administrator it displays but doesn't work? – Vinod Dalvi Apr 20 '17 at 12:04
  • exactly like that. – dtx Apr 20 '17 at 15:51
  • The user should have delete_post capability to make it work. – Vinod Dalvi Apr 21 '17 at 9:52
  • The user does have that capability, the problem is that it still doesn't work... – dtx Apr 22 '17 at 15:06
  • If you share your whole code in question then we can better help you. – Vinod Dalvi Apr 22 '17 at 15:15
1

Same problem here, that I've fixed. If it's not you, maybe this will help someone.

Did you blocked the non-admin users from accessing to the /wp-admin Dashboard ? The link provide by get_delete_post_link() use wp-admin, so if you blocked the access to the non-admin, they can't execute the delete.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.