wp/wp-includes/class-wp.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    13 	 *
    13 	 *
    14 	 * @since 2.0.0
    14 	 * @since 2.0.0
    15 	 * @access public
    15 	 * @access public
    16 	 * @var array
    16 	 * @var array
    17 	 */
    17 	 */
    18 	var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
    18 	public $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
    19 
    19 
    20 	/**
    20 	/**
    21 	 * Private query variables.
    21 	 * Private query variables.
    22 	 *
    22 	 *
    23 	 * Long list of private query variables.
    23 	 * Long list of private query variables.
    24 	 *
    24 	 *
    25 	 * @since 2.0.0
    25 	 * @since 2.0.0
    26 	 * @var array
    26 	 * @var array
    27 	 */
    27 	 */
    28 	var $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent__in', 'post_parent__not_in' );
    28 	public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in' );
    29 
    29 
    30 	/**
    30 	/**
    31 	 * Extra query variables set by the user.
    31 	 * Extra query variables set by the user.
    32 	 *
    32 	 *
    33 	 * @since 2.1.0
    33 	 * @since 2.1.0
    34 	 * @var array
    34 	 * @var array
    35 	 */
    35 	 */
    36 	var $extra_query_vars = array();
    36 	public $extra_query_vars = array();
    37 
    37 
    38 	/**
    38 	/**
    39 	 * Query variables for setting up the WordPress Query Loop.
    39 	 * Query variables for setting up the WordPress Query Loop.
    40 	 *
    40 	 *
    41 	 * @since 2.0.0
    41 	 * @since 2.0.0
    42 	 * @var array
    42 	 * @var array
    43 	 */
    43 	 */
    44 	var $query_vars;
    44 	public $query_vars;
    45 
    45 
    46 	/**
    46 	/**
    47 	 * String parsed to set the query variables.
    47 	 * String parsed to set the query variables.
    48 	 *
    48 	 *
    49 	 * @since 2.0.0
    49 	 * @since 2.0.0
    50 	 * @var string
    50 	 * @var string
    51 	 */
    51 	 */
    52 	var $query_string;
    52 	public $query_string;
    53 
    53 
    54 	/**
    54 	/**
    55 	 * Permalink or requested URI.
    55 	 * Permalink or requested URI.
    56 	 *
    56 	 *
    57 	 * @since 2.0.0
    57 	 * @since 2.0.0
    58 	 * @var string
    58 	 * @var string
    59 	 */
    59 	 */
    60 	var $request;
    60 	public $request;
    61 
    61 
    62 	/**
    62 	/**
    63 	 * Rewrite rule the request matched.
    63 	 * Rewrite rule the request matched.
    64 	 *
    64 	 *
    65 	 * @since 2.0.0
    65 	 * @since 2.0.0
    66 	 * @var string
    66 	 * @var string
    67 	 */
    67 	 */
    68 	var $matched_rule;
    68 	public $matched_rule;
    69 
    69 
    70 	/**
    70 	/**
    71 	 * Rewrite query the request matched.
    71 	 * Rewrite query the request matched.
    72 	 *
    72 	 *
    73 	 * @since 2.0.0
    73 	 * @since 2.0.0
    74 	 * @var string
    74 	 * @var string
    75 	 */
    75 	 */
    76 	var $matched_query;
    76 	public $matched_query;
    77 
    77 
    78 	/**
    78 	/**
    79 	 * Whether already did the permalink.
    79 	 * Whether already did the permalink.
    80 	 *
    80 	 *
    81 	 * @since 2.0.0
    81 	 * @since 2.0.0
    82 	 * @var bool
    82 	 * @var bool
    83 	 */
    83 	 */
    84 	var $did_permalink = false;
    84 	public $did_permalink = false;
    85 
    85 
    86 	/**
    86 	/**
    87 	 * Add name to list of public query variables.
    87 	 * Add name to list of public query variables.
    88 	 *
    88 	 *
    89 	 * @since 2.1.0
    89 	 * @since 2.1.0
    90 	 *
    90 	 *
    91 	 * @param string $qv Query variable name.
    91 	 * @param string $qv Query variable name.
    92 	 */
    92 	 */
    93 	function add_query_var($qv) {
    93 	public function add_query_var($qv) {
    94 		if ( !in_array($qv, $this->public_query_vars) )
    94 		if ( !in_array($qv, $this->public_query_vars) )
    95 			$this->public_query_vars[] = $qv;
    95 			$this->public_query_vars[] = $qv;
    96 	}
    96 	}
    97 
    97 
    98 	/**
    98 	/**
   101 	 * @since 2.3.0
   101 	 * @since 2.3.0
   102 	 *
   102 	 *
   103 	 * @param string $key Query variable name.
   103 	 * @param string $key Query variable name.
   104 	 * @param mixed $value Query variable value.
   104 	 * @param mixed $value Query variable value.
   105 	 */
   105 	 */
   106 	function set_query_var($key, $value) {
   106 	public function set_query_var($key, $value) {
   107 		$this->query_vars[$key] = $value;
   107 		$this->query_vars[$key] = $value;
   108 	}
   108 	}
   109 
   109 
   110 	/**
   110 	/**
   111 	 * Parse request to find correct WordPress query.
   111 	 * Parse request to find correct WordPress query.
   115 	 *
   115 	 *
   116 	 * @since 2.0.0
   116 	 * @since 2.0.0
   117 	 *
   117 	 *
   118 	 * @param array|string $extra_query_vars Set the extra query variables.
   118 	 * @param array|string $extra_query_vars Set the extra query variables.
   119 	 */
   119 	 */
   120 	function parse_request($extra_query_vars = '') {
   120 	public function parse_request($extra_query_vars = '') {
   121 		global $wp_rewrite;
   121 		global $wp_rewrite;
   122 
   122 
       
   123 		/**
       
   124 		 * Filter whether to parse the request.
       
   125 		 *
       
   126 		 * @since 3.5.0
       
   127 		 *
       
   128 		 * @param bool         $bool             Whether or not to parse the request. Default true.
       
   129 		 * @param WP           $this             Current WordPress environment instance.
       
   130 		 * @param array|string $extra_query_vars Extra passed query variables.
       
   131 		 */
   123 		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) )
   132 		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) )
   124 			return;
   133 			return;
   125 
   134 
   126 		$this->query_vars = array();
   135 		$this->query_vars = array();
   127 		$post_type_query_vars = array();
   136 		$post_type_query_vars = array();
   128 
   137 
   129 		if ( is_array($extra_query_vars) )
   138 		if ( is_array( $extra_query_vars ) ) {
   130 			$this->extra_query_vars = & $extra_query_vars;
   139 			$this->extra_query_vars = & $extra_query_vars;
   131 		else if (! empty($extra_query_vars))
   140 		} elseif ( ! empty( $extra_query_vars ) ) {
   132 			parse_str($extra_query_vars, $this->extra_query_vars);
   141 			parse_str( $extra_query_vars, $this->extra_query_vars );
   133 
   142 		}
   134 		// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
   143 		// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
   135 
   144 
   136 		// Fetch the rewrite rules.
   145 		// Fetch the rewrite rules.
   137 		$rewrite = $wp_rewrite->wp_rewrite_rules();
   146 		$rewrite = $wp_rewrite->wp_rewrite_rules();
   138 
   147 
   194 
   203 
   195 					if ( preg_match("#^$match#", $request_match, $matches) ||
   204 					if ( preg_match("#^$match#", $request_match, $matches) ||
   196 						preg_match("#^$match#", urldecode($request_match), $matches) ) {
   205 						preg_match("#^$match#", urldecode($request_match), $matches) ) {
   197 
   206 
   198 						if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
   207 						if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
   199 							// this is a verbose page match, lets check to be sure about it
   208 							// This is a verbose page match, let's check to be sure about it.
   200 							if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
   209 							if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
   201 						 		continue;
   210 						 		continue;
   202 						}
   211 						}
   203 
   212 
   204 						// Got a match.
   213 						// Got a match.
   234 
   243 
   235 				$this->did_permalink = false;
   244 				$this->did_permalink = false;
   236 			}
   245 			}
   237 		}
   246 		}
   238 
   247 
   239 		$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
   248 		/**
       
   249 		 * Filter the query variables whitelist before processing.
       
   250 		 *
       
   251 		 * Allows (publicly allowed) query vars to be added, removed, or changed prior
       
   252 		 * to executing the query. Needed to allow custom rewrite rules using your own arguments
       
   253 		 * to work, or any other custom query variables you want to be publicly available.
       
   254 		 *
       
   255 		 * @since 1.5.0
       
   256 		 *
       
   257 		 * @param array $public_query_vars The array of whitelisted query variables.
       
   258 		 */
       
   259 		$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
   240 
   260 
   241 		foreach ( get_post_types( array(), 'objects' ) as $post_type => $t )
   261 		foreach ( get_post_types( array(), 'objects' ) as $post_type => $t )
   242 			if ( $t->query_var )
   262 			if ( $t->query_var )
   243 				$post_type_query_vars[$t->query_var] = $post_type;
   263 				$post_type_query_vars[$t->query_var] = $post_type;
   244 
   264 
   292 		}
   312 		}
   293 
   313 
   294 		if ( isset($error) )
   314 		if ( isset($error) )
   295 			$this->query_vars['error'] = $error;
   315 			$this->query_vars['error'] = $error;
   296 
   316 
   297 		$this->query_vars = apply_filters('request', $this->query_vars);
   317 		/**
   298 
   318 		 * Filter the array of parsed query variables.
   299 		do_action_ref_array('parse_request', array(&$this));
   319 		 *
       
   320 		 * @since 2.1.0
       
   321 		 *
       
   322 		 * @param array $query_vars The array of requested query variables.
       
   323 		 */
       
   324 		$this->query_vars = apply_filters( 'request', $this->query_vars );
       
   325 
       
   326 		/**
       
   327 		 * Fires once all query variables for the current request have been parsed.
       
   328 		 *
       
   329 		 * @since 2.1.0
       
   330 		 *
       
   331 		 * @param WP &$this Current WordPress environment instance (passed by reference).
       
   332 		 */
       
   333 		do_action_ref_array( 'parse_request', array( &$this ) );
   300 	}
   334 	}
   301 
   335 
   302 	/**
   336 	/**
   303 	 * Send additional HTTP headers for caching, content type, etc.
   337 	 * Send additional HTTP headers for caching, content type, etc.
   304 	 *
   338 	 *
   305 	 * Sets the X-Pingback header, 404 status (if 404), Content-type. If showing
   339 	 * Sets the X-Pingback header, 404 status (if 404), Content-type. If showing
   306 	 * a feed, it will also send last-modified, etag, and 304 status if needed.
   340 	 * a feed, it will also send last-modified, etag, and 304 status if needed.
   307 	 *
   341 	 *
   308 	 * @since 2.0.0
   342 	 * @since 2.0.0
   309 	 */
   343 	 */
   310 	function send_headers() {
   344 	public function send_headers() {
   311 		$headers = array('X-Pingback' => get_bloginfo('pingback_url'));
   345 		$headers = array('X-Pingback' => get_bloginfo('pingback_url'));
   312 		$status = null;
   346 		$status = null;
   313 		$exit_required = false;
   347 		$exit_required = false;
   314 
   348 
   315 		if ( is_user_logged_in() )
   349 		if ( is_user_logged_in() )
   321 					$headers = array_merge($headers, wp_get_nocache_headers());
   355 					$headers = array_merge($headers, wp_get_nocache_headers());
   322 				$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   356 				$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   323 			} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) {
   357 			} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) {
   324 				$exit_required = true;
   358 				$exit_required = true;
   325 			}
   359 			}
   326 		} else if ( empty($this->query_vars['feed']) ) {
   360 		} elseif ( empty( $this->query_vars['feed'] ) ) {
   327 			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   361 			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   328 		} else {
   362 		} else {
   329 			// We're showing a feed, so WP is indeed the only thing that last changed
   363 			// We're showing a feed, so WP is indeed the only thing that last changed
   330 			if ( !empty($this->query_vars['withcomments'])
   364 			if ( !empty($this->query_vars['withcomments'])
   331 				|| false !== strpos( $this->query_vars['feed'], 'comments-' )
   365 				|| false !== strpos( $this->query_vars['feed'], 'comments-' )
   364 				$status = 304;
   398 				$status = 304;
   365 				$exit_required = true;
   399 				$exit_required = true;
   366 			}
   400 			}
   367 		}
   401 		}
   368 
   402 
   369 		$headers = apply_filters('wp_headers', $headers, $this);
   403 		/**
       
   404 		 * Filter the HTTP headers before they're sent to the browser.
       
   405 		 *
       
   406 		 * @since 2.8.0
       
   407 		 *
       
   408 		 * @param array $headers The list of headers to be sent.
       
   409 		 * @param WP    $this    Current WordPress environment instance.
       
   410 		 */
       
   411 		$headers = apply_filters( 'wp_headers', $headers, $this );
   370 
   412 
   371 		if ( ! empty( $status ) )
   413 		if ( ! empty( $status ) )
   372 			status_header( $status );
   414 			status_header( $status );
   373 
   415 
   374 		// If Last-Modified is set to false, it should not be sent (no-cache situation).
   416 		// If Last-Modified is set to false, it should not be sent (no-cache situation).
   394 			@header("{$name}: {$field_value}");
   436 			@header("{$name}: {$field_value}");
   395 
   437 
   396 		if ( $exit_required )
   438 		if ( $exit_required )
   397 			exit();
   439 			exit();
   398 
   440 
   399 		do_action_ref_array('send_headers', array(&$this));
   441 		/**
       
   442 		 * Fires once the requested HTTP headers for caching, content type, etc. have been sent.
       
   443 		 *
       
   444 		 * @since 2.1.0
       
   445 		 *
       
   446 		 * @param WP &$this Current WordPress environment instance (passed by reference).
       
   447 		 */
       
   448 		do_action_ref_array( 'send_headers', array( &$this ) );
   400 	}
   449 	}
   401 
   450 
   402 	/**
   451 	/**
   403 	 * Sets the query string property based off of the query variable property.
   452 	 * Sets the query string property based off of the query variable property.
   404 	 *
   453 	 *
   405 	 * The 'query_string' filter is deprecated, but still works. Plugins should
   454 	 * The 'query_string' filter is deprecated, but still works. Plugins should
   406 	 * use the 'request' filter instead.
   455 	 * use the 'request' filter instead.
   407 	 *
   456 	 *
   408 	 * @since 2.0.0
   457 	 * @since 2.0.0
   409 	 */
   458 	 */
   410 	function build_query_string() {
   459 	public function build_query_string() {
   411 		$this->query_string = '';
   460 		$this->query_string = '';
   412 		foreach ( (array) array_keys($this->query_vars) as $wpvar) {
   461 		foreach ( (array) array_keys($this->query_vars) as $wpvar) {
   413 			if ( '' != $this->query_vars[$wpvar] ) {
   462 			if ( '' != $this->query_vars[$wpvar] ) {
   414 				$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
   463 				$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
   415 				if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
   464 				if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
   416 					continue;
   465 					continue;
   417 				$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
   466 				$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
   418 			}
   467 			}
   419 		}
   468 		}
   420 
   469 
   421 		// query_string filter deprecated. Use request filter instead.
   470 		if ( has_filter( 'query_string' ) ) {  // Don't bother filtering and parsing if no plugins are hooked in.
   422 		if ( has_filter('query_string') ) {  // Don't bother filtering and parsing if no plugins are hooked in.
   471 			/**
   423 			$this->query_string = apply_filters('query_string', $this->query_string);
   472 			 * Filter the query string before parsing.
       
   473 			 *
       
   474 			 * @since 1.5.0
       
   475 			 * @deprecated 2.1.0 Use 'query_vars' or 'request' filters instead.
       
   476 			 *
       
   477 			 * @param string $query_string The query string to modify.
       
   478 			 */
       
   479 			$this->query_string = apply_filters( 'query_string', $this->query_string );
   424 			parse_str($this->query_string, $this->query_vars);
   480 			parse_str($this->query_string, $this->query_vars);
   425 		}
   481 		}
   426 	}
   482 	}
   427 
   483 
   428 	/**
   484 	/**
   440 	 * @global int $single If single page or post. Only set, if single page or post.
   496 	 * @global int $single If single page or post. Only set, if single page or post.
   441 	 * @global WP_User $authordata Only set, if author archive.
   497 	 * @global WP_User $authordata Only set, if author archive.
   442 	 *
   498 	 *
   443 	 * @since 2.0.0
   499 	 * @since 2.0.0
   444 	 */
   500 	 */
   445 	function register_globals() {
   501 	public function register_globals() {
   446 		global $wp_query;
   502 		global $wp_query;
   447 
   503 
   448 		// Extract updated query vars back into global namespace.
   504 		// Extract updated query vars back into global namespace.
   449 		foreach ( (array) $wp_query->query_vars as $key => $value ) {
   505 		foreach ( (array) $wp_query->query_vars as $key => $value ) {
   450 			$GLOBALS[ $key ] = $value;
   506 			$GLOBALS[ $key ] = $value;
   467 	/**
   523 	/**
   468 	 * Set up the current user.
   524 	 * Set up the current user.
   469 	 *
   525 	 *
   470 	 * @since 2.0.0
   526 	 * @since 2.0.0
   471 	 */
   527 	 */
   472 	function init() {
   528 	public function init() {
   473 		wp_get_current_user();
   529 		wp_get_current_user();
   474 	}
   530 	}
   475 
   531 
   476 	/**
   532 	/**
   477 	 * Set up the Loop based on the query variables.
   533 	 * Set up the Loop based on the query variables.
   478 	 *
   534 	 *
   479 	 * @uses WP::$query_vars
   535 	 * @since 2.0.0
   480 	 * @since 2.0.0
   536 	 */
   481 	 */
   537 	public function query_posts() {
   482 	function query_posts() {
       
   483 		global $wp_the_query;
   538 		global $wp_the_query;
   484 		$this->build_query_string();
   539 		$this->build_query_string();
   485 		$wp_the_query->query($this->query_vars);
   540 		$wp_the_query->query($this->query_vars);
   486  	}
   541  	}
   487 
   542 
   488  	/**
   543  	/**
   489  	 * Set the Headers for 404, if nothing is found for requested URL.
   544 	 * Set the Headers for 404, if nothing is found for requested URL.
   490 	 *
   545 	 *
   491 	 * Issue a 404 if a request doesn't match any posts and doesn't match
   546 	 * Issue a 404 if a request doesn't match any posts and doesn't match
   492 	 * any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
   547 	 * any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
   493 	 * issued, and if the request was not a search or the homepage.
   548 	 * issued, and if the request was not a search or the homepage.
   494 	 *
   549 	 *
   495 	 * Otherwise, issue a 200.
   550 	 * Otherwise, issue a 200.
   496 	 *
   551 	 *
   497 	 * @since 2.0.0
   552 	 * @since 2.0.0
   498  	 */
   553  	 */
   499 	function handle_404() {
   554 	public function handle_404() {
   500 		global $wp_query;
   555 		global $wp_query;
   501 
   556 
   502 		// If we've already issued a 404, bail.
   557 		// If we've already issued a 404, bail.
   503 		if ( is_404() )
   558 		if ( is_404() )
   504 			return;
   559 			return;
   510 		}
   565 		}
   511 
   566 
   512 		// We will 404 for paged queries, as no posts were found.
   567 		// We will 404 for paged queries, as no posts were found.
   513 		if ( ! is_paged() ) {
   568 		if ( ! is_paged() ) {
   514 
   569 
   515 			// Don't 404 for these queries if they matched an object.
   570 			// Don't 404 for authors without posts as long as they matched an author on this site.
   516 			if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() ) {
   571 			$author = get_query_var( 'author' );
       
   572 			if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
   517 				status_header( 200 );
   573 				status_header( 200 );
   518 				return;
   574 				return;
   519 			}
   575 			}
   520 
   576 
       
   577 			// Don't 404 for these queries if they matched an object.
       
   578 			if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
       
   579 				status_header( 200 );
       
   580 				return;
       
   581 			}
       
   582 
   521 			// Don't 404 for these queries either.
   583 			// Don't 404 for these queries either.
   522 			if ( is_home() || is_search() ) {
   584 			if ( is_home() || is_search() || is_feed() ) {
   523 				status_header( 200 );
   585 				status_header( 200 );
   524 				return;
   586 				return;
   525 			}
   587 			}
   526 		}
   588 		}
   527 
   589 
   540 	 *
   602 	 *
   541 	 * @since 2.0.0
   603 	 * @since 2.0.0
   542 	 *
   604 	 *
   543 	 * @param string|array $query_args Passed to {@link parse_request()}
   605 	 * @param string|array $query_args Passed to {@link parse_request()}
   544 	 */
   606 	 */
   545 	function main($query_args = '') {
   607 	public function main($query_args = '') {
   546 		$this->init();
   608 		$this->init();
   547 		$this->parse_request($query_args);
   609 		$this->parse_request($query_args);
   548 		$this->send_headers();
   610 		$this->send_headers();
   549 		$this->query_posts();
   611 		$this->query_posts();
   550 		$this->handle_404();
   612 		$this->handle_404();
   551 		$this->register_globals();
   613 		$this->register_globals();
   552 		do_action_ref_array('wp', array(&$this));
   614 
       
   615 		/**
       
   616 		 * Fires once the WordPress environment has been set up.
       
   617 		 *
       
   618 		 * @since 2.1.0
       
   619 		 *
       
   620 		 * @param WP &$this Current WordPress environment instance (passed by reference).
       
   621 		 */
       
   622 		do_action_ref_array( 'wp', array( &$this ) );
   553 	}
   623 	}
   554 
   624 
   555 }
   625 }
   556 
   626 
   557 /**
   627 /**
   564 	 * store for matches
   634 	 * store for matches
   565 	 *
   635 	 *
   566 	 * @access private
   636 	 * @access private
   567 	 * @var array
   637 	 * @var array
   568 	 */
   638 	 */
   569 	var $_matches;
   639 	private $_matches;
   570 
   640 
   571 	/**
   641 	/**
   572 	 * store for mapping result
   642 	 * store for mapping result
   573 	 *
   643 	 *
   574 	 * @access public
   644 	 * @access public
   575 	 * @var string
   645 	 * @var string
   576 	 */
   646 	 */
   577 	var $output;
   647 	public $output;
   578 
   648 
   579 	/**
   649 	/**
   580 	 * subject to perform mapping on (query string containing $matches[] references
   650 	 * subject to perform mapping on (query string containing $matches[] references
   581 	 *
   651 	 *
   582 	 * @access private
   652 	 * @access private
   583 	 * @var string
   653 	 * @var string
   584 	 */
   654 	 */
   585 	var $_subject;
   655 	private $_subject;
   586 
   656 
   587 	/**
   657 	/**
   588 	 * regexp pattern to match $matches[] references
   658 	 * regexp pattern to match $matches[] references
   589 	 *
   659 	 *
   590 	 * @var string
   660 	 * @var string
   591 	 */
   661 	 */
   592 	var $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
   662 	public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
   593 
   663 
   594 	/**
   664 	/**
   595 	 * constructor
   665 	 * constructor
   596 	 *
   666 	 *
   597 	 * @param string $subject subject if regex
   667 	 * @param string $subject subject if regex
   598 	 * @param array  $matches data to use in map
   668 	 * @param array  $matches data to use in map
   599 	 * @return self
   669 	 */
   600 	 */
   670 	public function __construct($subject, $matches) {
   601 	function WP_MatchesMapRegex($subject, $matches) {
       
   602 		$this->_subject = $subject;
   671 		$this->_subject = $subject;
   603 		$this->_matches = $matches;
   672 		$this->_matches = $matches;
   604 		$this->output = $this->_map();
   673 		$this->output = $this->_map();
   605 	}
   674 	}
   606 
   675 
   623 	 * do the actual mapping
   692 	 * do the actual mapping
   624 	 *
   693 	 *
   625 	 * @access private
   694 	 * @access private
   626 	 * @return string
   695 	 * @return string
   627 	 */
   696 	 */
   628 	function _map() {
   697 	private function _map() {
   629 		$callback = array($this, 'callback');
   698 		$callback = array($this, 'callback');
   630 		return preg_replace_callback($this->_pattern, $callback, $this->_subject);
   699 		return preg_replace_callback($this->_pattern, $callback, $this->_subject);
   631 	}
   700 	}
   632 
   701 
   633 	/**
   702 	/**
   635 	 *
   704 	 *
   636 	 * @access public
   705 	 * @access public
   637 	 * @param  array $matches preg_replace regexp matches
   706 	 * @param  array $matches preg_replace regexp matches
   638 	 * @return string
   707 	 * @return string
   639 	 */
   708 	 */
   640 	function callback($matches) {
   709 	public function callback($matches) {
   641 		$index = intval(substr($matches[0], 9, -1));
   710 		$index = intval(substr($matches[0], 9, -1));
   642 		return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
   711 		return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
   643 	}
   712 	}
   644 
   713 
   645 }
   714 }