WP::register_globals
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.
Method of the class: WP{}
No Hooks.
Returns
null. Nothing (null).
Usage
global $wp; $wp->register_globals();
Notes
- Global. WP_Query.
$wp_queryWordPress Query object. - Global. String.
$query_stringQuery string for the loop. - Global. Array.
$postsThe found posts. - Global. WP_Post|null.
$postThe current post, if available. - Global. String.
$requestThe SQL statement for the request. - Global. Int.
$moreOnly set, if single page or post. - Global. Int.
$singleIf single page or post. Only set, if single page or post. - Global. WP_User.
$authordataOnly set, if author archive.
Changelog
| Since 2.0.0 | Introduced. |
WP::register_globals() WP::register globals code WP 7.0
public function register_globals() {
global $wp_query;
// Extract updated query vars back into global namespace.
foreach ( (array) $wp_query->query_vars as $key => $value ) {
$GLOBALS[ $key ] = $value;
}
$GLOBALS['query_string'] = $this->query_string;
$GLOBALS['posts'] = & $wp_query->posts;
$GLOBALS['post'] = $wp_query->post ?? null;
$GLOBALS['request'] = $wp_query->request;
if ( $wp_query->is_single() || $wp_query->is_page() ) {
$GLOBALS['more'] = 1;
$GLOBALS['single'] = 1;
}
if ( $wp_query->is_author() ) {
$GLOBALS['authordata'] = get_userdata( get_queried_object_id() );
}
}