| 1 |
<?php |
| 2 |
|
| 3 |
class Error_Action extends Red_Action { |
| 4 |
function process_before( $code, $target ) { |
| 5 |
$this->code = $code; |
| 6 |
|
| 7 |
wp_reset_query(); |
| 8 |
set_query_var( 'is_404', true ); |
| 9 |
|
| 10 |
add_filter( 'template_include', [ $this, 'template_include' ] ); |
| 11 |
add_filter( 'pre_handle_404', [ $this, 'pre_handle_404' ] ); |
| 12 |
add_action( 'wp', [ $this, 'wp' ] ); |
| 13 |
|
| 14 |
return true; |
| 15 |
} |
| 16 |
|
| 17 |
public function wp() { |
| 18 |
status_header( $this->code ); |
| 19 |
nocache_headers(); |
| 20 |
|
| 21 |
global $wp_version; |
| 22 |
|
| 23 |
if ( version_compare( $wp_version, '5.1', '<' ) ) { |
| 24 |
header( 'X-Redirect-Agent: redirection' ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public function pre_handle_404() { |
| 29 |
global $wp_query; |
| 30 |
|
| 31 |
// Page comments plugin interferes with this |
| 32 |
$wp_query->posts = []; |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
public function template_include() { |
| 37 |
return get_404_template(); |
| 38 |
} |
| 39 |
|
| 40 |
public function needs_target() { |
| 41 |
return false; |
| 42 |
} |
| 43 |
} |
| 44 |
|