From 32e3266afb833256418ab1883213d74525280fae Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 10 Sep 2005 22:45:07 +0000 Subject: [PATCH] Add post_exists() and wp_create_categories(). git-svn-id: https://develop.svn.wordpress.org/trunk@2866 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 03e54eee49..bb4ba32fd5 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);