Outil de recherche WordPress pour les développeurs et auteurs de thèmes



edit_post_link ›

Depuis1.0.0
Dépréciéen/a
edit_post_link ( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' )
Paramètres: (5)
  • (string) $text Optional. Anchor text. If null, default is 'Edit This'. Default null.
    Requis: Non
    Défaut: null
  • (string) $before Optional. Display before edit link. Default empty.
    Requis: Non
    Défaut: (vide)
  • (string) $after Optional. Display after edit link. Default empty.
    Requis: Non
    Défaut: (vide)
  • (int|WP_Post) $id Optional. Post ID or post object. Default is the global `$post`.
    Requis: Non
    Défaut:
  • (string) $class Optional. Add custom class to link. Default 'post-edit-link'.
    Requis: Non
    Défaut: 'post-edit-link'
Défini(e) dans:
Codex:
Changelog:
  • 4.4.0

Displays the edit post link for post.



Source

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;
}