-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_unused_posts.php
49 lines (43 loc) · 2.09 KB
/
clean_unused_posts.php
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="el">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>
<body><?php
require_once('wp-load.php') ;
/**
* Goes through all blogs which are last updated <52 weeks and deletes the posts which are auto drafts or revisions or in trash.
* */
function clean_useless_posts() {
global $wpdb ;
echo '<pre>' ;
$blogs = $wpdb->get_results( "SELECT path , blog_id FROM wp_blogs WHERE (last_updated > NOW() - INTERVAL 52 WEEK AND last_updated < NOW() - INTERVAL 30 WEEK )" , ARRAY_A ) ;
$i = 0 ;
echo '<pre>' ;
echo count( $blogs ) . '<br/>' ;
echo 'blog_id, blog_url, db, posts on blog<br/>' ;
foreach ( $blogs as $blog ) {
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->base_prefix}{$blog[ 'blog_id' ]}_posts where "
. "post_status = 'auto-draft' OR "
. "post_status = 'revision' OR"
. " post_status='trash' and post_modified < NOW() - INTERVAL 10 WEEK" , ARRAY_A ) ;
if ( count( $posts ) > 0 ) {
echo '<br/>' . $blog[ 'blog_id' ] . ', http://blogs.sch.gr' . $blog[ 'path' ] . ', ' . substr( md5( $blog[ 'blog_id' ] ) , 0 , 1 ) . ', '
//. 'Posts:' . count( $postsall )
. ' not usable:' . count( $posts ) ;
$i ++ ;
//var_dump( $posts ) ;
switch_to_blog( $blog[ 'blog_id' ] ) ;
foreach ( $posts as $post ) {
wp_delete_post( $post[ 'ID' ] , true ) ;
}
restore_current_blog() ;
}
}
echo '<br/>' . $i ;
}
clean_useless_posts() ;
?>
</body>
</html>