On this page
get_edit_post_link( int|WP_Post $post, string $context = 'display' ): string|null
Retrieves the edit post link for post.
Description
Can be used within the WordPress loop or outside of it. Can be used with pages, posts, attachments, and revisions.
Parameters
$postint|WP_Post Optional-
Post ID or post object. Default is the global
$post. $contextstring Optional-
How to output the
'&'character. Default'&'.Default:
'display'
Return
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.
Source
File: wp-includes/link-template.php. View all references
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 );
}
Hooks
- apply_filters( 'get_edit_post_link',
string $link ,int $post_id ,string $context ) -
Filters the post edit link.
Related
Uses
| Uses | Description |
|---|---|
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| admin_url() wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
Used By
| Used By | Description |
|---|---|
| wp_get_post_revisions_url() wp-includes/revision.php | Returns the url for viewing and potentially restoring revisions of a given post. |
| do_block_editor_incompatible_meta_box() wp-admin/includes/template.php | Renders a “fake” meta box with an information message, shown on the block editor, when an incompatible meta box is found. |
| WP_Posts_List_Table::handle_row_actions() wp-admin/includes/class-wp-posts-list-table.php | Generates and displays row action links. |
| WP_Posts_List_Table::column_title() wp-admin/includes/class-wp-posts-list-table.php | Handles the title column output. |
| WP_Media_List_Table::column_parent() wp-admin/includes/class-wp-media-list-table.php | Handles the parent column output. |
| WP_Media_List_Table::column_title() wp-admin/includes/class-wp-media-list-table.php | Handles the title column output. |
| wp_dashboard_recent_posts() wp-admin/includes/dashboard.php | Generates Publishing Soon and Recently Published sections. |
| wp_dashboard_recent_drafts() wp-admin/includes/dashboard.php | Show recent drafts of the user on the dashboard. |
| attachment_submitbox_metadata() wp-admin/includes/media.php | Displays non-editable attachment metadata in the publish meta box. |
| _admin_notice_post_locked() wp-admin/includes/post.php | Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. |
| post_submit_meta_box() wp-admin/includes/meta-boxes.php | Displays post submit form fields. |
| WP_Media_List_Table::_get_row_actions() wp-admin/includes/class-wp-media-list-table.php | |
| WP_Comments_List_Table::column_response() wp-admin/includes/class-wp-comments-list-table.php | |
| redirect_post() wp-admin/includes/post.php | Redirects to previous page. |
| edit_post_link() wp-includes/link-template.php | Displays the edit post link for post. |
| wp_admin_bar_edit_menu() wp-includes/admin-bar.php | Provides an edit link for posts and terms. |
| wp_post_revision_title() wp-includes/post-template.php | Retrieves formatted date timestamp of a revision (linked to that revisions’s page). |
| wp_post_revision_title_expanded() wp-includes/post-template.php | Retrieves formatted date timestamp of a revision (linked to that revisions’s page). |
| wp_prepare_attachment_for_js() wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. |
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_edit_post_link