s, seemingly successful requests can be switched to * a 404 so that canonical redirection logic can kick in. * * @since 2.0.0 * @access public * * @global WP_Query $wp_query */ public function handle_404() { global $wp_query; /** * Filter whether to short-circuit default header status handling. * * Returning a non-false value from the filter will short-circuit the handling * and return early. * * @since 4.5.0 * * @param bool $preempt Whether to short-circuit default header status handling. Default false. * @param WP_Query $wp_query WordPress Query object. */ if ( false !== apply_filters( 'pre_handle_404', false, $wp_query ) ) { return; } // If we've already issued a 404, bail. if ( is_404() ) return; // Never 404 for the admin, robots, or if we found posts. if ( is_admin() || is_robots() || $wp_query->posts ) { $success = true; if ( is_singular() ) { $p = false; if ( $wp_query->post instanceof WP_Post ) { $p = clone $wp_query->post; } // Only set X-Pingback for single posts that allow pings. if ( $p && pings_open( $p ) ) { @header( 'X-Pingback: ' . get_bloginfo( 'pingback_url' ) ); } // check for paged content that exceeds the max number of pages $next = ''; if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $this->query_vars['page'] ) ) { $page = trim( $this->query_vars['page'], '/' ); $success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 ); } } if ( $success ) { status_header( 200 ); return; } } // We will 404 for paged queries, as no posts were found. if ( ! is_paged() ) { // Don't 404 for authors without posts as long as they matched an author on this site. $author = get_query_var( 'author' ); if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) { status_header( 200 ); return; } // Don't 404 for these queries if they matched an object. if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) { status_header( 200 ); return; } // Don't 404 for these queries either. if ( is_home() || is_search() || is_feed() ) { status_header( 200 ); return; } } // Guess it's time to 404. $wp_query->set_404(); status_header( 404 ); nocache_headers(); } /** * Sets up all of the variables required by the WordPress environment. * * The action 'wp' has one parameter that references the WP object. It * allows for accessing the properties and methods to further manipulate the * object. * * @since 2.0.0 * @access public * * @param string|array $query_args Passed to {@link parse_request()} */ public function main($query_args = '') { $this->init(); $this->parse_request($query_args); $this->send_headers(); $this->query_posts(); $this->handle_404(); $this->register_globals(); /** * Fires once the WordPress environment has been set up. * * @since 2.1.0 * * @param WP &$this Current WordPress environment instance (passed by reference). */ do_action_ref_array( 'wp', array( &$this ) ); } } /** * Helper class to remove the need to use eval to replace $matches[] in query strings. * * @since 2.9.0 */ class WP_MatchesMapRegex { /** * store for matches * * @access private * @var array */ private $_matches; /** * store for mapping result * * @access public * @var string */ public $output; /** * subject to perform mapping on (query string containing $matches[] references * * @access private * @var string */ private $_subject; /** * regexp pattern to match $matches[] references * * @var string */ public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number /** * constructor * * @param string $subject subject if regex * @param array $matches data to use in map */ public function __construct($subject, $matches) { $this->_subject = $subject; $this->_matches = $matches; $this->output = $this->_map(); } /** * Substitute substring matches in subject. * * static helper function to ease use * * @static * @access public * * @param string $subject subject * @param array $matches data used for substitution * @return string */ public static function apply($subject, $matches) { $oSelf = new WP_MatchesMapRegex($subject, $matches); return $oSelf->output; } /** * do the actual mapping * * @access private * @return string */ private function _map() { $callback = array($this, 'callback'); return preg_replace_callback($this->_pattern, $callback, $this->_subject); } /** * preg_replace_callback hook * * @access public * @param array $matches preg_replace regexp matches * @return string */ public function callback($matches) { $index = intval(substr($matches[0], 9, -1)); return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' ); } } Database Error

Error establishing a database connection