@@ -1805,8 +1805,6 @@ function ( $attr, $key ) {
1805
1805
}
1806
1806
1807
1807
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 );
1810
1808
$ terms = explode ( ', ' , $ import_post_term );
1811
1809
$ terms = array_filter (
1812
1810
$ terms ,
@@ -1820,31 +1818,35 @@ function( $term ) {
1820
1818
return $ term ;
1821
1819
}
1822
1820
);
1821
+
1823
1822
$ default_category = (int ) get_option ( 'default_category ' );
1823
+ $ has_default = false ;
1824
+
1824
1825
foreach ( $ terms as $ term ) {
1825
1826
// 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".
1826
1827
$ array = explode ( '_ ' , $ term );
1827
1828
$ term_id = array_pop ( $ array );
1828
1829
$ taxonomy = implode ( '_ ' , $ array );
1829
1830
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 ;
1843
1834
}
1844
1835
1845
1836
$ result = wp_set_object_terms ( $ new_post_id , intval ( $ term_id ), $ taxonomy , true );
1846
1837
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__ );
1847
1838
}
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
+ }
1848
1850
}
1849
1851
1850
1852
do_action ( 'feedzy_import_extra ' , $ job , $ item_obj , $ new_post_id , $ import_errors , $ import_info );
0 commit comments