[wp-trac] [WordPress Trac] #14113: Function that could improve the current edit_post_link()
WordPress Trac
wp-trac at lists.automattic.com
Sun Jun 27 15:20:43 UTC 2010
#14113: Function that could improve the current edit_post_link()
-------------------------+--------------------------------------------------
Reporter: metacortex | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Template | Version:
Severity: normal | Keywords:
-------------------------+--------------------------------------------------
Basicly this function is the same than
[http://core.trac.wordpress.org/browser/trunk/wp-includes/link-
template.php#L820 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>
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14113>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list