get_edit_post_link()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_edit_post_link( int|WP_Post $post, string $context = 'display' ): string|null
Описание
Можно использовать как внутри цикла WordPress, так и вне его. Подходит для страниц, записей, вложений, ревизий, глобальных стилей, шаблонов и частей шаблонов.
Оригинал (английский)
Can be used within the WordPress loop or outside of it. Can be used with pages, posts, attachments, revisions, global styles, templates, and template parts.
Параметры
$post
int|WP_Post
необязательный
$context
string
необязательный
= 'display'
Возвращаемое значение
string|null
Исходный код
wp-includes/link-template.php:1452
function get_edit_post_link( $post = 0, $context = 'display' ) {
$post = get_post( $post );
if ( ! $post ) {
return null;
}
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 null;
}
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
return null;
}
$link = '';
if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) {
$slug = urlencode( get_stylesheet() . '//' . $post->post_name );
$link = admin_url( sprintf( $post_type_object->_edit_link, $post->post_type, $slug ) );
} elseif ( 'wp_navigation' === $post->post_type ) {
$link = admin_url( sprintf( $post_type_object->_edit_link, (string) $post->ID ) );
} elseif ( $post_type_object->_edit_link ) {
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
}
/**
* 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 );
}
История изменений
| Версия | Описание |
|---|---|
| 6.3.0 | Adds custom link for wp_navigation post types. Adds custom links for wp_template_part and wp_template post types. |
| 2.3.0 | Introduced. |

