edit_post_link()

最后更新于:2021-11-26 04:00:59

edit_post_link( string$text=null, string$before=”, string$after=”, int|GC_Post$id, string$class=’post-edit-link’)

Displays the edit post link for post.

参数

$text

(string) (Optional) Anchor text. If null, default is ‘Edit This’.

Default value: null

$before

(string) (Optional) Display before edit link.

Default value: ”

$after

(string) (Optional) Display after edit link.

Default value: ”

$id

(int|GC_Post) (Optional) Post ID or post object. Default is the global $post.

$class

(string) (Optional) Add custom class to link.

Default value: ‘post-edit-link’

源文件

文件: gc-includes/link-template.php

function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) {
	$post = get_post( $id );
	if ( ! $post ) {
		return;
	}

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

	if ( null === $text ) {
		$text = __( 'Edit This' );
	}

	$link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>';

	/**
	 * Filters the post edit link anchor tag.
	 *
	 * @since 2.3.0
	 *
	 * @param string $link    Anchor tag for the edit link.
	 * @param int    $post_id Post ID.
	 * @param string $text    Anchor text.
	 */
	echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;
}