WP::parse_request( array|string $extra_query_vars = '' ): bool
- Since
- 2.0.0, 6.0.0
- Source
wp-includes/class-wp.php:136
Parses the request to find the correct WordPress query.
Description
Sets up the query variables based on the request. There are also many filters and actions that can be used to further manipulate the result.
Parameters
$extra_query_varsarray|stringoptional- Set the extra query variables.Default:
''
Return
bool- Whether the request was parsed.
Hooks fired · 4
4 hooks fire while WP::parse_request() runs, in this order:
- apply_filters( do_parse_request )filterline 148 (+12 into the body)
Filters whether to parse the request.
- apply_filters( query_vars )filterline 311 (+175 into the body)
Filters the query variables allowed before processing.
- apply_filters( request )filterline 409 (+273 into the body)
Filters the array of parsed query variables.
- do_action( parse_request )actionline 418 (+282 into the body)
Fires once all query variables for the current request have been parsed.
Uses · 15
- apply_filters()Calls the callback functions that have been added to a filter hook.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- get_page_by_path()Retrieves a page given its path.
- get_post_status_object()Retrieves a post status object by name.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- get_post_types()Gets a list of all registered post type objects.
- is_post_type_viewable()Determines whether a post type is considered "viewable".
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- __()Retrieves the translation of $text.
- get_taxonomies()Retrieves a list of registered taxonomy names or objects.
- is_admin()Determines whether the current request is for an administrative interface page.
Show all 15
- wp_resolve_numeric_slug_conflicts()Resolves numeric slugs that collide with date permalinks.
- do_action_ref_array()Calls the callback functions that have been added to an action hook, specifying arguments in an array.
- WP_MatchesMapRegex::apply()Substitute substring matches in subject.
Used by · 1
- WP::main()Sets up all of the variables required by the WordPress environment.
Source
public function parse_request( $extra_query_vars = '' ) { global $wp_rewrite; /** * Filters whether to parse the request. * * @since 3.5.0 * * @param bool $bool Whether or not to parse the request. Default true. * @param WP $wp Current WordPress environment instance. * @param array|string $extra_query_vars Extra passed query variables. */ if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) { return false; } $this->query_vars = array(); $post_type_query_vars = array(); if ( is_array( $extra_query_vars ) ) { $this->extra_query_vars = & $extra_query_vars; } elseif ( ! empty( $extra_query_vars ) ) { parse_str( $extra_query_vars, $this->extra_query_vars ); } // Process PATH_INFO, REQUEST_URI, and 404 for permalinks. // Fetch the rewrite rules. $rewrite = $wp_rewrite->wp_rewrite_rules(); if ( ! empty( $rewrite ) ) { // If we match a rewrite rule, this will be cleared. $error = '404'; $this->did_permalink = true; $pathinfo = $_SERVER['PATH_INFO'] ?? ''; list( $pathinfo ) = explode( '?', $pathinfo ); $pathinfo = str_replace( '%', '%25', $pathinfo ); list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] ); $self = $_SERVER['PHP_SELF']; $home_path = parse_url( home_url(), PHP_URL_PATH ); $home_path_regex = ''; if ( is_string( $home_path ) && '' !== $home_path ) { $home_path = trim( $home_path, '/' ); $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) ); } /* * Trim path info from the end and the leading home path from the front. * For path info requests, this leaves us with the requesting filename, if any. * For 404 requests, this leaves us with the requested permalink. */ $req_uri = str_replace( $pathinfo, '', $req_uri ); $req_uri = trim( $req_uri, '/' ); $pathinfo = trim( $pathinfo, '/' ); $self = trim( $self, '/' ); if ( ! empty( $home_path_regex ) ) { $req_uri = preg_replace( $home_path_regex, '', $req_uri ); $req_uri = trim( $req_uri, '/' ); $pathinfo = preg_replace( $home_path_regex, '', $pathinfo ); $pathinfo = trim( $pathinfo, '/' ); $self = preg_replace( $home_path_regex, '', $self ); $self = trim( $self, '/' ); } // The requested permalink is in $pathinfo for path info requests and $req_uri for other requests. if ( ! empty( $pathinfo ) && ! preg_match( '|^.*' . $wp_rewrite->index . '$|', $pathinfo ) ) { $requested_path = $pathinfo; } else { // If the request uri is the index, blank it out so that we don't try to match it against a rule. if ( $req_uri === $wp_rewrite->index ) { $req_uri = ''; } $requested_path = $req_uri; } $requested_file = $req_uri;History
Introduced in 2.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.0.0
A return value was added.from the docblock
2.0.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/class-wp.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.