Ticket #16567: 16567.4.diff
File 16567.4.diff, 2.3 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
449 449 $popular_ids = wp_popular_terms_checklist($taxonomy->name, 0, 10, false); 450 450 451 451 foreach ( $names as $cat_name ) { 452 $cat_name = trim($cat_name); 453 $category_nicename = sanitize_title($cat_name); 454 if ( '' === $category_nicename ) 452 $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 453 if ( is_wp_error( $cat_id ) && $cat_id->get_error_code() == 'term_exists' ) { 454 $cat_id = $cat_id->get_error_data(); 455 } 456 457 if ( is_wp_error( $cat_id ) || ! $cat_id ) { 455 458 continue; 456 if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) 457 $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 458 if ( is_wp_error( $cat_id ) ) { 459 continue; 460 } elseif ( is_array( $cat_id ) ) { 459 } else { 461 460 $cat_id = $cat_id['term_id']; 462 461 } 462 463 463 $checked_categories[] = $cat_id; 464 464 if ( $parent ) // Do these all at once in a second 465 465 continue; … … 774 774 * @param string $action Action to perform. 775 775 */ 776 776 function wp_ajax_add_link_category( $action ) { 777 if ( empty( $action ) ) 777 if ( empty( $action ) ) 778 778 $action = 'add-link-category'; 779 779 check_ajax_referer( $action ); 780 780 if ( !current_user_can( 'manage_categories' ) ) … … 782 782 $names = explode(',', wp_unslash( $_POST['newcat'] ) ); 783 783 $x = new WP_Ajax_Response(); 784 784 foreach ( $names as $cat_name ) { 785 $cat_name = trim($cat_name); 786 $slug = sanitize_title($cat_name); 787 if ( '' === $slug ) 785 $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 786 if ( is_wp_error( $cat_id ) && $cat_id->get_error_code() == 'term_exists' ) { 787 $cat_id = $cat_id->get_error_data(); 788 } 789 790 if ( is_wp_error( $cat_id ) || ! $cat_id ) { 788 791 continue; 789 if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) 790 $cat_id = wp_insert_term( $cat_name, 'link_category' ); 791 if ( is_wp_error( $cat_id ) ) { 792 continue; 793 } elseif ( is_array( $cat_id ) ) { 792 } else { 794 793 $cat_id = $cat_id['term_id']; 795 794 } 795 796 796 $cat_name = esc_html( $cat_name ); 797 797 $x->add( array( 798 798 'what' => 'link-category',