Deprecate wp_get/set_post_cats() in favor of wp_get/set_post_categories().

git-svn-id: http://svn.automattic.com/wordpress/trunk@3849 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-06-06 05:04:41 +00:00
parent db3a022631
commit 0585475e02
4 changed files with 26 additions and 18 deletions

View File

@ -187,12 +187,12 @@ function wp_delete_category($cat_ID) {
$default_cat = get_option('default_category'); $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) { if ( is_array($posts) ) foreach ($posts as $post_id) {
$cats = wp_get_post_cats('', $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);
else else
$cats = array_diff($cats, array($cat_ID)); $cats = array_diff($cats, array($cat_ID));
wp_set_post_cats('', $post_id, $cats); wp_set_post_categories($post_id, $cats);
} }
$default_link_cat = get_option('default_link_category'); $default_link_cat = get_option('default_link_category');
@ -230,7 +230,7 @@ function wp_create_categories($categories, $post_id = '') {
} }
if ($post_id) if ($post_id)
wp_set_post_cats('', $post_id, $cat_ids); wp_set_post_categories($post_id, $cat_ids);
return $cat_ids; return $cat_ids;
} }

View File

@ -462,4 +462,12 @@ function list_authors($optioncount = false, $exclude_admin = true, $show_fullnam
return wp_list_authors($args); return wp_list_authors($args);
} }
function wp_get_post_cats($blogid = '1', $post_ID = 0) {
return wp_get_post_categories($post_ID);
}
function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
return wp_set_post_categories($post_ID, $post_categories);
}
?> ?>

View File

@ -161,7 +161,7 @@ function wp_insert_post($postarr = array()) {
$wpdb->query( "UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = '$post_ID'" ); $wpdb->query( "UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = '$post_ID'" );
} }
wp_set_post_cats('', $post_ID, $post_category); wp_set_post_categories($post_ID, $post_category);
if ( 'page' == $post_type ) { if ( 'page' == $post_type ) {
clean_page_cache($post_ID); clean_page_cache($post_ID);
@ -348,7 +348,7 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) {
$wpdb->query( "UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = '$post_ID'" ); $wpdb->query( "UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = '$post_ID'" );
} }
wp_set_post_cats('', $post_ID, $post_category); wp_set_post_categories($post_ID, $post_category);
if ( $file ) if ( $file )
add_post_meta($post_ID, '_wp_attached_file', $file ); add_post_meta($post_ID, '_wp_attached_file', $file );
@ -411,10 +411,10 @@ function wp_get_single_post($postid = 0, $mode = OBJECT) {
// Set categories // Set categories
if($mode == OBJECT) { if($mode == OBJECT) {
$post->post_category = wp_get_post_cats('',$postid); $post->post_category = wp_get_post_categories($postid);
} }
else { else {
$post['post_category'] = wp_get_post_cats('',$postid); $post['post_category'] = wp_get_post_categories($postid);
} }
return $post; return $post;
@ -486,7 +486,7 @@ function wp_publish_post($post_id) {
return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id)); return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id));
} }
function wp_get_post_cats($blogid = '1', $post_ID = 0) { function wp_get_post_categories($post_ID = 0) {
global $wpdb; global $wpdb;
$post_ID = (int) $post_ID; $post_ID = (int) $post_ID;
@ -504,7 +504,7 @@ function wp_get_post_cats($blogid = '1', $post_ID = 0) {
return array_unique($result); return array_unique($result);
} }
function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) { function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
global $wpdb; global $wpdb;
// If $post_categories isn't already an array, make it one: // If $post_categories isn't already an array, make it one:
if (!is_array($post_categories) || 0 == count($post_categories)) if (!is_array($post_categories) || 0 == count($post_categories))
@ -555,7 +555,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'"); $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
wp_cache_delete($cat_id, 'category'); wp_cache_delete($cat_id, 'category');
} }
} // wp_set_post_cats() } // wp_set_post_categories()
function wp_delete_post($postid = 0) { function wp_delete_post($postid = 0) {
global $wpdb, $wp_rewrite; global $wpdb, $wp_rewrite;
@ -570,7 +570,7 @@ function wp_delete_post($postid = 0) {
do_action('delete_post', $postid); do_action('delete_post', $postid);
if ( 'publish' == $post->post_status && 'post' == $post->post_type ) { if ( 'publish' == $post->post_status && 'post' == $post->post_type ) {
$categories = wp_get_post_cats('', $post->ID); $categories = wp_get_post_categories($post->ID);
if( is_array( $categories ) ) { if( is_array( $categories ) ) {
foreach ( $categories as $cat_id ) { foreach ( $categories as $cat_id ) {
$wpdb->query("UPDATE $wpdb->categories SET category_count = category_count - 1 WHERE cat_ID = '$cat_id'"); $wpdb->query("UPDATE $wpdb->categories SET category_count = category_count - 1 WHERE cat_ID = '$cat_id'");

View File

@ -242,7 +242,7 @@ class wp_xmlrpc_server extends IXR_Server {
$user_data = get_userdatabylogin($user_login); $user_data = get_userdatabylogin($user_login);
$post_data = wp_get_single_post($post_ID, ARRAY_A); $post_data = wp_get_single_post($post_ID, ARRAY_A);
$categories = implode(',', wp_get_post_cats(1, $post_ID)); $categories = implode(',', wp_get_post_categories($post_ID));
$content = '<title>'.stripslashes($post_data['post_title']).'</title>'; $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
$content .= '<category>'.$categories.'</category>'; $content .= '<category>'.$categories.'</category>';
@ -285,7 +285,7 @@ class wp_xmlrpc_server extends IXR_Server {
foreach ($posts_list as $entry) { foreach ($posts_list as $entry) {
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
$categories = implode(',', wp_get_post_cats(1, $entry['ID'])); $categories = implode(',', wp_get_post_categories($entry['ID']));
$content = '<title>'.stripslashes($entry['post_title']).'</title>'; $content = '<title>'.stripslashes($entry['post_title']).'</title>';
$content .= '<category>'.$categories.'</category>'; $content .= '<category>'.$categories.'</category>';
@ -695,7 +695,7 @@ class wp_xmlrpc_server extends IXR_Server {
$post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']); $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
$categories = array(); $categories = array();
$catids = wp_get_post_cats('', $post_ID); $catids = wp_get_post_categories($post_ID);
foreach($catids as $catid) { foreach($catids as $catid) {
$categories[] = get_cat_name($catid); $categories[] = get_cat_name($catid);
} }
@ -755,7 +755,7 @@ class wp_xmlrpc_server extends IXR_Server {
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
$categories = array(); $categories = array();
$catids = wp_get_post_cats('', $entry['ID']); $catids = wp_get_post_categories($entry['ID']);
foreach($catids as $catid) { foreach($catids as $catid) {
$categories[] = get_cat_name($catid); $categories[] = get_cat_name($catid);
} }
@ -958,7 +958,7 @@ class wp_xmlrpc_server extends IXR_Server {
} }
$categories = array(); $categories = array();
$catids = wp_get_post_cats('', intval($post_ID)); $catids = wp_get_post_categories(intval($post_ID));
// first listed category will be the primary category // first listed category will be the primary category
$isPrimary = true; $isPrimary = true;
foreach($catids as $catid) { foreach($catids as $catid) {
@ -996,7 +996,7 @@ class wp_xmlrpc_server extends IXR_Server {
$catids[] = $cat['categoryId']; $catids[] = $cat['categoryId'];
} }
wp_set_post_cats('', $post_ID, $catids); wp_set_post_categories($post_ID, $catids);
return true; return true;
} }
@ -1079,7 +1079,7 @@ class wp_xmlrpc_server extends IXR_Server {
$postdata['post_status'] = 'publish'; $postdata['post_status'] = 'publish';
// retain old cats // retain old cats
$cats = wp_get_post_cats('',$post_ID); $cats = wp_get_post_categories($post_ID);
$postdata['post_category'] = $cats; $postdata['post_category'] = $cats;
$this->escape($postdata); $this->escape($postdata);