为了在前台能够直接定位到需要编辑的评论,可以使用WordPress函数edit_comment_link来取得某条评论的编辑链接。下面一起来学习下edit_comment_link函数,以及它的函数原型,看看是如何实现的。
edit_comment_link( string $text = null, string $before = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, string $after = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ )
显示带有格式的编辑注释链接。
参数
$text
(string) (可选) 锚文本,如果为空,则显示编辑此。
默认值: null
$before
(string) (可选) 在链接输出之前显示。
默认值: ”
$after
(string) (可选) 在链接输出后显示。
默认值: ”
函数原型
该函数位于wp-includes/link-template.php,在线地址:https://developer.wordpress.org/reference/files/wp-includes/link-template.php/
function edit_comment_link( $text = null, $before = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, $after = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ) {
$comment = get_comment();
if ( ! current_user_can( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’edit_comment\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, $comment->comment_ID ) ) {
return;
}
if ( null === $text ) {
$text = __( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’Edit This\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );
}
$link = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<a class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”comment-edit-link\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . esc_url( get_edit_comment_link( $comment ) ) . \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $text . \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'</a>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;
/**
* Filters the comment edit link anchor tag.
*
* @since 2.3.0
*
* @param string $link Anchor tag for the edit link.
* @param int $comment_id Comment ID.
* @param string $text Anchor text.
*/
echo $before . apply_filters( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’edit_comment_link\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, $link, $comment->comment_ID, $text ) . $after;
}
简单使用
使用默认值显示编辑注释链接。
edit_comment_link();
在段落中显示带有链接文本“编辑评论”的编辑注释链接。
edit_comment_link( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’编辑评论\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<p>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'</p>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );