File: edit-form-ajax-cat.php

package info (click to toggle)
wordpress 2.0.10-1etch6
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,040 kB
  • ctags: 7,377
  • sloc: php: 26,382; sh: 4,645; makefile: 23
file content (37 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require_once('../wp-config.php');
require_once('admin-functions.php');
require_once('admin-db.php');

if ( !current_user_can('manage_categories') )
	die('-1');
if ( !check_ajax_referer() )
	die('-1');

function get_out_now() { exit; }

add_action('shutdown', 'get_out_now', -1);

$names = explode(',', rawurldecode($_POST['ajaxnewcat']) );
$ids   = array();

foreach ($names as $cat_name) {
	$cat_name = trim( $cat_name );
	
	if ( !$category_nicename = sanitize_title($cat_name) )
		continue;
	if ( $already = category_exists($cat_name) ) {
		$ids[] = (string) $already;
		continue;
	}
	
	$new_cat_id = wp_create_category($cat_name);
	
	$ids[] = (string) $new_cat_id;
}

$return = join(',', $ids);

die( (string) $return );

?>