From a8146c05238a254990a96097d480b81f0d807a24 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 10 Sep 2005 22:45:07 +0000 Subject: [PATCH] Add post_exists() and wp_create_categories(). git-svn-id: http://svn.automattic.com/wordpress/trunk@2866 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-functions.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 03e54eee4..bb4ba32fd 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -320,6 +320,22 @@ function wp_create_category($cat_name) { return wp_insert_category($cat_array); } + +function wp_create_categories($categories, $post_id = '') { + $cat_ids = array(); + foreach ($categories as $category) { + if ( $id = category_exists($category) ) + $cat_ids[] = $id; + else if ( $id = wp_create_category($category) ) + $cat_ids[] = $id; + } + + if ( $post_id ) + wp_set_post_cats('', $post_id, $cat_ids); + + return $cat_ids; +} + function category_exists($cat_name) { global $wpdb; if ( !$category_nicename = sanitize_title($cat_name) ) @@ -365,6 +381,21 @@ function wp_delete_user($id, $reassign = 'novalue') { return true; } + +function post_exists($title, $content = '', $post_date = '') { + global $wpdb; + + if ( !empty($post_date) ) + $post_date = "AND post_date = '$post_date'"; + + if ( ! empty($title) ) + return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' $post_date"); + else if ( ! empty($content) ) + return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date"); + + return 0; +} + function url_shorten ($url) { $short_url = str_replace('http://', '', stripslashes($url)); $short_url = str_replace('www.', '', $short_url);