@@ -373,6 +373,7 @@ public function feedzy_import_feed_options() {
373373 $ import_auto_translation = get_post_meta ( $ post ->ID , 'import_auto_translation ' , true );
374374 $ import_auto_translation = 'yes ' === $ import_auto_translation ? 'checked ' : '' ;
375375 $ import_translation_lang = get_post_meta ( $ post ->ID , 'import_auto_translation_lang ' , true );
376+ $ mark_duplicate_tag = get_post_meta ( $ post ->ID , 'mark_duplicate_tag ' , true );
376377 $ import_post_author = get_post_meta ( $ post ->ID , 'import_post_author ' , true );
377378 $ filter_conditions = get_post_meta ( $ post ->ID , 'filter_conditions ' , true );
378379
@@ -1033,6 +1034,9 @@ private function get_complete_import_status( $post_id ) {
10331034 if ( $ items ) {
10341035 $ status ['cumulative ' ] = count ( $ items );
10351036 }
1037+ if ( ! empty ( $ status ['duplicates ' ] ) ) {
1038+ $ status ['total ' ] = absint ( $ status ['total ' ] - count ( $ status ['duplicates ' ] ) );
1039+ }
10361040
10371041 return $ status ;
10381042 }
@@ -1411,6 +1415,8 @@ private function run_job( $job, $max ) {
14111415 $ import_translation_lang = get_post_meta ( $ job ->ID , 'import_auto_translation_lang ' , true );
14121416 $ filter_conditions = get_post_meta ( $ job ->ID , 'filter_conditions ' , true );
14131417 $ import_post_author = get_post_meta ( $ job ->ID , 'import_post_author ' , true );
1418+ $ mark_duplicate_tag = get_post_meta ( $ job ->ID , 'mark_duplicate_tag ' , true );
1419+ $ mark_duplicate_tag = feedzy_is_pro () && ! empty ( $ mark_duplicate_tag ) ? preg_replace ( '/[\[\]#]/ ' , '' , $ mark_duplicate_tag ) : '' ;
14141420 $ max = $ import_feed_limit ;
14151421
14161422 if ( empty ( $ filter_conditions ) ) {
@@ -1567,11 +1573,36 @@ private function run_job( $job, $max ) {
15671573 $ is_duplicate = $ use_new_hash ? in_array ( $ item_hash , $ imported_items_new , true ) : in_array ( $ item_hash , $ imported_items_old , true );
15681574 $ items_found [ $ item ['item_url ' ] ] = $ item ['item_title ' ];
15691575
1576+ $ duplicate_tag_value = array ();
1577+ $ mark_duplicate_key = 'item_url ' ;
15701578 if ( 'yes ' === $ import_remove_duplicates && ! $ is_duplicate ) {
1571- $ is_duplicate_post = $ this ->is_duplicate_post ( $ import_post_type , 'feedzy_item_url ' , esc_url_raw ( $ item ['item_url ' ] ) );
1579+ if ( ! empty ( $ mark_duplicate_tag ) ) {
1580+ $ mark_duplicate_tag = is_string ( $ mark_duplicate_tag ) ? explode ( ', ' , $ mark_duplicate_tag ) : $ mark_duplicate_tag ;
1581+ $ mark_duplicate_tag = array_map ( 'trim ' , $ mark_duplicate_tag );
1582+ $ duplicate_tag_value = array_map (
1583+ function ( $ tag ) use ( $ item_obj , $ item ) {
1584+ if ( str_contains ( $ tag , 'item_custom ' ) && $ this ->feedzy_is_business () ) {
1585+ $ tag = apply_filters ( 'feedzy_parse_custom_tags ' , "[# $ tag] " , $ item_obj );
1586+ } elseif ( isset ( $ item [ $ tag ] ) ) {
1587+ $ tag = isset ( $ item [ $ tag ] ) ? is_object ( $ item [ $ tag ] ) ? wp_json_encode ( $ item [ $ tag ] ) : $ item [ $ tag ] : '' ;
1588+ }
1589+ return $ tag ;
1590+ },
1591+ $ mark_duplicate_tag
1592+ );
1593+ }
1594+ if ( ! empty ( $ duplicate_tag_value ) ) {
1595+ $ duplicate_tag_value = implode ( ' ' , $ duplicate_tag_value );
1596+ $ duplicate_tag_value = substr ( sanitize_key ( wp_strip_all_tags ( $ duplicate_tag_value ) ), 0 , apply_filters ( 'feedzy_mark_duplicate_content_limit ' , 256 ) );
1597+ $ mark_duplicate_key = 'mark_duplicate ' ;
1598+ } else {
1599+ $ duplicate_tag_value = esc_url_raw ( $ item ['item_url ' ] );
1600+ }
1601+ $ is_duplicate_post = $ this ->is_duplicate_post ( $ import_post_type , 'feedzy_ ' . $ mark_duplicate_key , $ duplicate_tag_value );
15721602 if ( ! empty ( $ is_duplicate_post ) ) {
15731603 foreach ( $ is_duplicate_post as $ p ) {
1574- $ found_duplicates [] = get_post_meta ( $ p , 'feedzy_item_url ' , true );
1604+ $ found_duplicates [ $ item_hash ] = get_post_meta ( $ p , 'feedzy_ ' . $ mark_duplicate_key , true );
1605+ $ duplicates [ $ item ['item_url ' ] ] = $ item ['item_title ' ];
15751606 wp_delete_post ( $ p , true );
15761607 }
15771608 }
@@ -2120,6 +2151,11 @@ function( $term ) {
21202151 update_post_meta ( $ new_post_id , 'feedzy_job ' , $ job ->ID );
21212152 update_post_meta ( $ new_post_id , 'feedzy_item_author ' , sanitize_text_field ( $ author ) );
21222153
2154+ // Verify that the `$mark_duplicate_key` does not match `'item_url'` to ensure the condition applies only when a different tag is specified.
2155+ if ( $ mark_duplicate_key && 'item_url ' !== $ mark_duplicate_key ) {
2156+ update_post_meta ( $ new_post_id , 'feedzy_ ' . $ mark_duplicate_key , $ duplicate_tag_value );
2157+ }
2158+
21232159 // we can use this to associate the items that were imported in a particular run.
21242160 update_post_meta ( $ new_post_id , 'feedzy_job_time ' , $ last_run );
21252161
0 commit comments