-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeleted-posts.php
70 lines (61 loc) · 1.5 KB
/
deleted-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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Plugin Name: Deleted Posts
* Plugin URI: https://github.com/indiewordpress/wordpress-deleted-posts
* Description: Sends a HTTP 410 (Gone) response to requests for trashed posts/pages.
* Author: IndieWordPress Team
* Author URI: https://github.com/indiewordpress
* Version: 1.0.0
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Text Domain: deleted-posts
*/
add_action( 'plugins_loaded', array( 'DeletedPosts_Plugin', 'init' ) );
/**
* Deleted Posts Plugin Class
*
* @author Matthias Pfefferle
*/
class DeletedPosts_Plugin {
/**
* Initialize Deleted Posts Plugin
*/
public static function init() {
add_action( 'template_redirect', array( 'DeletedPosts_Plugin', 'handle_410' ), 99 );
}
public static function handle_410() {
if ( ! is_404() ) {
return;
}
global $wp_query;
// check slug
if ( ! empty( $wp_query->query['pagename'] ) ) {
$query = new WP_Query(
array(
'pagename' => $wp_query->query['pagename'] . '__trashed',
'post_status' => 'trash',
)
);
} elseif ( ! empty( $wp_query->query['name'] ) ) {
$query = new WP_Query(
array(
'name' => $wp_query->query['name'] . '__trashed',
'post_status' => 'trash',
)
);
} else {
return;
}
// return 410
if ( $query->get_posts() ) {
status_header( 410 );
// check if theme has a 410.php template
$template_410 = get_query_template( 410 );
// return 410 template
if ( $template_410 ) {
load_template( $template_410 );
exit;
}
}
}
}