WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 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.)

Attachments (1)

29538.patch (973 bytes) - added by boonebgorges 4 years ago.

Download all attachments as: .zip

Change History (3)

@boonebgorges
4 years ago

#1 @SergeyBiryukov
4 years ago

  • Keywords has-patch commit added
  • Milestone changed from Awaiting Review to 4.1

#2 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 29714:

Don't display Edit links for posts and terms in toolbar if they are empty.

props boonebgorges.
fixes #29538.

Note: See TracTickets for help on using tickets.