Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
**Donate link:** https://indieweb.org/how-to-sponsor
**Tags:** deleted posts, 410, 451, indieweb
**Requires at least:** 4.6
**Tested up to:** 4.6.2
**Stable tag:** 1.0.0
**Tested up to:** 5.0.3
**Stable tag:** 1.0.1
**License:** MIT
**License URI:** http://opensource.org/licenses/MIT

Expand Down
78 changes: 36 additions & 42 deletions deleted-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,60 @@
* 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
* Version: 1.0.1
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Text Domain: deleted-posts
*/

add_action( 'plugins_loaded', array( 'DeletedPosts_Plugin', 'init' ) );
add_action( 'template_redirect', 'IndieWordPress_handle_410', 99 );

/**
* 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 );
function IndieWordPress_handle_410() {

if ( ! is_404() ) {
return;
}

public static function handle_410() {
if ( ! is_404() ) {
return;
}
global $wp_query;

global $wp_query;
$defaultArguments = [
'pagename' => ( empty( $wp_query->query['pagename'] ) ? $wp_query->query['pagename'] : false ),
'name' => ( empty( $wp_query->query['name'] ) ? $wp_query->query['name'] : false),
'post_status' => 'trash',
];

// 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;
$filteredArguments = array_filter($defaultArguments, function($value){
if($value === false || $value == 'trash'){
return $value;
}

// return 410
if ( $query->get_posts() ) {
status_header( 410 );
return $value . '__trashed';
});

// check if theme has a 410.php template
$template_410 = get_query_template( 410 );
if ( count($filteredArguments) <= 1 ) {
return;
}

// return 410 template
if ( $template_410 ) {
load_template( $template_410 );
exit;
}
}
$query = new WP_Query($filteredArguments);

// return 410
if ( count($query->get_posts()) <= 0 ) {
return;
}

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;
}
}
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://indieweb.org/how-to-sponsor
Tags: deleted posts, 410, 451, indieweb
Requires at least: 4.6
Tested up to: 5.0.3
Stable tag: 1.0.0
Stable tag: 1.0.1
License: MIT
License URI: http://opensource.org/licenses/MIT

Expand Down