summaryrefslogtreecommitdiffstats
path: root/wp-admin/admin-db.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-admin/admin-db.php')
-rw-r--r--wp-admin/admin-db.php38
1 files changed, 16 insertions, 22 deletions
diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php
index 27c422f..40b4556 100644
--- a/wp-admin/admin-db.php
+++ b/wp-admin/admin-db.php
@@ -138,17 +138,19 @@ function wp_insert_category($catarr) {
$wpdb->query( "UPDATE $wpdb->categories SET category_nicename = '$category_nicename' WHERE cat_ID = '$cat_ID'" );
}
- wp_cache_delete($cat_ID, 'category');
- wp_cache_delete('get_categories', 'category');
+ // Keep in mind when using this filter and altering the cat_ID that the two queries above
+ // have already taken place with the OLD cat_ID
+ // Also note that you may have post2cat entries with the old cat_ID if this is an update
+ $cat_ID = apply_filters('cat_id_filter', $cat_ID, $update);
+
+ clean_category_cache($cat_ID);
if ($update) {
do_action('edit_category', $cat_ID);
} else {
- wp_cache_delete('all_category_ids', 'category');
do_action('create_category', $cat_ID);
do_action('add_category', $cat_ID);
}
- $cat_ID = apply_filters( "cat_id_filter", $cat_ID );
return $cat_ID;
}
@@ -177,29 +179,27 @@ function wp_delete_category($cat_ID) {
global $wpdb;
$cat_ID = (int) $cat_ID;
+ $default_cat = get_option('default_category');
+ $default_link_cat = get_option('default_link_category');
- // Don't delete the default cat.
- if ( $cat_ID == get_option('default_category') )
- return 0;
-
- if ( $cat_ID == get_option('default_link_category') )
+ // Don't delete either of the default cats
+ if ( $cat_ID == $default_cat || $cat_ID == $default_link_cat )
return 0;
$category = get_category($cat_ID);
$parent = $category->category_parent;
- // Delete the category.
+ // Delete the category
if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
return 0;
- // Update children to point to new parent.
+ // Update children to point to new parent
$wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
- // Only set posts and links to the default category if they're not in another category already.
- $default_cat = get_option('default_category');
+ // Only set posts and links to the default category if they're not in another category already
$posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'");
- if ( is_array($posts) ) foreach ($posts as $post_id) {
+ foreach ( (array) $posts as $post_id ) {
$cats = wp_get_post_categories($post_id);
if ( 1 == count($cats) )
$cats = array($default_cat);
@@ -208,9 +208,8 @@ function wp_delete_category($cat_ID) {
wp_set_post_categories($post_id, $cats);
}
- $default_link_cat = get_option('default_link_category');
$links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'");
- if ( is_array($links) ) foreach ($links as $link_id) {
+ foreach ( (array) $links as $link_id ) {
$cats = wp_get_link_cats($link_id);
if ( 1 == count($cats) )
$cats = array($default_link_cat);
@@ -219,12 +218,8 @@ function wp_delete_category($cat_ID) {
wp_set_link_cats($link_id, $cats);
}
- wp_cache_delete($cat_ID, 'category');
- wp_cache_delete('all_category_ids', 'category');
- wp_cache_delete('get_categories', 'category');
-
+ clean_category_cache($cat_ID);
do_action('delete_category', $cat_ID);
-
return 1;
}
@@ -492,7 +487,6 @@ function wp_set_link_cats($link_ID = 0, $link_categories = array()) {
do_action('edit_category', $cat_id);
}
- do_action('edit_link', $link_ID);
} // wp_set_link_cats()
function post_exists($title, $content = '', $post_date = '') {