Skip to content

Commit a0b78ea

Browse files
committed
simplified plugin
1 parent 2d31a65 commit a0b78ea

6 files changed

Lines changed: 60 additions & 17 deletions

File tree

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function(grunt) {
1414
mainFile: 'deleted-posts.php',
1515
domainPath: '/languages',
1616
exclude: ['bin/.*', '.git/.*', 'vendor/.*'],
17-
potFilename: 'wordpress-deleted-posts.pot',
17+
potFilename: 'deleted-posts.pot',
1818
type: 'wp-plugin',
1919
updateTimestamp: true
2020
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
**License:** MIT
99
**License URI:** http://opensource.org/licenses/MIT
1010

11-
Deleted Posts for WordPress!
11+
Sends a HTTP 410 (Gone) response to requests for trashed posts/pages.

composer.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
{
22
"name": "indiewordpress/wordpress-deleted-posts",
3-
"description": "",
3+
"description": "Sends a HTTP 410 (Gone) response to requests for trashed posts/pages.",
44
"require": {
5-
"php": ">=5.6.0"
5+
"php": ">=5.6.0",
6+
"composer/installers": "~1.0"
67
},
78
"type": "wordpress-plugin",
89
"license": "MIT",
910
"authors": [
1011
{
1112
"name": "Matthias Pfefferle",
12-
"homepage": "http://notizblog.org"
13+
"homepage": "http://notiz.blog"
1314
}
1415
],
1516
"require-dev": {
1617
"phpunit/phpunit": "5.5.*"
1718
},
18-
"scripts": {
19-
"test": [
20-
"composer install",
21-
"bin/install-wp-tests.sh wordpress wordpress wordpress",
22-
"vendor/bin/phpunit"
23-
]
19+
"extra": {
20+
"installer-name": "deleted-posts"
2421
}
2522
}

deleted-posts.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Deleted Posts
44
* Plugin URI: https://github.com/indiewordpress/wordpress-deleted-posts
5-
* Description: Deleted Posts
5+
* Description: Sends a HTTP 410 (Gone) response to requests for trashed posts/pages.
66
* Author: IndieWordPress Team
77
* Author URI: https://github.com/indiewordpress
88
* Version: 1.0.0
@@ -19,10 +19,52 @@
1919
* @author Matthias Pfefferle
2020
*/
2121
class DeletedPosts_Plugin {
22+
2223
/**
2324
* Initialize Deleted Posts Plugin
2425
*/
2526
public static function init() {
27+
add_action( 'template_redirect', array( 'DeletedPosts_Plugin', 'handle_410' ), 99 );
28+
}
29+
30+
public static function handle_410() {
31+
if ( ! is_404() ) {
32+
return;
33+
}
34+
35+
global $wp_query;
36+
37+
// check slug
38+
if ( ! empty( $wp_query->query['pagename'] ) ) {
39+
$query = new WP_Query(
40+
array(
41+
'pagename' => $wp_query->query['pagename'] . '__trashed',
42+
'post_status' => 'trash',
43+
)
44+
);
45+
} elseif ( ! empty( $wp_query->query['name'] ) ) {
46+
$query = new WP_Query(
47+
array(
48+
'name' => $wp_query->query['name'] . '__trashed',
49+
'post_status' => 'trash',
50+
)
51+
);
52+
} else {
53+
return;
54+
}
55+
56+
// return 410
57+
if ( $query->get_posts() ) {
58+
status_header( 410 );
59+
60+
// check if theme has a 410.php template
61+
$template_410 = get_query_template( 410 );
2662

63+
// return 410 template
64+
if ( $template_410 ) {
65+
load_template( $template_410 );
66+
exit;
67+
}
68+
}
2769
}
2870
}
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
# Copyright (C) 2016 IndieWordPress Team
1+
# Copyright (C) 2017 IndieWordPress Team
22
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
55
"Project-Id-Version: Deleted Posts 1.0.0\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/deleted-posts\n"
7-
"POT-Creation-Date: 2016-11-13 20:53:32+00:00\n"
7+
"POT-Creation-Date: 2017-03-05 21:42:24+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"
11-
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
11+
"PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <LL@li.org>\n"
1414
"X-Generator: grunt-wp-i18n 0.5.4\n"
1515

16-
#. Description of the plugin/theme
16+
#. Plugin Name of the plugin/theme
1717
msgid "Deleted Posts"
1818
msgstr ""
1919

2020
#. Plugin URI of the plugin/theme
2121
msgid "https://github.com/indiewordpress/wordpress-deleted-posts"
2222
msgstr ""
2323

24+
#. Description of the plugin/theme
25+
msgid "Sends a HTTP 410 (Gone) response to requests for trashed posts/pages."
26+
msgstr ""
27+
2428
#. Author of the plugin/theme
2529
msgid "IndieWordPress Team"
2630
msgstr ""

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Stable tag: 1.0.0
88
License: MIT
99
License URI: http://opensource.org/licenses/MIT
1010

11-
Deleted Posts for WordPress!
11+
Sends a HTTP 410 (Gone) response to requests for trashed posts/pages.

0 commit comments

Comments
 (0)