[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp.php (summary)

(no description)

File Size: 1082 lines (36 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP:: (14 methods):
  add_query_var()
  remove_query_var()
  set_query_var()
  parse_request()
  send_headers()
  build_query_string()
  register_globals()
  init()
  query_posts()
  handle_random()
  redirect_random_search()
  urlencode_query_args()
  handle_404()
  main()


Class: WP  - X-Ref

WordPress environment setup class.

add_query_var( $qv )   X-Ref
Adds a query variable to the list of public query variables.

param: string $qv Query variable name.

remove_query_var( $name )   X-Ref
Removes a query variable from a list of public query variables.

param: string $name Query variable name.

set_query_var( $key, $value )   X-Ref
Sets the value of a query variable.

param: string $key   Query variable name.
param: mixed  $value Query variable value.

parse_request( $extra_query_vars = '' )   X-Ref
Parses the request to find the correct WordPress query.

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.

return: bool Whether the request was parsed.
param: array|string $extra_query_vars Set the extra query variables.

send_headers()   X-Ref
Sends additional HTTP headers for caching, content type, etc.

Sets the Content-Type header. Sets the 'error' status (if passed) and optionally exits.
If showing a feed, it will also send Last-Modified, ETag, and 304 status if needed.


build_query_string()   X-Ref
Sets the query string property based off of the query variable property.

The {@see 'query_string'} filter is deprecated, but still works. Plugins should
use the {@see 'request'} filter instead.


register_globals()   X-Ref
Set up the WordPress Globals.

The query_vars property will be extracted to the GLOBALS. So care should
be taken when naming global variables that might interfere with the
WordPress environment.


init()   X-Ref
Set up the current user.


query_posts()   X-Ref
Set up the Loop based on the query variables.


handle_random()   X-Ref
Redirects random content requests to a randomly selected post.

For random content requests, runs the main query to select a single random post
from the requested archive and redirects to it. The post is selected by looking up
random post IDs, see {@see wp_random_content_posts_pre_query()}, as sorting posts
randomly requires the database to read every eligible post. For example, `example.com/random/`
redirects to a random post and `example.com/random/category/news/` redirects to a
random post in the "news" category.

The random post is selected by the main query, so {@see 'pre_get_posts'} callbacks
customizing the archive apply to the selection. While the query runs, callbacks
enforcing the eligible posts, order and limit are added after any other callbacks:

- {@see wp_random_content_pre_get_posts()} on the {@see 'pre_get_posts'} action.
- {@see wp_random_content_posts_where()} on the {@see 'posts_where'} filter.
- {@see wp_random_content_posts_orderby()} on the {@see 'posts_orderby'} filter.
- {@see wp_random_content_post_limits()} on the {@see 'post_limits'} filter.
- {@see wp_random_content_posts_fields()} on the {@see 'posts_fields'} filter.
- {@see wp_random_content_posts_pre_query()} on the {@see 'posts_pre_query'} filter.

If a post is selected, the redirect is sent by {@see wp_random_content_redirect()}
on the {@see 'template_redirect'} action at priority 100, so the request is set up
and the {@see 'wp'} action has fired before the redirect.

If no post is selected, for example on an empty archive, the request is a 404 as
there is no post to redirect to. If a post is selected, the request ends with
the redirect. Otherwise the request continues with the results of the main
query, which is not run again.

Search requests are never random content requests. A search request that includes
the `random` query variable is redirected to the search results without it, see
{@see WP::redirect_random_search()}.

Requests that are not for posts ignore the `random` query variable, they are neither
random content requests nor redirected. These are requests for robots.txt, the
favicon, sitemaps, feeds and trackbacks.

return: bool Whether the main query was run for a random content request.

redirect_random_search()   X-Ref
Redirects search requests for random content to the search results.

Random content can not be requested from search results. Instead, a search
request that includes the `random` query variable is redirected to
the same request without it.

The location depends on how random content was requested:

- By the `random` query string parameter: the requested path is retained and the
parameter is removed. For example, `example.com/search/foo/?random` redirects to
`example.com/search/foo/` and `example.com/?s=foo&random` to `example.com/?s=foo`.
- By a rewrite rule, such as those using the random base: the path is replaced by the
query variables of the request, so the location never includes the random base.
For example, `example.com/random/category/news/?s=foo` redirects to
`example.com/?s=foo&category_name=news`.

Other query string parameters, including those that are not query variables, are
retained. The redirect happens before the main query is run, so no search is
performed for the redirected request.

As with random content requests, only front end GET and HEAD requests are redirected.
The request is not redirected when the location would be the requested URL. This is
the case when random content is not requested by the URL, for example by a filter,
or is requested by a rewrite rule for the home page.


urlencode_query_args( array $query_args )   X-Ref
URL-encodes the names and values of query string parameters.

Unlike urlencode_deep(), the parameter names are encoded as well as the values. A
name is from the request, so may include characters that separate parameters.

The values are unslashed before they are encoded. The names are not, as slashes
are only added to the values of the superglobals.

return: array<string, mixed> URL-encoded query string parameters. Values that are
param: array<mixed> $query_args Query string parameters. The values are expected to

handle_404()   X-Ref
Set the Headers for 404, if nothing is found for requested URL.

Issue a 404 if a request doesn't match any posts and doesn't match any object
(e.g. an existing-but-empty category, tag, author) and a 404 was not already issued,
and if the request was not a search or the homepage.

Otherwise, issue a 200.

This sets headers after posts have been queried. handle_404() really means "handle status".
By inspecting the result of querying posts, seemingly successful requests can be switched to
a 404 so that canonical redirection logic can kick in.


main( $query_args = '' )   X-Ref
Sets up all of the variables required by the WordPress environment.

The action {@see 'wp'} has one parameter that references the WP object. It
allows for accessing the properties and methods to further manipulate the
object.

param: string|array $query_args Passed to parse_request().



Generated : Mon Nov 23 08:20:01 2026 Cross-referenced by PHPXref