diff --git a/wp-admin/includes/bookmark.php b/wp-admin/includes/bookmark.php
index e1298abe45..4201d355a3 100644
--- a/wp-admin/includes/bookmark.php
+++ b/wp-admin/includes/bookmark.php
@@ -51,6 +51,8 @@ function wp_delete_link($link_id) {
do_action('deleted_link', $link_id);
+ clean_bookmark_cache($link_id);
+
return true;
}
@@ -65,7 +67,7 @@ function get_link_to_edit( $link_id ) {
return get_bookmark( $link_id, OBJECT, 'edit' );
}
-function wp_insert_link($linkdata) {
+function wp_insert_link($linkdata, $wp_error = false) {
global $wpdb, $current_user;
$defaults = array('link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 );
@@ -119,14 +121,24 @@ function wp_insert_link($linkdata) {
}
if ( $update ) {
- $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_url = %s,
+ if ( false === $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_url = %s,
link_name = %s, link_image = %s, link_target = %s,
link_visible = %s, link_description = %s, link_rating = %s,
link_rel = %s, link_notes = %s, link_rss = %s
- WHERE link_id = %s", $link_url, $link_name, $link_image, $link_target, $link_visible, $link_description, $link_rating, $link_rel, $link_notes, $link_rss, $link_id) );
+ WHERE link_id = %s", $link_url, $link_name, $link_image, $link_target, $link_visible, $link_description, $link_rating, $link_rel, $link_notes, $link_rss, $link_id) ) ) {
+ if ( $wp_error )
+ return new WP_Error('db_update_error', __('Could not update link in the database'), $wpdb->last_error);
+ else
+ return 0;
+ }
} else {
- $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
- $link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss) );
+ if ( false === $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
+ $link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss) ) ) {
+ if ( $wp_error )
+ return new WP_Error('db_insert_error', __('Could not insert link into the database'), $wpdb->last_error);
+ else
+ return 0;
+ }
$link_id = (int) $wpdb->insert_id;
}
@@ -137,6 +149,8 @@ function wp_insert_link($linkdata) {
else
do_action('add_link', $link_id);
+ clean_bookmark_cache($link_id);
+
return $link_id;
}
@@ -149,6 +163,8 @@ function wp_set_link_cats($link_id = 0, $link_categories = array()) {
$link_categories = array_unique($link_categories);
wp_set_object_terms($link_id, $link_categories, 'link_category');
+
+ clean_bookmark_cache($link_id);
} // wp_set_link_cats()
function wp_update_link($linkdata) {
diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php
index fe7c123903..30e19a66a4 100644
--- a/wp-admin/link-manager.php
+++ b/wp-admin/link-manager.php
@@ -163,7 +163,7 @@ if ( $links ) {
35)
$short_url = substr($short_url, 0, 32).'...';
-
$visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
- ++ $i;
- $style = ($i % 2) ? '' : ' class="alternate"';
+ $style = ($alt % 2) ? '' : ' class="alternate"';
+ ++ $alt;
+ $edit_link = get_edit_bookmark_link();
?>>';
foreach($link_columns as $column_name=>$column_display_name) {
switch($column_name) {
case 'name':
- echo "link_name)) . "' class='edit'>$link->link_name ";
- echo $link->link_description . " | ";
+ echo "link_name)) . "' class='edit'>$link->link_name ";
+ $actions = array();
+ $actions['edit'] = '' . __('Edit') . '';
+ $actions['delete'] = "link_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf( __("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name )) . "') ) { return true;}return false;\">" . __('Delete') . "";
+ $action_count = count($actions);
+ $i = 0;
+ foreach ( $actions as $action => $link ) {
+ ++$i;
+ ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
+ echo "$link$sep";
+ }
+ echo ' | ';
break;
case 'url':
echo "link_name)."'>$short_url | ";
diff --git a/wp-includes/bookmark.php b/wp-includes/bookmark.php
index 03999cb154..c16721d9f8 100644
--- a/wp-includes/bookmark.php
+++ b/wp-includes/bookmark.php
@@ -17,22 +17,37 @@
* @param string $filter Optional, default is 'raw'.
* @return array|object Type returned depends on $output value.
*/
-function get_bookmark($bookmark_id, $output = OBJECT, $filter = 'raw') {
+function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') {
global $wpdb;
- $link = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark_id));
- $link->link_category = array_unique( wp_get_object_terms($link->link_id, 'link_category', 'fields=ids') );
+ if ( empty($bookmark) ) {
+ if ( isset($GLOBALS['link']) )
+ $_bookmark = & $GLOBALS['link'];
+ else
+ $_bookmark = null;
+ } elseif ( is_object($bookmark) ) {
+ wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');
+ $_bookmark = $bookmark;
+ } else {
+ if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $link) ) {
+ $_bookmark = & $GLOBALS['link'];
+ } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) {
+ $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark));
+ $_bookmark->link_category = array_unique( wp_get_object_terms($_bookmark->link_id, 'link_category', 'fields=ids') );
+ wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark');
+ }
+ }
- $link = sanitize_bookmark($link, $filter);
+ $_bookmark = sanitize_bookmark($_bookmark, $filter);
if ( $output == OBJECT ) {
- return $link;
+ return $_bookmark;
} elseif ( $output == ARRAY_A ) {
- return get_object_vars($link);
+ return get_object_vars($_bookmark);
} elseif ( $output == ARRAY_N ) {
- return array_values(get_object_vars($link));
+ return array_values(get_object_vars($_bookmark));
} else {
- return $link;
+ return $_bookmark;
}
}
@@ -331,16 +346,14 @@ function sanitize_bookmark_field($field, $value, $bookmark_id, $context) {
}
/**
- * Deletes entire bookmark cache
+ * Deletes bookmark cache
*
- * @since 2.1.0
+ * @since 2.7.0
* @uses wp_cache_delete() Deletes the contents of 'get_bookmarks'
*/
-function delete_get_bookmark_cache() {
+function clean_bookmark_cache($bookmark_id) {
+ wp_cache_delete( $bookmark_id, 'bookmark' );
wp_cache_delete( 'get_bookmarks', 'bookmark' );
}
-add_action( 'add_link', 'delete_get_bookmark_cache' );
-add_action( 'edit_link', 'delete_get_bookmark_cache' );
-add_action( 'delete_link', 'delete_get_bookmark_cache' );
?>
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index a5c9b33fc5..5052fb0a1a 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -547,6 +547,29 @@ function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
}
+function get_edit_bookmark_link( $link = 0 ) {
+ $link = &get_bookmark( $link );
+
+ if ( !current_user_can('manage_links') )
+ return;
+
+ $location = admin_url('link.php?action=edit&link_id=') . $link->link_id;
+ return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
+}
+
+function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
+ $bookmark = get_bookmark($bookmark);
+
+ if ( !current_user_can('manage_links') )
+ return;
+
+ if ( empty($link) )
+ $link = __('Edit This');
+
+ $link = '' . $link . '';
+ echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
+}
+
// Navigation links
function get_previous_post($in_same_cat = false, $excluded_categories = '') {