Developer Docs
  • Getting started
  • Tutorials
    • Integrate your theme with HivePress
    • Create a custom HivePress extension
  • Framework
    • Blocks
      • Callback
      • Container
      • Content
      • Form
      • Menu
      • Modal
      • Part
      • Section
      • Template
      • Toggle
    • Components
      • Cache
      • Helper
      • Request
      • Router
      • Translator
    • Configurations
      • Comment types
      • Image sizes
      • Meta boxes
      • Post types
      • Scripts
      • Settings
      • Strings
      • Styles
      • Taxonomies
    • Controllers
    • Emails
    • Fields
      • Checkbox
      • Checkboxes
      • Date
      • Date Range
      • Email
      • File
      • Number
      • Number Range
      • Password
      • Phone
      • Radio Buttons
      • Repeater
      • Select
      • Text
      • Textarea
      • Time
      • URL
    • Forms
    • Menus
    • Models
      • Making queries
      • Creating models
      • Customizing models
    • Templates
  • Resources
    • Code snippets
    • Code reference
    • Hook reference
    • REST API
Powered by GitBook
On this page
  • Request context
  • Query variables

Was this helpful?

  1. Framework
  2. Components

Request

PreviousHelperNextRouter

Last updated 2 years ago

Was this helpful?

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.

Request context

To set a request context value, call the set_context method 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 get_context method:

$value = hivepress()->request->get_context( 'custom_key' );

Use the hivepress/v1/components/request/context hook 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();

If the current user is logged in, the User object is returned. Also, you can get the current page number for paginated queries:

$page = hivepress()->request->get_page_number();

Query variables

To get a HivePress-specific (prefixed with hp_), call the get_param method with the variable name:

$value = hivepress()->request->get_param( 'custom_name' );

You can also call the get_params method to get an array of all the HivePress query variables.

model
query variable