WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 months ago

#14113 closed enhancement (wontfix)

Function that could improve the current edit_post_link()

Reported by: metacortex Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Template Keywords: needs-patch
Focuses: Cc:

Description

Basicly this function is the same than edit_post_link() but some little differences which can make it more useful for developers. So far it has two advantages:

1) The edit link can be easily returned.

2) It's possible to choose a class for link tags.

// Returned
function wp_get_edit_link($args = '') {
	$defaults = array(
		'link'   => null,
		'before' => '',
		'after'  => '',
		'id'     => 0,
		'class'  => 'post-edit-link'
	);

	$r = wp_parse_args($args, $predet);
	extract($r);

	if ( !$post = &get_post($id) )
		return;

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

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

	$post_type_obj = get_post_type_object($post->post_type);
	$link = '<a class="'. $class .'" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>';
	return $before . apply_filters('get_edit_link' , $link , $post->ID) . $after;
}

// Echoed
function wp_edit_link($args = '') {
	echo wp_get_edit_link($args);
}

Example using the function:

Returning:

<?php 
$var = get_wp_edit_link('before=<span class="my-edit-class">&after=</span>&class=my-link-class&link=Edit me!');
echo $var;
?>

Echoing:

<?php wp_edit_link('before=<span class="my-edit-class">&after=</span>&class=my-link-class&link=Edit me!'); ?>

Results on:

<span class="my-edit-class"><a class="my-link-class" href="http://url.to/post.html">Edit me!</a></span>

Change History (5)

comment:1 metacortex4 years ago

I made a mistake. The string:

$r = wp_parse_args($args, $predet);

Showld be

$r = wp_parse_args($args, $defaults);

comment:2 metacortex4 years ago

  • Version set to 3.0

comment:3 nacin4 years ago

  • Keywords needs-patch added

comment:4 nacin3 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:5 johnbillion3 months ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

We now have get_edit_post_link() which returns the edit post URL. This should be sufficient as you can craft your own <a> tag around it with whichever class name you like.

Note: See TracTickets for help on using tickets.