wp_nonce_ays( string $action )
- Since
- 2.0.4
- Source
wp-includes/functions.php:3673
Description
If the action has the nonce explain message, then it will be displayed along with the "Are you sure?" message.
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.
Parameters
$actionstring- The nonce action.
Performance profile
How much work a call to wp_nonce_ays() 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
- Moderate
- Scaling
- Constant
- Instructions
- 21–48
- Plugin surface
- None
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 81.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()one call below wp_nonce_ays() - hookthird-party callbacks
apply_filters()one call below wp_nonce_ays()
Further down the call graph this can also reach 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_nonce_ays() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$action !== "log-out" && !wp_get_referer() | 21 | __(), __(), wp_get_referer(), wp_die() |
$action === "log-out" | 44–46 | __(), __(), get_bloginfo(), sprintf(), __(), wp_logout_url(), sprintf(), wp_die() |
$action !== "log-out" && wp_get_referer() | 48 | __(), __(), wp_get_referer(), wp_get_referer(), remove_query_arg(), sanitize_url(), wp_validate_redirect(), esc_url(), __(), wp_die() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 81 | 21–48 | 3 | |
| 8.5 | 81 | 21–48 | 3 | |
| 8.4 | 81 | 21–48 | 3 | |
| 8.3 | 81 | 21–48 | 3 | |
| 8.2 | 81 | 21–48 | 3 | |
| 8.1 | 81 | 21–48 | 3 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 82 | 21–48 | 3 |
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 · 9
- __()Retrieves the translation of $text.
- get_bloginfo()Retrieves information about the current site.
- wp_logout_url()Retrieves the logout URL.
- wp_get_referer()Retrieves referer from '_wp_http_referer' or HTTP referer.
- remove_query_arg()Removes an item or items from a query string.
- wp_validate_redirect()Validates a URL for use in a redirect.
- sanitize_url()Sanitizes a URL for database or redirect usage.
- esc_url()Checks and cleans a URL.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
Used by · 1
- check_admin_referer()Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.
Source code
function wp_nonce_ays( $action ) { // Default title and response code. $title = __( 'An error occurred.' ); $response_code = 403; if ( 'log-out' === $action ) { $title = sprintf( /* translators: %s: Site title. */ __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ); $redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; $html = $title; $html .= '</p><p>'; $html .= sprintf( /* translators: %s: Logout URL. */ __( 'Do you really want to <a href="%s">log out</a>?' ), wp_logout_url( $redirect_to ) ); } else { $html = __( 'The link you followed has expired.' ); if ( wp_get_referer() ) { $wp_http_referer = remove_query_arg( 'updated', wp_get_referer() ); $wp_http_referer = wp_validate_redirect( sanitize_url( $wp_http_referer ) ); $html .= '</p><p>'; $html .= sprintf( '<a href="%s">%s</a>', esc_url( $wp_http_referer ), __( 'Please try again.' ) ); } } wp_die( $html, $title, $response_code );}Changelog
Introduced in 2.0.4. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
none to never.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.