@@ -1907,8 +1907,6 @@ function ( $attr, $key ) {
1907
1907
}
1908
1908
1909
1909
if ( $ import_post_term !== 'none ' && strpos ( $ import_post_term , '_ ' ) > 0 ) {
1910
- // let's get the slug of the uncategorized category, even if it renamed.
1911
- $ uncategorized = get_category ( 1 );
1912
1910
$ terms = explode ( ', ' , $ import_post_term );
1913
1911
$ terms = array_filter (
1914
1912
$ terms ,
@@ -1922,31 +1920,35 @@ function( $term ) {
1922
1920
return $ term ;
1923
1921
}
1924
1922
);
1923
+
1925
1924
$ default_category = (int ) get_option ( 'default_category ' );
1925
+ $ has_default = false ;
1926
+
1926
1927
foreach ( $ terms as $ term ) {
1927
1928
// 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".
1928
1929
$ array = explode ( '_ ' , $ term );
1929
1930
$ term_id = array_pop ( $ array );
1930
1931
$ taxonomy = implode ( '_ ' , $ array );
1931
1932
1932
- // uncategorized
1933
- // 1. may be the unmodified category ID 1
1934
- // 2. may have been recreated ('uncategorized') and may have a different slug in different languages.
1935
- if ( $ default_category === $ uncategorized ->term_id ) {
1936
- wp_remove_object_terms (
1937
- $ new_post_id , apply_filters (
1938
- 'feedzy_uncategorized ' , array (
1939
- 1 ,
1940
- 'uncategorized ' ,
1941
- $ uncategorized ->slug ,
1942
- ), $ job ->ID
1943
- ), 'category '
1944
- );
1933
+ // If the term is not default, flag it.
1934
+ if ( $ default_category === (int ) $ term_id ) {
1935
+ $ has_default = true ;
1945
1936
}
1946
1937
1947
1938
$ result = wp_set_object_terms ( $ new_post_id , intval ( $ term_id ), $ taxonomy , true );
1948
1939
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__ );
1949
1940
}
1941
+
1942
+ // If the default category is not used, remove it.
1943
+ if ( ! $ has_default ) {
1944
+ wp_remove_object_terms (
1945
+ $ new_post_id , apply_filters (
1946
+ 'feedzy_uncategorized ' , array (
1947
+ $ default_category ,
1948
+ ), $ job ->ID
1949
+ ), 'category '
1950
+ );
1951
+ }
1950
1952
}
1951
1953
1952
1954
do_action ( 'feedzy_import_extra ' , $ job , $ item_obj , $ new_post_id , $ import_errors , $ import_info );
0 commit comments