File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -262,15 +262,13 @@ function wp_insert_category($catarr) {
262262 $ result = $ wpdb ->query ($ query );
263263
264264 if ( $ update ) {
265- $ rval = $ wpdb ->rows_affected ;
266265 do_action ('edit_category ' , $ cat_ID );
267266 } else {
268- $ rval = $ wpdb ->insert_id ;
269267 do_action ('create_category ' , $ rval );
270268 do_action ('add_category ' , $ rval );
271269 }
272270
273- return $ rval ;
271+ return $ cat_ID ;
274272}
275273
276274function wp_update_category ($ catarr ) {
@@ -317,6 +315,19 @@ function wp_delete_category($cat_ID) {
317315 return 1 ;
318316}
319317
318+ function wp_create_category ($ cat_name ) {
319+ $ cat_array = compact ('cat_name ' );
320+ return wp_insert_category ($ cat_array );
321+ }
322+
323+ function category_exists ($ cat_name ) {
324+ global $ wpdb ;
325+ if ( !$ category_nicename = sanitize_title ($ cat_name ) )
326+ return 0 ;
327+
328+ return $ wpdb ->get_var ("SELECT cat_ID FROM $ wpdb ->categories WHERE category_nicename = ' $ category_nicename' " );
329+ }
330+
320331function wp_delete_user ($ id , $ reassign = 'novalue ' ) {
321332 global $ wpdb ;
322333
Original file line number Diff line number Diff line change 77if ( !current_user_can ('manage_categories ' ) )
88 die ('-1 ' );
99
10- function grab_id () {
11- global $ new_cat_id ;
12- $ new_cat_id = func_get_arg (0 );
13- }
14-
1510function get_out_now () { exit ; }
1611
17-
18- add_action ('edit_category ' , 'grab_id ' );
19- add_action ('create_category ' , 'grab_id ' );
2012add_action ('shutdown ' , 'get_out_now ' , -1 );
2113
2214$ cat_name = rawurldecode ($ _GET ['ajaxnewcat ' ]);
2315
2416if ( !$ category_nicename = sanitize_title ($ cat_name ) )
2517 die ('0 ' );
26- if ( $ already = $ wpdb -> get_var ( " SELECT cat_ID FROM $ wpdb -> categories WHERE category_nicename = ' $ category_nicename ' " ) )
18+ if ( $ already = category_exists ( $ cat_name ) )
2719 die ((string ) $ already );
2820
2921$ cat_name = $ wpdb ->escape ($ cat_name );
30- $ cat_array = compact ('cat_name ' , 'category_nicename ' );
31- wp_insert_category ($ cat_array );
22+ $ new_cat_id = wp_create_category ($ cat_name );
3223die ((string ) $ new_cat_id );
3324?>
You can’t perform that action at this time.
0 commit comments