| 537 | // Add custom taxonomies. |
| 538 | $taxs= get_object_taxonomies('post'); |
| 539 | foreach($taxs as $ta) { |
| 540 | if(($ta == 'post_tag') || ($ta == 'category')) continue; |
| 541 | |
| 542 | $patt = '|<category domain="'. $ta.'" nicename="[^"]+">(.*?)</category>|is'; |
| 543 | preg_match_all("'".$patt."'", $post, $tags2); |
| 544 | $tags2 = $tags2[1]; |
| 545 | |
| 546 | $tag_index2 = 0; |
| 547 | foreach ($tags2 as $tag2) { |
| 548 | $tags2[$tag_index2] = $wpdb->escape( html_entity_decode( str_replace(array( '<![CDATA[', ']]>' ), '', $tag2 ) ) ); |
| 549 | $tag_index2++; |
| 550 | } |
| 551 | |
| 552 | if (count($tags2) > 0) { |
| 553 | $post_tags = array(); |
| 554 | foreach ($tags2 as $tag) { |
| 555 | if ( '' == $tag ) |
| 556 | continue; |
| 557 | $slug = sanitize_term_field('slug', $tag, 0, $ta, 'db'); |
| 558 | $tag_obj = get_term_by('slug', $slug, $ta); |
| 559 | $tag_id = 0; |
| 560 | if ( ! empty($tag_obj) ) |
| 561 | $tag_id = $tag_obj->term_id; |
| 562 | if ( $tag_id == 0 ) { |
| 563 | $tag = $wpdb->escape($tag); |
| 564 | $tag_id = wp_insert_term($tag, $ta); |
| 565 | if ( is_wp_error($tag_id) ) |
| 566 | continue; |
| 567 | $tag_id = $tag_id['term_id']; |
| 568 | } |
| 569 | $post_tags[] = intval($tag_id); |
| 570 | } |
| 571 | wp_set_post_terms($post_id, $post_tags, $ta, true); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | |