wp_get_referer(): string|false
- Since
- 2.0.4
- Source
wp-includes/functions.php:1975
Description
If it's the same as the current request URL, will return false.
Compatibility
- WordPress
- since 2.0.4
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
string|false- Referer URL on success, false on failure.
Performance profile
How much work a call to wp_get_referer() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 5–32
- Plugin surface
- None
- Called by
- 13
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 34.
Nothing here hands control to plugin code.
13 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_get_referer()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_referer() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!function_exists() | 5 | function_exists() |
function_exists() | 9 | function_exists(), wp_get_raw_referer() |
function_exists() && $ref === false | 17 | function_exists(), wp_get_raw_referer(), wp_unslash() |
function_exists() | 28 | function_exists(), wp_get_raw_referer(), wp_unslash(), home_url(), wp_unslash() |
function_exists() && $ref !== false | 32 | function_exists(), wp_get_raw_referer(), wp_unslash(), home_url(), wp_unslash(), wp_validate_redirect() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 34 instructions, 5–32 executed per call, 4 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 4
- wp_get_raw_referer()Retrieves unvalidated referer from the '_wp_http_referer' URL query variable or the HTTP referer.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- wp_validate_redirect()Validates a URL for use in a redirect.
Used by · 13
- WP_Customize_Manager::get_return_url()Gets URL to link the user to when closing the Customizer.
- WP_Recovery_Mode::handle_exit_recovery_mode()Handles a request to exit Recovery Mode.
- WP_Terms_List_Table::column_name()
- WP_Terms_List_Table::handle_row_actions()Generates and displays row action links.
- _admin_notice_post_locked()Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
- auth_redirect()Checks if a user is logged in, if not it redirects them to the login page.
- check_admin_referer()Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.
- redirect_post()Redirects to previous page.
- set_screen_options()Saves option for number of rows when listing posts, pages, comments, etc.
- the_block_editor_meta_box_post_form_hidden_fields()Renders the hidden form required for the meta boxes form.
- wp_media_attach_action()Encapsulates the logic for Attach/Detach actions.
- wp_nonce_ays()Displays "Are You Sure" message to confirm the action being taken.
Show all 13
- wp_original_referer_field()Retrieves or displays original referer hidden field for forms.
Source code
function wp_get_referer() { // Return early if called before wp_validate_redirect() is defined. if ( ! function_exists( 'wp_validate_redirect' ) ) { return false; } $ref = wp_get_raw_referer(); if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref && home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref ) { return wp_validate_redirect( $ref, false ); } return false;}Changelog
Introduced in 2.0.4. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.