Ticket #4147: api-functions.diff

File api-functions.diff, 2.8 KB (added by rob1n, 5 years ago)
  • wp-admin/admin-db.php

     
    213213        // Update children to point to new parent 
    214214        $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 
    215215 
    216         // Only set posts and links to the default category if they're not in another category already 
     216        // Only set posts links to the default category if they're not in another category already 
    217217        $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID' AND rel_type = 'category'"); 
    218218        foreach ( (array) $posts as $post_id ) { 
    219219                $cats = wp_get_post_categories($post_id); 
     
    224224                wp_set_post_categories($post_id, $cats); 
    225225        } 
    226226 
    227         $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'"); 
     227        clean_category_cache($cat_ID); 
     228        do_action('delete_category', $cat_ID); 
     229        return 1; 
     230} 
     231 
     232function wp_create_category($cat_name) { 
     233        $cat_array = compact('cat_name'); 
     234        return wp_insert_category($cat_array); 
     235} 
     236 
     237function wp_create_link_category($cat_name) { 
     238        $type = TAXONOMY_LINK_CATEGORY; 
     239        $cat_array = compact('cat_name', 'type'); 
     240        return wp_insert_category($cat_array); 
     241} 
     242 
     243function wp_delete_link_category($cat_ID) { 
     244        global $wpdb; 
     245 
     246        $cat_ID = (int) $cat_ID; 
     247        $default_link_cat = get_option('default_link_category'); 
     248 
     249        // Don't delete either of the default cats 
     250        if ( $cat_ID == $default_link_cat ) 
     251                return 0; 
     252 
     253        $category = get_category($cat_ID); 
     254        $parent = $category->category_parent; 
     255 
     256        // Delete the category if it is not also a tag or regular category. 
     257        if ( 0 == ($category->type & TAXONOMY_TAG) || 0 == ($category->type & TAXONOMY_CATEGORY) ) { 
     258                if ($wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'")) { 
     259                        // Update children to point to new parent 
     260                        $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 
     261                } else { 
     262                        return false; 
     263                } 
     264        } else { 
     265                $wpdb->query("UPDATE $wpdb->categories SET type = type & ~" . TAXONOMY_LINK_CATEGORY . " WHERE cat_ID = '$cat_ID'"); 
     266        } 
     267         
     268        // Only set links to the default category if they're not in another category already 
     269        $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id = '$cat_ID'"); 
    228270        foreach ( (array) $links as $link_id ) { 
    229271                $cats = wp_get_link_cats($link_id); 
    230272                if ( 1 == count($cats) ) 
     
    236278 
    237279        clean_category_cache($cat_ID); 
    238280        do_action('delete_category', $cat_ID); 
    239         return 1; 
     281         
     282        return true; 
    240283} 
    241284 
    242 function wp_create_category($cat_name) { 
    243         $cat_array = compact('cat_name'); 
    244         return wp_insert_category($cat_array); 
    245 } 
    246  
    247285function wp_create_categories($categories, $post_id = '') { 
    248286        $cat_ids = array (); 
    249287        foreach ($categories as $category) {