This component implements callbacks and methods for managing the page request context. With the request context, you can get the request-specific data anywhere in the code rather than passing it to each function that runs during a request.
To set a request context value, call the
set_contextmethod with the key and a value:
hivepress()->request->set_context( 'custom_key', $value );
Once the context value is set, you can get it anywhere by calling the
$value = hivepress()->request->get_context( 'custom_key' );
hivepress/v1/components/request/contexthook that filters the request context array if you need to set some context values on every page load. There are also a few pre-defined context values. For example, you can get the current user object this way:
$user = hivepress()->request->get_user();
$page = hivepress()->request->get_page_number();
$value = hivepress()->request->get_param( 'custom_name' );
You can also call the
get_paramsmethod to get an array of all the HivePress query variables.