mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-12 19:30:38 +01:00
wp_delete_category() tweaks and code consolidation. fixes #3463
git-svn-id: http://svn.automattic.com/wordpress/trunk@4639 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5ce03d44bb
commit
448c02eed3
@ -174,29 +174,27 @@ function wp_delete_category($cat_ID) {
|
|||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$cat_ID = (int) $cat_ID;
|
$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.
|
// Don't delete either of the default cats
|
||||||
if ( $cat_ID == get_option('default_category') )
|
if ( $cat_ID == $default_cat || $cat_ID == $default_link_cat )
|
||||||
return 0;
|
|
||||||
|
|
||||||
if ( $cat_ID == get_option('default_link_category') )
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
$category = get_category($cat_ID);
|
$category = get_category($cat_ID);
|
||||||
|
|
||||||
$parent = $category->category_parent;
|
$parent = $category->category_parent;
|
||||||
|
|
||||||
// Delete the category.
|
// Delete the category
|
||||||
if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
|
if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
|
||||||
return 0;
|
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'");
|
$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.
|
// Only set posts and links to the default category if they're not in another category already
|
||||||
$default_cat = get_option('default_category');
|
|
||||||
$posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'");
|
$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);
|
$cats = wp_get_post_categories($post_id);
|
||||||
if ( 1 == count($cats) )
|
if ( 1 == count($cats) )
|
||||||
$cats = array($default_cat);
|
$cats = array($default_cat);
|
||||||
@ -205,9 +203,8 @@ function wp_delete_category($cat_ID) {
|
|||||||
wp_set_post_categories($post_id, $cats);
|
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'");
|
$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);
|
$cats = wp_get_link_cats($link_id);
|
||||||
if ( 1 == count($cats) )
|
if ( 1 == count($cats) )
|
||||||
$cats = array($default_link_cat);
|
$cats = array($default_link_cat);
|
||||||
@ -217,9 +214,7 @@ function wp_delete_category($cat_ID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clean_category_cache($cat_ID);
|
clean_category_cache($cat_ID);
|
||||||
|
|
||||||
do_action('delete_category', $cat_ID);
|
do_action('delete_category', $cat_ID);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user