Add category_exists() and wp_create_category().
git-svn-id: https://develop.svn.wordpress.org/trunk@2864 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e75196a77b
commit
cfe42dc930
@ -262,15 +262,13 @@ function wp_insert_category($catarr) {
|
||||
$result = $wpdb->query($query);
|
||||
|
||||
if ( $update ) {
|
||||
$rval = $wpdb->rows_affected;
|
||||
do_action('edit_category', $cat_ID);
|
||||
} else {
|
||||
$rval = $wpdb->insert_id;
|
||||
do_action('create_category', $rval);
|
||||
do_action('add_category', $rval);
|
||||
}
|
||||
|
||||
return $rval;
|
||||
return $cat_ID;
|
||||
}
|
||||
|
||||
function wp_update_category($catarr) {
|
||||
@ -317,6 +315,19 @@ function wp_delete_category($cat_ID) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function wp_create_category($cat_name) {
|
||||
$cat_array = compact('cat_name');
|
||||
return wp_insert_category($cat_array);
|
||||
}
|
||||
|
||||
function category_exists($cat_name) {
|
||||
global $wpdb;
|
||||
if ( !$category_nicename = sanitize_title($cat_name) )
|
||||
return 0;
|
||||
|
||||
return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
|
||||
}
|
||||
|
||||
function wp_delete_user($id, $reassign = 'novalue') {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -7,27 +7,18 @@ get_currentuserinfo();
|
||||
if ( !current_user_can('manage_categories') )
|
||||
die('-1');
|
||||
|
||||
function grab_id() {
|
||||
global $new_cat_id;
|
||||
$new_cat_id = func_get_arg(0);
|
||||
}
|
||||
|
||||
function get_out_now() { exit; }
|
||||
|
||||
|
||||
add_action('edit_category', 'grab_id');
|
||||
add_action('create_category', 'grab_id');
|
||||
add_action('shutdown', 'get_out_now', -1);
|
||||
|
||||
$cat_name = rawurldecode($_GET['ajaxnewcat']);
|
||||
|
||||
if ( !$category_nicename = sanitize_title($cat_name) )
|
||||
die('0');
|
||||
if ( $already = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'") )
|
||||
if ( $already = category_exists($cat_name) )
|
||||
die((string) $already);
|
||||
|
||||
$cat_name = $wpdb->escape($cat_name);
|
||||
$cat_array = compact('cat_name', 'category_nicename');
|
||||
wp_insert_category($cat_array);
|
||||
$new_cat_id = wp_create_category($cat_name);
|
||||
die((string) $new_cat_id);
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user