{"pageProps":{"title":"edit_link()","titleType":"Function","type":"functions","content":"

edit_link() WordPress Function

The edit_link() function is used to get the edit link for a post. This function is typically used when displaying the edit link for a post in the frontend.

edit_link( int $link_id ) #

Updates or inserts a link using values provided in $_POST.


Parameters

$link_id

(int)(Optional) ID of the link to edit. Default 0.


Top ↑

Return

(int|WP_Error) Value 0 or WP_Error on failure. The link ID on success.


Top ↑

Source

File: wp-admin/includes/bookmark.php

function edit_link( $link_id = 0 ) {\n\tif ( ! current_user_can( 'manage_links' ) ) {\n\t\twp_die(\n\t\t\t'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .\n\t\t\t'<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>',\n\t\t\t403\n\t\t);\n\t}\n\n\t$_POST['link_url']   = esc_html( $_POST['link_url'] );\n\t$_POST['link_url']   = esc_url( $_POST['link_url'] );\n\t$_POST['link_name']  = esc_html( $_POST['link_name'] );\n\t$_POST['link_image'] = esc_html( $_POST['link_image'] );\n\t$_POST['link_rss']   = esc_url( $_POST['link_rss'] );\n\tif ( ! isset( $_POST['link_visible'] ) || 'N' !== $_POST['link_visible'] ) {\n\t\t$_POST['link_visible'] = 'Y';\n\t}\n\n\tif ( ! empty( $link_id ) ) {\n\t\t$_POST['link_id'] = $link_id;\n\t\treturn wp_update_link( $_POST );\n\t} else {\n\t\treturn wp_insert_link( $_POST );\n\t}\n}\n

Expand full source codeCollapse full source codeView on TracView on GitHub


Top ↑

Related

Top ↑

Uses

Uses
UsesDescription
wp-admin/includes/bookmark.php:wp_update_link()

Updates a link in the database.

wp-admin/includes/bookmark.php:wp_insert_link()

Inserts a link into the database, or updates an existing link.

wp-includes/capabilities.php:current_user_can()

Returns whether the current user has the specified capability.

wp-includes/l10n.php:__()

Retrieve the translation of $text.

wp-includes/formatting.php:esc_html()

Escaping for HTML blocks.

wp-includes/formatting.php:esc_url()

Checks and cleans a URL.

wp-includes/functions.php:wp_die()

Kills WordPress execution and displays HTML page with an error message.

Show 2 more usesHide more uses

Top ↑

Used By

Used By
Used ByDescription
wp-admin/includes/bookmark.php:add_link()

Add a link to using values provided in $_POST.


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.
","description":"Updates or inserts a link using values provided in $_POST.","sidebarFiles":{"Hook":[{"componentTitle":"add_link","componentLink":"/reference/hooks/add_link","private":"","deprecated":""},{"componentTitle":"delete_link","componentLink":"/reference/hooks/delete_link","private":"","deprecated":""},{"componentTitle":"deleted_link","componentLink":"/reference/hooks/deleted_link","private":"","deprecated":""},{"componentTitle":"edit_link","componentLink":"/reference/hooks/edit_link","private":"","deprecated":""}],"Function":[{"componentTitle":"add_link()","componentLink":"/reference/functions/add_link","private":"","deprecated":""},{"componentTitle":"edit_link()","componentLink":"/reference/functions/edit_link","private":"","deprecated":"","active":"active"},{"componentTitle":"get_default_link_to_edit()","componentLink":"/reference/functions/get_default_link_to_edit","private":"","deprecated":""},{"componentTitle":"get_link_to_edit()","componentLink":"/reference/functions/get_link_to_edit","private":"","deprecated":""},{"componentTitle":"wp_delete_link()","componentLink":"/reference/functions/wp_delete_link","private":"","deprecated":""},{"componentTitle":"wp_get_link_cats()","componentLink":"/reference/functions/wp_get_link_cats","private":"","deprecated":""},{"componentTitle":"wp_insert_link()","componentLink":"/reference/functions/wp_insert_link","private":"","deprecated":""},{"componentTitle":"wp_link_manager_disabled_message()","componentLink":"/reference/functions/wp_link_manager_disabled_message","private":"private","deprecated":""},{"componentTitle":"wp_set_link_cats()","componentLink":"/reference/functions/wp_set_link_cats","private":"","deprecated":""},{"componentTitle":"wp_update_link()","componentLink":"/reference/functions/wp_update_link","private":"","deprecated":""}]}},"__N_SSG":true}