diff options
Diffstat (limited to 'wp-admin/admin-db.php')
-rw-r--r-- | wp-admin/admin-db.php | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php index b41891f..ea6e60d 100644 --- a/wp-admin/admin-db.php +++ b/wp-admin/admin-db.php @@ -48,7 +48,7 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true ) { if ( ! $user->has_cap('edit_others_posts') ) { if ( $user->has_cap('edit_posts') || $exclude_zeros == false ) return array($user->id); - else + else return false; } @@ -157,6 +157,9 @@ function wp_update_category($catarr) { $cat_ID = (int) $catarr['cat_ID']; + if( $cat_ID == $catarr['category_parent'] ) + return false; + // First, get all of the original fields $category = get_category($cat_ID, ARRAY_A); @@ -201,7 +204,7 @@ function wp_delete_category($cat_ID) { $cats = array($default_cat); else $cats = array_diff($cats, array($cat_ID)); - wp_set_post_categories($post_id, $cats); + wp_set_post_categories($post_id, $cats); } $default_link_cat = get_option('default_link_category'); @@ -212,9 +215,9 @@ function wp_delete_category($cat_ID) { $cats = array($default_link_cat); else $cats = array_diff($cats, array($cat_ID)); - wp_set_link_cats($link_id, $cats); + wp_set_link_cats($link_id, $cats); } - + wp_cache_delete($cat_ID, 'category'); wp_cache_delete('all_category_ids', 'category'); @@ -287,9 +290,9 @@ function wp_delete_user($id, $reassign = 'novalue') { function wp_revoke_user($id) { $id = (int) $id; - + $user = new WP_User($id); - $user->remove_all_caps(); + $user->remove_all_caps(); } function wp_insert_link($linkdata) { @@ -387,15 +390,15 @@ function wp_update_link($linkdata) { $link = add_magic_quotes($link); // Passed link category list overwrites existing category list if not empty. - if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) + if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) && 0 != count($linkdata['link_category']) ) - $link_cats = $linkdata['link_category']; - else - $link_cats = $link['link_category']; + $link_cats = $linkdata['link_category']; + else + $link_cats = $link['link_category']; // Merge old and new fields with new fields overwriting old ones. $linkdata = array_merge($link, $linkdata); - $linkdata['link_category'] = $link_cats; + $linkdata['link_category'] = $link_cats; return wp_insert_link($linkdata); } @@ -404,7 +407,7 @@ function wp_delete_link($link_id) { global $wpdb; do_action('delete_link', $link_id); - + $categories = wp_get_link_cats($link_id); if( is_array( $categories ) ) { foreach ( $categories as $category ) { @@ -420,9 +423,9 @@ function wp_delete_link($link_id) { function wp_get_link_cats($link_ID = 0) { global $wpdb; - $sql = "SELECT category_id - FROM $wpdb->link2cat - WHERE link_id = $link_ID + $sql = "SELECT category_id + FROM $wpdb->link2cat + WHERE link_id = $link_ID ORDER BY category_id"; $result = $wpdb->get_col($sql); @@ -443,8 +446,8 @@ function wp_set_link_cats($link_ID = 0, $link_categories = array()) { // First the old categories $old_categories = $wpdb->get_col(" - SELECT category_id - FROM $wpdb->link2cat + SELECT category_id + FROM $wpdb->link2cat WHERE link_id = $link_ID"); if (!$old_categories) { @@ -459,9 +462,9 @@ function wp_set_link_cats($link_ID = 0, $link_categories = array()) { if ($delete_cats) { foreach ($delete_cats as $del) { $wpdb->query(" - DELETE FROM $wpdb->link2cat - WHERE category_id = $del - AND link_id = $link_ID + DELETE FROM $wpdb->link2cat + WHERE category_id = $del + AND link_id = $link_ID "); } } @@ -472,18 +475,21 @@ function wp_set_link_cats($link_ID = 0, $link_categories = array()) { if ($add_cats) { foreach ($add_cats as $new_cat) { $wpdb->query(" - INSERT INTO $wpdb->link2cat (link_id, category_id) + INSERT INTO $wpdb->link2cat (link_id, category_id) VALUES ($link_ID, $new_cat)"); } } - + // Update category counts. $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); foreach ( $all_affected_cats as $cat_id ) { $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'"); $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); wp_cache_delete($cat_id, 'category'); + do_action('edit_category', $cat_id); } + + do_action('edit_link', $link_ID); } // wp_set_link_cats() function post_exists($title, $content = '', $post_date = '') { |