Wordpress/wp-admin/edit-form-ajax-cat.php

29 lines
745 B
PHP
Raw Normal View History

<?php
require_once('../wp-config.php');
require_once('admin-functions.php');
get_currentuserinfo();
if ( !current_user_can('manage_categories') )
die('-1');
function grab_id() {
global $new_cat_id;
$new_cat_id = func_get_arg(0);
}
add_action('edit_category', 'grab_id');
add_action('create_category', 'grab_id');
$cat_name = stripslashes($_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'") )
die($already);
$cat_name = $wpdb->escape($cat_name);
$cat_array = compact('cat_name', 'category_nicename');
wp_insert_category($cat_array);
echo $new_cat_id;
?>