-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdedup.php
More file actions
52 lines (48 loc) · 1.68 KB
/
dedup.php
File metadata and controls
52 lines (48 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
Plugin Name: Dedup
Description: This plugin hooks into the Brafton WordPress Importer Plugin. It tries to catch duplicate posts and make them drafts.
Author: Edward Hornig at Brafton (and Nikita)
*/
add_action('brafton_article_after_save_hook', 'brafton_dedup', 1, 2);
add_action('brafton_video_after_save_hook', 'brafton_dedup', 1, 2);
function brafton_dedup($post_id, $article){
//ed's original dedup
$title_check = sanitize_title(get_the_title($post_id));
$post_check = get_post($post_id);
$slug_check = $post_check->post_name;
if ($title_check !== $slug_check) {
$post_check_array = array(
'ID' => $post_id,
'post_status' => 'draft'
);
wp_update_post($post_check_array);
}
//alternative method of dedup
//loops through every post and trashes any duplicates
//may be resource intensive so only use on sites with <200 posts
/*
$args = array(
'post_type' => 'post',
'meta_query' => array('key' => 'brafton_id')
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
$title_check = sanitize_title(get_the_title($post_query->ID));
$post_check = get_post($post_query->ID);
$slug_check = $post_check->post_name;
if ($title_check !== $slug_check) {
// $post_check_array = array(
// 'ID' => $post_query->ID,
// 'post_status' => 'draft'
// );
// wp_update_post($post_check_array);
wp_trash_post($post_query->ID);
}
}
}
*/
}
?>