Changeset 5523 for trunk/wp-admin/admin-db.php
- Timestamp:
- 05/23/2007 07:15:10 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-db.php
r5522 r5523 464 464 } 465 465 466 function wp_get_link_cats($link_ID = 0) { 467 global $wpdb; 468 469 $sql = "SELECT category_id 470 FROM $wpdb->link2cat 471 WHERE link_id = $link_ID 472 ORDER BY category_id"; 473 474 $result = $wpdb->get_col($sql); 475 476 if ( !$result ) 477 $result = array(); 478 479 return array_unique($result); 480 } 481 482 function wp_set_link_cats($link_ID = 0, $link_categories = array()) { 483 global $wpdb; 466 function wp_get_link_cats($link_id = 0) { 467 468 $cats = get_object_terms($link_id, 'link_category', 'get=ids'); 469 470 return array_unique($cats); 471 } 472 473 function wp_set_link_cats($link_id = 0, $link_categories = array()) { 484 474 // If $link_categories isn't already an array, make it one: 485 475 if (!is_array($link_categories) || 0 == count($link_categories)) 486 476 $link_categories = array(get_option('default_link_category')); 487 477 478 $link_categories = array_map('intval', $link_categories); 488 479 $link_categories = array_unique($link_categories); 489 480 490 // First the old categories 491 $old_categories = $wpdb->get_col(" 492 SELECT category_id 493 FROM $wpdb->link2cat 494 WHERE link_id = '$link_ID'"); 495 496 if (!$old_categories) { 497 $old_categories = array(); 498 } else { 499 $old_categories = array_unique($old_categories); 500 } 501 502 // Delete any? 503 $delete_cats = array_diff($old_categories,$link_categories); 504 505 if ($delete_cats) { 506 foreach ($delete_cats as $del) { 507 $del = (int) $del; 508 $wpdb->query(" 509 DELETE FROM $wpdb->link2cat 510 WHERE category_id = '$del' 511 AND link_id = '$link_ID' 512 "); 513 } 514 } 515 516 // Add any? 517 $add_cats = array_diff($link_categories, $old_categories); 518 519 if ($add_cats) { 520 foreach ($add_cats as $new_cat) { 521 $new_cat = (int) $new_cat; 522 if ( !empty($new_cat) ) 523 $wpdb->query(" 524 INSERT INTO $wpdb->link2cat (link_id, category_id) 525 VALUES ('$link_ID', '$new_cat')"); 526 } 527 } 528 529 // Update category counts. 530 $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); 531 foreach ( $all_affected_cats as $cat_id ) { 532 $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'"); 533 $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); 534 wp_cache_delete($cat_id, 'category'); 535 do_action('edit_category', $cat_id); 536 } 537 481 wp_set_object_terms($link_id, $link_categories, 'link_category'); 538 482 } // wp_set_link_cats() 539 483
Note: See TracChangeset
for help on using the changeset viewer.