函数原型
get_edit_post_link( int|WP_Post $post, string $context = ‘display’ ): string|null
函数描述
Retrieves the edit post link for post.
是否弃用
未弃用
函数参数
-
$post
int|WP_Post
Optional - Post ID or post object. Default is the global
$post. -
$context
string
Optional - How to output the
'&'character. Default'&'.Default:
'display'
函数返回值
string|null The edit post link for the given post. Null if the post type does not exist or does not allow an editing UI.
函数位置
File: wp-includes/link-template.php.
函数源码
function get_edit_post_link( $post = 0, $context = 'display' ) {
$post = get_post( $post );
if ( ! $post ) {
return;
}
if ( 'revision' === $post->post_type ) {
$action = '';
} elseif ( 'display' === $context ) {
$action = '&action=edit';
} else {
$action = '&action=edit';
}
$post_type_object = get_post_type_object( $post->post_type );
if ( ! $post_type_object ) {
return;
}
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
return;
}
if ( $post_type_object->_edit_link ) {
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
} else {
$link = '';
}
/**
* Filters the post edit link.
*
* @since 2.3.0
*
* @param string $link The edit link.
* @param int $post_id Post ID.
* @param string $context The link context. If set to 'display' then ampersands
* are encoded.
*/
return apply_filters( 'get_edit_post_link', $link, $post->ID, $context );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |

