What is the function of wp() in wp-blog-header.php

From the WordPress source code: “Set up the WordPress query.” (wp-includes/functions.php)

The wp() method in turn calls the WP->main (wp-includes/class-wp.php), which has the following description:

 "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."

This appears to be sort of a “boot” sequence for wordpress. Parsing the query parameters passed in the url, applying http headers to the response (this includes setting the X-pingback header for pingbacks), setting up the post query ($wp_query and $wp_the_query variables) if applicable, setting up 404 handling and registering global variables/constants.

        $this->init();
        $this->parse_request($query_args);
        $this->send_headers();
        $this->query_posts();
        $this->handle_404();
        $this->register_globals();

To get further details look through each of the methods, they are all in wp-includes/class-wp.php