WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 2 weeks ago

#44017 new enhancement

Add filter to display edit post link without 'edit_post' capability

Reported by: rafsuntaskin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version:
Component: Posts, Post Types Keywords: has-patch reporter-feedback
Focuses: Cc:

Description

WordPress has come a long way from just being a Blogging CMS. Now we can allow our end users to Post using different plugin without bringing the users in WP Admin. So, basically users don't need the 'edit_post' capability to be just able to create and edit posts using plugins.

Hence, this filter is needed so that plugins can allow any user to view the built in edit post link on front-end if needed.

Attachments (1)

patch.diff (477 bytes) - added by rafsuntaskin 6 weeks ago.
'can_view_edit_post_link' filter added

Download all attachments as: .zip

Change History (4)

@rafsuntaskin
6 weeks ago

'can_view_edit_post_link' filter added

#1 @johnbillion
6 weeks ago

  • Component changed from General to Posts, Post Types
  • Keywords reporter-feedback added

Thanks for the report, @rafsuntaskin, and welcome to WordPress Trac.

This seems like a conflicting requirement. If the user cannot edit a given post, what purpose would there be in allowing them to access the edit post URL? If the URL is going to point to another location, then this ought to be doable with the get_edit_post_link filter while retaining the user's ability to edit the post.

#2 @rafsuntaskin
6 weeks ago

Hi @johnbillion ,

Thank you for your response.

Even if the URL is pointing another location you can't show the link using get_edit_post_link filter unless the user has 'edit_post' capability. Because the function bails out before that filter is even fired.

As I have said we can allow users to Edit or Create posts from Front-end using various Form plugins or implementing custom forms. In that case you don't want users to have edit_posts capability as it's too much.

Suppose, we are creating a simple directory site where we allow users to post a Directory info using A custom form template which are saved as post. We can also allow users to edit the info using the Same form template. So, even if the user is set as post_author he won't see the Edit link by default. Because the edit_post_link function checks for edit_post capability and bails out immediately before running the get_edit_post_link filter.

Here is a screenshot : https://d.pr/free/i/90mOOO

Here you can see that the John is the post author and is already logged in but he can't see the Edit link as he doesn't have the edit post capability. Though he can edit the post using our custom form which we should have been able to link using the get_edit_post_link if it fired.

By allowing this patched filter we can do this from plugins without creating customized theme templates. Hence, we should be able to get this result : https://d.pr/free/i/xvITap

You can see that the default EDIT link now shows up and we can also customize the link using the get_edit_post_link filter.

Hope I was clear enough about my view. Let me know if I have missed anything.

Thanks

#3 @rafsuntaskin
2 weeks ago

@SergeyBiryukov @johnbillion @swissspidy

Please let me know your review update if you get chance to check it out.

Thanks

Note: See TracTickets for help on using tickets.