WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#12197 closed defect (bug) (fixed)

edit_post_link() - "Edit Post" shows as link title no matter what $link is entered

Reported by: sc0ttkclark Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 2.9.1
Component: Template Keywords:
Focuses: Cc:

Description

Currently when this is used:

edit_post_link('Edit this Blah Blah');

Then this is output:

<a class="post-edit-link" href="link-to-wp-admin-edit" title="Edit Post">Edit this Blah Blah</a>

Of course, that's an i18n "Edit Post" but still, this should be overwritten by the $link parameter (if provided). And even then, if none is provided the Title should be the same as the Anchor text.

See below for my proposed bug fix:

/**
 * Display edit post link for post.
 *
 * @since 1.0.0
 *
 * @param string $link Optional. Anchor text.
 * @param string $before Optional. Display before edit link.
 * @param string $after Optional. Display after edit link.
 * @param int $id Optional. Post ID.
 */
function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
	if ( !$post = &get_post( $id ) )
		return;

	if ( !$url = get_edit_post_link( $post->ID ) )
		return;

	if ( null === $link )
		$link = __('Edit This');

	$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $link ) . '">' . $link . '</a>';
	echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
}

Attachments (1)

link-template-patch.diff (572 bytes) - added by wojtekszkutnik 5 years ago.
patch

Download all attachments as: .zip

Change History (5)

@wojtekszkutnik5 years ago

patch

comment:1 @aaroncampbell5 years ago

  • Cc aaron@… added

Actually, you have to assume that $link is already translated, so you shouldn't be wrapping it in __()

comment:2 @sc0ttkclark5 years ago

Looks like this is fixed in 3.0, however it's not using $link - it's using the $post_type_obj->labels->edit_item which isn't too bad ;)

comment:3 @sc0ttkclark5 years ago

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

comment:4 @nacin4 years ago

  • Milestone changed from Future Release to 3.1
Note: See TracTickets for help on using tickets.