| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/wordpress-seo/frontend/ |
Upload File : |
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Frontend
*/
/**
* Class WPSEO_Handle_404
*
* Handles intercepting requests.
*
* @since 9.4
*/
class WPSEO_Handle_404 implements WPSEO_WordPress_Integration {
/**
* Registers all hooks to WordPress.
*
* @return void
*/
public function register_hooks() {
add_filter( 'pre_handle_404', array( $this, 'handle_404' ) );
}
/**
* Handle the 404 status code.
*
* @param bool $handled Whether we've handled the request.
*
* @return bool True if it's 404.
*/
public function handle_404( $handled ) {
if ( is_feed() ) {
return $this->is_feed_404( $handled );
}
return $handled;
}
/**
* If there are no posts in a feed, make it 404 instead of sending an empty RSS feed.
*
* @global WP_Query $wp_query
*
* @param bool $handled Whether we've handled the request.
*
* @return bool True if it's 404.
*/
protected function is_feed_404( $handled ) {
global $wp_query;
// Don't 404 if the query contains post(s) or an object.
if ( $wp_query->posts || $wp_query->get_queried_object() ) {
return $handled;
}
// Don't 404 if it isn't archive or singular.
if ( ! $wp_query->is_archive() && ! $wp_query->is_singular() ) {
return $handled;
}
$wp_query->is_feed = false;
$this->set_404();
add_filter( 'old_slug_redirect_url', '__return_false' );
add_filter( 'redirect_canonical', '__return_false' );
return true;
}
/**
* Sets the 404 status code.
*
* @global WP_Query $wp_query
*
* @return void
*/
private function set_404() {
global $wp_query;
// Overwrite Content-Type header.
if ( ! headers_sent() ) {
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
}
$wp_query->set_404();
status_header( 404 );
nocache_headers();
}
}