Opened 10 years ago
Closed 10 years ago
#29538 closed enhancement (fixed)
Sanity check before using get_edit_post_link() to build 'Edit' button in toolbar
Reported by: | boonebgorges | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.9.2 |
Component: | Toolbar | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
edit_post_link()
is used in most themes to create the 'Edit' link seen while viewing a post as an 'edit_post' user. The only way to remove this link without touching template files is to take advantage of the following lines in edit_post_link()
, which bail out of the function when get_edit_post_link()
is empty. Something like this:
function bbg_dont_show_edit_link( $link, $post_id ) { if ( $dont_show_edit_link_on_this_page ) { $link = ''; } return $link; } add_filter( 'get_edit_post_link', 'bbg_dont_show_edit_link', 10, 2 );
(See https://buddypress.trac.wordpress.org/ticket/5853 for an actual use case.)
The problem with this technique is that get_edit_post_link()
is also used to build the 'Edit' button on the toolbar. Returning an empty string from get_edit_post_link()
will result in a 'Edit' button with an empty href attribute.
I suggest doing a simple sanity check before adding the 'Edit' button. See attached patch.
(Side note - I realize that this technique for hiding the link is not ideal, but it's the only option really available to plugin devs, and in any case the proposed patch doesn't do any harm.)
In 29714: