[wp-trac] [WordPress Trac] #29538: Sanity check before using get_edit_post_link() to build 'Edit' button in toolbar

WordPress Trac noreply at wordpress.org
Fri Sep 5 16:02:28 UTC 2014


#29538: Sanity check before using get_edit_post_link() to build 'Edit' button in
toolbar
--------------------------+-----------------------------
 Reporter:  boonebgorges  |      Owner:
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Toolbar       |    Version:  3.9.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 `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.)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29538>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list