@@ -1805,8 +1805,6 @@ function ( $attr, $key ) {
18051805 }
18061806
18071807 if ( $ import_post_term !== 'none ' && strpos ( $ import_post_term , '_ ' ) > 0 ) {
1808- // let's get the slug of the uncategorized category, even if it renamed.
1809- $ uncategorized = get_category ( 1 );
18101808 $ terms = explode ( ', ' , $ import_post_term );
18111809 $ terms = array_filter (
18121810 $ terms ,
@@ -1820,31 +1818,35 @@ function( $term ) {
18201818 return $ term ;
18211819 }
18221820 );
1821+
18231822 $ default_category = (int ) get_option ( 'default_category ' );
1823+ $ has_default = false ;
1824+
18241825 foreach ( $ terms as $ term ) {
18251826 // this handles both x_2, where 2 is the term id and x is the taxonomy AND x_2_3_4 where 4 is the term id and the taxonomy name is "x 2 3 4".
18261827 $ array = explode ( '_ ' , $ term );
18271828 $ term_id = array_pop ( $ array );
18281829 $ taxonomy = implode ( '_ ' , $ array );
18291830
1830- // uncategorized
1831- // 1. may be the unmodified category ID 1
1832- // 2. may have been recreated ('uncategorized') and may have a different slug in different languages.
1833- if ( $ default_category === $ uncategorized ->term_id ) {
1834- wp_remove_object_terms (
1835- $ new_post_id , apply_filters (
1836- 'feedzy_uncategorized ' , array (
1837- 1 ,
1838- 'uncategorized ' ,
1839- $ uncategorized ->slug ,
1840- ), $ job ->ID
1841- ), 'category '
1842- );
1831+ // If the term is not default, flag it.
1832+ if ( $ default_category === (int ) $ term_id ) {
1833+ $ has_default = true ;
18431834 }
18441835
18451836 $ result = wp_set_object_terms ( $ new_post_id , intval ( $ term_id ), $ taxonomy , true );
18461837 do_action ( 'themeisle_log_event ' , FEEDZY_NAME , sprintf ( 'After creating post in %s/%d, result = %s ' , $ taxonomy , $ term_id , print_r ( $ result , true ) ), 'debug ' , __FILE__ , __LINE__ );
18471838 }
1839+
1840+ // If the default category is not used, remove it.
1841+ if ( ! $ has_default ) {
1842+ wp_remove_object_terms (
1843+ $ new_post_id , apply_filters (
1844+ 'feedzy_uncategorized ' , array (
1845+ $ default_category ,
1846+ ), $ job ->ID
1847+ ), 'category '
1848+ );
1849+ }
18481850 }
18491851
18501852 do_action ( 'feedzy_import_extra ' , $ job , $ item_obj , $ new_post_id , $ import_errors , $ import_info );
0 commit comments