You appear to be a bot. Output may be restricted
Description
Modify WordPress's query internals as if a given URL has been requested.
Usage
WP_UnitTestCase::go_to( $url );
Parameters
- $url
- ( string ) required – The URL for the request.
Returns
voidSource
File name: oik-batch/tests/testcase.phpLines:
1 to 42 of 42
function go_to( $url ) { // note: the WP and WP_Query classes like to silently fetch parameters // from all over the place (globals, GET, etc), which makes it tricky // to run them more than once without very carefully clearing everything $_GET = $_POST = array(); foreach (array('query_string', 'id', 'postdata', 'authordata', 'day', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages', 'pagenow') as $v) { if ( isset( $GLOBALS[$v] ) ) unset( $GLOBALS[$v] ); } $parts = parse_url($url); if (isset($parts['scheme'])) { $req = isset( $parts['path'] ) ? $parts['path'] : ''; if (isset($parts['query'])) { $req .= '?' . $parts['query']; // parse the url query vars into $_GET parse_str($parts['query'], $_GET); } } else { $req = $url; } if ( ! isset( $parts['query'] ) ) { $parts['query'] = ''; } $_SERVER['REQUEST_URI'] = $req; unset($_SERVER['PATH_INFO']); self::flush_cache(); unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']); $GLOBALS['wp_the_query'] = new WP_Query(); $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; $public_query_vars = $GLOBALS['wp']->public_query_vars; $private_query_vars = $GLOBALS['wp']->private_query_vars; $GLOBALS['wp'] = new WP(); $GLOBALS['wp']->public_query_vars = $public_query_vars; $GLOBALS['wp']->private_query_vars = $private_query_vars; _cleanup_query_vars(); $GLOBALS['wp']->main($parts['query']); }View on GitHub