WP::register_globals() WordPress Method
The register_globals() function in WordPress allows you to register custom global variables for use in your theme or plugin. This function takes two arguments: the name of the variable to register, and the value to assign to it. For example, if you wanted to create a global variable named $foo with the value "bar", you would use the following code: register_globals( 'foo', 'bar' ); You can then access the $foo variable anywhere in your theme or plugin code by using the global keyword, like so: global $foo; echo $foo; // outputs "bar" Keep in mind that the register_globals() function should be used sparingly, as it can potentially create security risks if not used carefully.
WP::register_globals() #
Set up the WordPress Globals.
Description
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.
Source
File: wp-includes/class-wp.php
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'] = isset( $wp_query->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() ); } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |